How to use the mobx.runInAction 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 TerriaJS / terriajs / lib / ViewModels / createGlobalBaseMapOptions.ts View on Github external
CommonStrata.user,
      "layers",
      "nasa-black-marble:dnb_land_ocean_ice.2012.54000x27000_geo"
    );
    blackMarble.setTrait(CommonStrata.user, "opacity", 1.0);
    blackMarble.loadMapItems();
  });
  result.push(
    new BaseMapViewModel(
      blackMarble,
      require("../../wwwroot/images/black-marble.png")
    )
  );

  const positron = new OpenStreetMapCatalogItem("basemap-positron", terria);
  runInAction(() => {
    positron.setTrait(CommonStrata.user, "name", "Positron (Light)");
    positron.setTrait(
      CommonStrata.user,
      "url",
      "https://global.ssl.fastly.net/light_all/"
    );

    // https://cartodb.com/basemaps/ gives two different attribution strings. In any case HTML gets swallowed, so we have to adapt.
    // 1 '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, ©
    //   <a href="http://cartodb.com/attributions">CartoDB</a>'
    // 2 Map tiles by <a href="http://cartodb.com/attributions#basemaps">CartoDB</a>, under <a href="https://creativecommons.org/licenses/by/3.0/">
    //   CC BY 3.0</a>. Data by <a href="http://www.openstreetmap.org/">OpenStreetMap</a>, under ODbL.
    positron.setTrait(
      CommonStrata.user,
      "attribution",
      "© OpenStreetMap contributors ODbL, © CartoDB CC-BY 3.0"
github phiresky / backchannel-prediction / web_vis / ts / socket.ts View on Github external
then(resolve: (t: T) =&gt; R, reject?: (error: any) =&gt; any): LulPromise {
        if (this.data) {
            // resolve instantly without waiting for call stack to empty
            const nextVal = resolve(this.data);
            const nextLul = new LulPromise(Promise.resolve(nextVal));
            if (typeof nextVal === "object" &amp;&amp; typeof (nextVal as any)["then"] !== "function") {
                mobx.runInAction("then()", () =&gt; nextLul.data = nextVal);
            }
            return nextLul;
        } else {
            return new LulPromise(this.promise.then(resolve, reject));
        }
    }
}
github mobx-little-router / mobx-little-router / packages / mobx-little-router / src / model / RouterStore.js View on Github external
updateRoutes(routes: Route&lt;*, *&gt;[]) {
    runInAction(() =&gt; {
      this.prevRoutes.replace(this.routes.slice())
      this.routes.replace(routes)

      // Update params
      this.params.clear()
      this.routes.forEach(route =&gt; {
        this.params.set(route.node.value.key, route.params)
      })
    })
  }
github async-labs / saas / book / 9-end / app / lib / store / team.ts View on Github external
public async edit({ name, avatarUrl }: { name: string; avatarUrl: string }) {
    try {
      const { slug } = await updateTeam({
        teamId: this._id,
        name,
        avatarUrl,
      });

      runInAction(() => {
        this.name = name;
        this.slug = slug;
        this.avatarUrl = avatarUrl;
      });
    } catch (error) {
      console.error(error);
      throw error;
    }
  }
github textileio / desktop / src / Stores / index.ts View on Github external
@action async fetchNotifications() {
    try {
      const notifications = await textile.notifications.list()
      const processed = notifications.items.map((item) => {
        item.user.avatar = item.user.avatar
          ? `${this.gateway}/ipfs/${item.user.avatar}/0/small/content`
          : DEFAULT_AVATAR
        return item
      })
      runInAction('fetchNotifications', () => {
        this.notifications = processed
      })
    } catch (err) {
      console.log(err)
    }
  }
  @action async readNotification(id: string) {
github async-labs / saas / book / 12-begin / app / lib / store / user.ts View on Github external
public async createCustomer({ token }: { token: object }) {
    try {
      const { hasCardInformation, stripeCard } = await createCustomerApiMethod({
        token,
      });

      runInAction(() => {
        this.hasCardInformation = hasCardInformation;
        this.stripeCard = stripeCard;
      });
    } catch (error) {
      console.error(error);
      throw error;
    }
  }
github eez-open / studio / packages / eez-studio-ui / notification.tsx View on Github external
function getToast() {
    if (!toastModule) {
        toastModule = require("react-toastify") as typeof ToastModule;

        const ToastContainer = toastModule.ToastContainer;
        runInAction(() =&gt; {
            container.set(
                
            );
        });
    }

    return toastModule.toast;
}
github owid / owid-grapher / admin / client / TagsIndexPage.tsx View on Github external
async getData() {
        const json = await this.context.admin.getJSON("/api/tags.json")
        runInAction(() => {
            this.tags = json.tags
        })
    }
github alaatm / Sejil / src / Sejil.Client / src / Store.ts View on Github external
try {
            const response = await fetch(url, {
                method: 'post',
                body: JSON.stringify({
                    queryText: this.queryText,
                    dateFilter: this.dateFilter instanceof Array
                        ? null
                        : this.dateFilter,
                    dateRangeFilter: this.dateFilter instanceof Array
                        ? this.dateFilter.map(d => formatServerDate(d))
                        : null,
                    levelFilter: this.levelFilter,
                    exceptionsOnly: this.exceptionsOnly,
                })
            });
            runInAction('set loading finished', () => this.loading = false);

            if (!response.ok) {
                if (this.onEventsLoadError) {
                    this.onEventsLoadError(response);
                }
                return;
            }

            const events = await response.json() as ILogEntry[];

            if (events.length) {
                if (!this.startingTimestamp) {
                    this.startingTimestamp = events[0].timestamp;
                }

                runInAction('load entries', () => this.logEntries = this.logEntries.concat(events));