V
V
vitaliyfilatov2020-12-26 20:13:33
Angular
vitaliyfilatov, 2020-12-26 20:13:33

Does it make sense to use Redux in an Angular application?

At the moment, the question arises of using Redux in an Angular application. Redux is a powerful tool for development (especially for medium and large applications that are planned to be developed). However, there are big doubts about this. In the application in question, there are many hierarchical structures (sometimes more than 3 levels) and then the code using Redux (we are implementing ngsx at the moment) for the component will look something like this (the code is simplified as much as possible to reflect only the idea):

export class SomeComponent {

  tableData: TreeTableData = new TreeTableData();
  //build TreeTableData for tree table view
  builder: SomeBuilder;
  public pageSize:number;
  public page:number;

  @Select(SomeState.state) state$: Observable<StateModel>;

  constructor(private store: Store) {
    //...
    //instantiate and configure builder
    //...
    this.state$.subscribe(patientState => {
        this.tableData = this.builder.build(state.items);
        this.restorePaginator();
        this.tableData.isLoading = state.loading;
      });
    this.builder.expandRowCallback = (row, tableData) => {
      ///...
      //dispatch that row is expanded
      ///...
    };
    this.builder.tableConfig.events.rowCollapsed = (row, tableData) => {
      ///...
      //dispatch that row is collapsed
      ///...
    };
  }

  private restorePaginator() {
    if(this.pageSize)
      this.tableData.pageSize = this.pageSize;
    if(this.page)
      this.tableData.page = this.page;
  }

  onPageNumberChanged(page:number) {
    this.page = page;
  }

  onPageSizeChanged(pageSize:number) {
    this.pageSize = pageSize;
  }
}

Those. to correctly restore the state of a hierarchical view, each time you have to notify the storage about a change in the status of hiding / expanding a row. And that's just a matter of revealing/hiding.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question