How to use the mobx.reaction function in mobx

To help you get started, we’ve selected a few mobx examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github 500tech / angular-tree-component / lib / components / tree-node-collection.component.ts View on Github external
ngOnInit() {
    this.virtualScroll = this.treeModel.virtualScroll;
    this._dispose = [
      // return node indexes so we can compare structurally,
      reaction(() => {
        return this.virtualScroll.getViewportNodes(this.nodes).map(n => n.index);
      }, (nodeIndexes) => {
          this.viewportNodes = nodeIndexes.map((i) => this.nodes[i]);
        }, { compareStructural: true, fireImmediately: true } as any
      ),
      reaction(() => this.nodes, (nodes) => {
        this.viewportNodes = this.virtualScroll.getViewportNodes(nodes);
      })
    ];
  }
github zenprotocol / explorer / src / pages / governance / components / tabs / Votes.jsx View on Github external
reloadOnBlocksCountChange() {
    this.forceDisposer = reaction(
      () => this.props.rootStore.blockStore.blocksCount,
      () => {
        this.props.rootStore.uiStore.setRepoVotesTableData({ force: true });
      }
    );
  }
  stopReload() {
github Kitware / itk-vtk-viewer / src / UserInterface / PointSets / createPointSetSizeSlider.js View on Github external
store.pointSetsUI.sizes.push(defaultPointSetSize);
        }
      })
      const selectedPointSetIndex = store.pointSetsUI.selectedPointSetIndex;
      sizeElement.value = store.pointSetsUI.sizes[selectedPointSetIndex];
    }
  )

  reaction(() => {
    return store.pointSetsUI.selectedPointSetIndex;
    },
    (selectedPointSetIndex) => {
      sizeElement.value = store.pointSetsUI.sizes[selectedPointSetIndex];
    });

  reaction(() => {
    return store.pointSetsUI.sizes.slice();
  },
    (sizes) => {
      const selectedPointSetIndex = store.pointSetsUI.selectedPointSetIndex;
      const value = sizes[selectedPointSetIndex];
      store.pointSetsUI.representationProxies[selectedPointSetIndex].setPointSize(value)
      store.renderWindow.render();
      sizeElement.value = value;
    });

  sizeElement.addEventListener('input', (event) => {
      event.preventDefault();
      event.stopPropagation();
      const selectedPointSetIndex = store.pointSetsUI.selectedPointSetIndex;
      store.pointSetsUI.sizes[selectedPointSetIndex] = Number(event.target.value);
    });
github jiangshanmeta / react-admin / src / components / common / editor / Editor.js View on Github external
relates.filter(item=>typeof item.handler === 'function').forEach((relateItem)=>{
                const callback = function(newVal){
                    if(this.$refs[field]){
                        relateItem.handler.call(this.$refs[field],newVal);
                    }else{
                        setTimeout(()=>{
                            callback.call(this,newVal);
                        },0);
                    }
                };

                const unwatch = reaction(()=>{
                    return this.getRelateData(relateItem);
                },callback.bind(this),relateItem.config)

                this.recordUnwatchs.push(unwatch);

            });
github gotify / server / ui / src / message / MessagesStore.ts View on Github external
public constructor(
        private readonly appStore: BaseStore,
        private readonly snack: SnackReporter
    ) {
        reaction(() => appStore.getItems(), this.createEmptyStatesForApps);
    }
github lennerd / git-for-beginners / src / components / VisualisationPointer.js View on Github external
const { visPointer } = this.props;

        return visPointer.position;
      },
      position => {
        tween({
          from: this.position.get(),
          to: position,
          duration: 1000,
          ease: easing.easeInOut,
        }).start(this.position);
      },
      { equals: comparer.structural },
    );

    this.disposeLinePath = reaction(
      () => this.linePath,
      linePath => {
        const prevLinePath = this.linePathValue.get();

        parallel(
          ...linePath.map((lineSegment, index) =>
            tween({
              from: prevLinePath[index],
              to: lineSegment,
              duration: 1000,
              ease: easing.easeInOut,
            }),
          ),
        ).start(this.linePathValue);
      },
      { equals: comparer.structural },
github surmon-china / surmon.me.native / src / pages / about / setting.tsx View on Github external
constructor(props: ILanguageDetailIconProps) {
    super(props)
    reaction(
      () => this.props.close,
      close => this.updateOpacityAnimate(close ? 1 : 0)
    )
  }
github tabixio / tabix / app / src / stores / DashboardStore.ts View on Github external
private startReactions() {
    this.autosaveTimer = window.setInterval(() => {
      tabsStorage.saveTabs(this.tabs.map(_ => _.toJSON()));
    }, 30000);

    this.changeTabsReaction = reaction(
      () => this.tabs,
      tabs => {
        tabsStorage.saveTabs(tabs.map(_ => _.toJSON()));
      }
    );

    this.changeActiveTabReaction = reaction(
      () => this.activeTab,
      tab => {
        this.uiStore.resetTabViewState();
        tabsStorage.saveActiveTabId(tab.map(t => t.id).orUndefined());
      }
    );
  }