Skip to content

Base classes and utilities of mobx stores and validable mobx models.

License

Notifications You must be signed in to change notification settings

vlazh/mobx-utils

Repository files navigation

MobX Utils

npm package

Useful utils for mobx.

import { observable } from 'mobx';
import { attachSelectors, createRootStore, createStore } from '@js-toolkit/mobx-utils/store/object';

const rootStore0 = createRootStore({
  store1: createStore(
    {
      prop1: 0,
      prop2: 0,
      prop3: [],
      prop4: '',
      method: () => {},
    },
    {
      prop3: observable.shallow,
      prop4: false,
    }
  ),
});

const rootStore = attachSelectors(rootStore0, {
  get isProp1(): boolean {
    return root.store1.prop1 > 0;
  },
});