How to use the mobx-state-tree.getRoot function in mobx-state-tree

To help you get started, we’ve selected a few mobx-state-tree 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 baidu / amis / src / store / form.ts View on Github external
} else {
          if (options && options.onSuccess) {
            const ret = options.onSuccess(json);

            if (ret && ret.then) {
              yield ret;
            }
          }
          self.markSaving(false);
          self.updateMessage(json.msg || (options && options.successMessage));
          self.msg &&
            (getRoot(self) as IRendererStore).notify('success', self.msg);
          return json.data;
        }
      } catch (e) {
        if ((getRoot(self) as IRendererStore).storeType !== 'RendererStore') {
          // 已经销毁了,不管这些数据了。
          return;
        }

        self.markSaving(false);
        // console.error(e.stack);`
        (getRoot(self) as IRendererStore).notify('error', e.message);
        throw e;
      }
    });
github zooniverse / front-end-monorepo / packages / lib-classifier / src / plugins / tasks / models / Task.js View on Github external
updateAnnotation (value) {
      const { addAnnotation } = getRoot(self).classifications
      addAnnotation(self, value)
    },
github kitze / JSUI / src / models / Project.js View on Github external
installNodeModules: flow(function*() {
        const store = getRoot(self);
        yield self.runScript('install');
        store.createNotification('Done', `Dependencies for ${self.name} are installed.`);
      }),
      reinstallDependencies: flow(function*() {
github heartexlabs / label-studio / src / interfaces / control / Rectangle.js View on Github external
get completion() {
      return getRoot(self).completionStore.selected;
    },
  }));
github zooniverse / front-end-monorepo / packages / lib-classifier / src / store / WorkflowStore.js View on Github external
        const validUPPReference = isValidReference(() => getRoot(self).userProjectPreferences.active)
        const validWorkflowReference = isValidReference(() => self.active)
github mobxjs / mobx-state-tree / packages / mst-middlewares / src / undo-manager.ts View on Github external
afterCreate() {
                const selfRoot = getRoot(self)
                targetStore = getEnv(self).targetStore || selfRoot
                if (targetStore === self) {
                    throw new Error(
                        "UndoManager should be created as part of a tree, or with `targetStore` in it's environment"
                    )
                }
                addDisposer(self, addMiddleware(targetStore, undoRedoMiddleware, false))
            },
            undo: decorate(atomic, () => {
github zooniverse / front-end-monorepo / packages / app-project / stores / Recents.js View on Github external
fetch: flow(function * fetch () {
        const { client, project, user } = getRoot(self)
        self.loadingState = asyncStates.loading
        try {
          const token = yield auth.checkBearerToken()
          const authorization = `Bearer ${token}`
          const query = {
            project_id: project.id,
            sort: '-created_at'
          }
          const response = yield client.panoptes.get(`/users/${user.id}/recents`, query, { authorization })
          const { recents } = response.body
          self.recents = recents.map(recent => ({
            subjectId: recent.links.subject,
            locations: recent.locations
          }))
          self.loadingState = asyncStates.success
        } catch (error) {
github PacktPublishing / MobX-Quick-Start-Guide / src / Chapter08 / mst / references.js View on Github external
getAssignee() {
                if (!this.assignee) return undefined;
                return getRoot(self).users.get(this.assignee);
            },
        }))