How to use the mobx.autorun 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 mobxjs / mobx-utils / test / create-view-model.ts View on Github external
function tests(model) {
    const viewModel = utils.createViewModel(model)
    let tr
    let vr
    // original rendering
    const d1 = mobx.autorun(() => {
        tr =
            model.title +
            ":" +
            model.done +
            ",interested:" +
            model.usersInterested.slice().toString() +
            ",unobservedProp:" +
            model.unobservedProp +
            ",usersCount:" +
            model.usersCount
    })
    // view model rendering
    const d2 = mobx.autorun(() => {
        vr =
            viewModel.title +
            ":" +
github electron / fiddle / src / renderer / touch-bar-manager.ts View on Github external
public setupTouchBar() {
    // First, the welcome
    this.setWelcomeItems();

    // Then, go with the intro
    setTimeout(() => {
      this.setDefaultItems();
    }, 4000);

    autorun(this.updateStartStopBtn);
    autorun(this.updateVersionSelectorItems);
    autorun(this.updateVersionButton);
  }
github ff14wed / aetherometer / ui / src / stores / commonStore.ts View on Github external
} else if (payload.adminOTP) {
      const adminToken = await this.gqlClient.initializeAdminToken(payload.adminOTP);
      ipcRenderer.send('save-admin-token', adminToken);
    }

    this.apiVersion = await this.gqlClient.getAPIVersion();

    const storeDefaultPlugins = this.diskStore.get('defaultPlugins') as Array<{ name: string, url: string }>;
    for (const { name, url } of storeDefaultPlugins) {
      await this.addPlugin('default', name, url);
    }

    this.switchToNewStream = this.diskStore.get('switchToNewStream') as boolean;
    this.savedSessions = String(this.diskStore.get('savedSessions'));

    this.autoSaveDispose = autorun(() => {
      const plugins = Array.from(this.defaultPlugins.values()).map((plugin) => ({
        name: plugin.name,
        url: plugin.url,
      }));
      this.diskStore.set('defaultPlugins', plugins);
      this.diskStore.set('switchToNewStream', this.switchToNewStream);
      this.diskStore.set('savedSessions', this.sanitizedSavedSessions);
    });

    this.timeUpdateTimeout = setInterval(() => {
      this.streams.forEach((stream) => stream.updateDisplayStartTime());
    }, 60000);

    this.subscription = await this.addStreamListeners(
      action(async (streamID: number) => {
        // tslint:disable-next-line: no-console
github meetalva / alva / packages / core / src / adapters / electron-adapter / electron-adapter.ts View on Github external
});

			const message =
				typeof m.payload === 'object' && typeof (m.payload as any).message === 'string'
					? (m.payload as any).message
					: '';

			Sentry.withScope(scope => {
				scope.setTag('report-type', 'user-report');
				scope.setLevel(Sentry.Severity.Error);
				scope.setExtra('report', JSON.stringify(m.payload));
				Sentry.captureMessage(`User report: ${message}`);
			});
		});

		Mobx.autorun(async () => {
			server.sender.send({
				type: MT.ProjectRecordsChanged,
				id: uuid.v4(),
				payload: {
					projects: await this.server.dataHost.getProjects()
				}
			});
		});

		// Open the splash screen when starting without file
		if (!opts || !opts.filePath) {
			await host.createWindow({
				address: server.location.origin,
				variant: HostWindowVariant.Splashscreen
			});
		} else {
github owid / owid-grapher / admin / client / VariableSelector.tsx View on Github external
componentDidMount() {
        this.dispose = autorun(() => {
            if (!this.editorData)
                runInAction(() =>
                    this.props.editor.loadNamespace(this.currentNamespace.name)
                )
        })

        this.chosenVariables = this.props.slot.dimensionsWithData.map(d => ({
            name: d.displayName,
            id: d.variableId,
            datasetName: "",
            searchKey: ""
        }))
    }
github sulu / sulu / src / Sulu / Bundle / AdminBundle / Resources / js / containers / Toolbar / withToolbar.js View on Github external
componentDidMount() {
            if (super.componentDidMount) {
                super.componentDidMount();
            }

            const {router} = this.props;

            const toolbarDisposer = autorun(() => {
                const toolbarConfig = toolbar.call(this);
                toolbarStorePool.setToolbarConfig(toolbarStoreKey, toolbarConfig);
                log.info(
                    (WithToolbarComponent.displayName || '') + ' configured toolbar "' + toolbarStoreKey + '"',
                    toolbarConfig
                );
            });

            this.updateRouteHookDisposer = router.addUpdateRouteHook((newRoute, newAttributes) => {
                const {attributes: oldAttributes, route: oldRoute} = router;
                if (getViewKeyFromRoute(newRoute, newAttributes) !== getViewKeyFromRoute(oldRoute, oldAttributes)) {
                    toolbarDisposer();
                }

                return true;
            }, UPDATE_ROUTE_HOOK_PRIORITY);
github HSLdevcom / jore-map-ui / src / components / sidebar / routeListView / RouteList.tsx View on Github external
async componentDidMount() {
        await this.fetchRoutes();
        this.props.routePathStore!.clear();
        this.props.searchStore!.setSearchInput('');

        autorun(() => this.centerMapToRoutes());
    }
github stolenng / mobx-cross-data-example / src / preact / index.js View on Github external
componentDidMount() {
        autorun(() => this.updateComponent(templatesStore.getTemplates));
    }
github mobxjs / mobx-angular / lib / directives / mobx-autorun.directive.ts View on Github external
autoDetect(view: EmbeddedViewRef) {
    this.dispose = autorun(
      () => view.detectChanges(),
    );
  }
github zenprotocol / explorer / src / store / UIStore.js View on Github external
autorun(function runOnAddressChange() {
      addressStore.resetAddressTransactionAssets(state.addressTxAssetsTable.address);
      addressStore.fetchAddress(state.addressTxAssetsTable.address);
    });

    autorun(function fetchAddressTxAssetsOnChange() {
      if (state.addressTxAssetsTable.address) {
        addressStore.fetchAddressTransactionAssets(state.addressTxAssetsTable.address, {
          page: state.addressTxAssetsTable.curPage,
          pageSize: state.addressTxAssetsTable.pageSize,
        });
      }
    });

    autorun(function fetchAddressTxsOnChange() {
      if (state.addressTxsTable.address) {
        addressStore.loadAddressTransactions(state.addressTxsTable.address, {
          page: state.addressTxsTable.curPage,
          pageSize: state.addressTxsTable.pageSize,
        });
      }
    });

    autorun(function fetchContractsOnChange() {
      if (
        state.contractsTable.curPage * state.contractsTable.pageSize <
        contractStore.contractsCount
      ) {
        contractStore.loadContracts({
          page: state.contractsTable.curPage,
          pageSize: state.contractsTable.pageSize,