How to use the mobx-state-tree.types.frozen 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 wp-pwa / wp-pwa / core / packages / analytics / pwa / components / __tests__ / index.tests.js View on Github external
import React from 'react';
import renderer from 'react-test-renderer';
import { Provider } from 'mobx-react';
import { types } from 'mobx-state-tree';
import Analytics from '..';

const Stores = types.model('Stores').props({
  build: types.frozen({
    isPwa: true,
    channel: 'pwa',
    packages: 'saturn-theme,wp-org-connection',
  }),
  connection: types.frozen({
    selectedItem: { type: 'post', id: 60 },
  }),
  analytics: types.frozen({
    customDimensions: () => ({
      dimension1: 'dim1_post60',
      dimension2: 'dim2_post60',
    }),
    googleAnalytics: {
      ids: ['UA-12345678-1', 'UA-12345678-2'],
    },
    googleTagManager: {
      ids: ['GTM-112233'],
      clientProperties: {
        anonymize: false,
        siteId: 'site1122334455',
        userIds: ['user00', 'user01'],
github birkir / prime / packages / prime-ui / src / stores / models / WebhookCall.ts View on Github external
import { types } from 'mobx-state-tree';

export const WebhookCall = types.model('WebhookCall', {
  id: types.identifier,
  success: types.boolean,
  request: types.frozen(),
  response: types.frozen(),
});
github mobxjs / mobx-state-tree / packages / mst-middlewares / src / undo-manager.ts View on Github external
IPatchRecorder,
    createActionTrackingMiddleware2,
    getEnv,
    getRoot,
    applyPatch,
    flow,
    addMiddleware,
    addDisposer,
    decorate,
    isActionContextThisOrChildOf
} from "mobx-state-tree"
import { atomic } from "."

const Entry = types.model("UndoManagerEntry", {
    patches: types.frozen>(),
    inversePatches: types.frozen>()
})

const UndoManager = types
    .model("UndoManager", {
        history: types.array(Entry),
        undoIdx: 0
    })
    .views(self => ({
        get undoLevels() {
            return self.undoIdx
        },
        get redoLevels() {
            return self.history.length - self.undoIdx
        },
        get canUndo() {
            return this.undoLevels > 0
github birkir / prime / packages / prime-ui / src / stores / models / Schema.ts View on Github external
type?: string;
}

export const DEFAULT_TYPE = 'string';
export const DEFAULT_GROUP_TITLE = 'Main';

export const SchemaField = types
  .model('SchemaField', {
    id: types.identifier,
    type: types.string,
    name: types.string,
    title: types.string,
    description: types.maybeNull(types.string),
    primary: types.optional(types.boolean, false),
    schemaId: types.maybeNull(types.string),
    options: types.frozen(),
    group: DEFAULT_GROUP_TITLE,
    fields: types.maybeNull(types.array(types.late((): any => SchemaField))),
    __typename: types.maybeNull(types.string),
  })
  .preProcessSnapshot(snapshot => ({
    ...snapshot,
    fields: snapshot.fields || [],
  }))
  .views(self => ({
    get isLeaf(): boolean {
      return !hasParentOfType(self, SchemaField);
    },
    get defaultOptions() {
      const settingsField = Settings.fields.find((f: any) => f.type === self.type);
      if (settingsField) {
        return settingsField.options;
github baidu / amis / src / store / crud.ts View on Github external
isEmpty,
  qsstringify
} from '../utils/helper';
import {Api, Payload, fetchOptions, Action} from '../types';
import qs from 'qs';
import pick = require('lodash/pick');
import {resolveVariableAndFilter} from '../utils/tpl-builtin';

class ServerError extends Error {
  type = 'ServerError';
}

export const CRUDStore = ServiceStore.named('CRUDStore')
  .props({
    pristineQuery: types.optional(types.frozen(), {}),
    query: types.optional(types.frozen(), {}),
    prevPage: 1,
    page: 1,
    perPage: 10,
    total: 0,
    mode: 'normal',
    hasNext: false,
    selectedAction: types.frozen(),
    items: types.optional(types.array(types.frozen()), []),
    selectedItems: types.optional(types.array(types.frozen()), []),
    unSelectedItems: types.optional(types.array(types.frozen()), []),
    filterTogggable: false,
    filterVisible: true,
    hasInnerModalOpen: false
  })
  .views(self => ({
    get lastPage() {
github kitze / rttr / src / router-store.js View on Github external
import {types} from 'mobx-state-tree';
import {replaceUrlParams} from './utils';

export const RouterStore = types
  .model({
    page: '',
    path: '/',
    params: types.frozen(),
    queryParams: types.frozen(),
    extra: types.frozen(),
    options: types.frozen()
  })
  .views(self => ({
    get currentUrl() {
      return replaceUrlParams(self.path, self.params, self.queryParams);
    }
  }))
  .actions(self => ({
    openPage({id, path, extra: pageExtra}, params = {}, queryParams = {}, extra = {}) {
      self.page = id;
      self.path = path;
      self.params = params;
      self.queryParams = queryParams;
      self.extra = {...pageExtra, ...extra};
    }
github Feverqwe / tSearch / src / stores / CodeMakerStore.js View on Github external
* @property {function} setState
 * @property {*} props
 * @property {function} setPath
 * @property {function} setOptions
 * @property {function} setSelectMode
 * @property {function} setSelectOptions
 * @property {function} selectListener
 * @property {function} selectHandler
 * @property {function} setSelectListener
 * @property {function} setSelectHandler
 * @property {function} setSelect
 */
const FrameStore = types.model('FrameStore', {
  state: types.optional(types.enumeration(['idle', 'pending', 'done', 'error']), 'idle'),
  path: types.optional(types.string, ''),
  options: types.frozen(),
  selectMode: types.optional(types.boolean, false),
  selectOptions: types.frozen(),
}).actions(self => {
  return {
    setState(value) {
      self.state = value;
    },
    setPath(value) {
      self.path = value;
    },
    setOptions(options) {
      self.options = options;
    },
    setSelectMode(value) {
      self.selectMode = value;
    },
github padraic-X / augesco / src / models / instanceTx.js View on Github external
import { types, getRoot, flow } from "mobx-state-tree";
import { txStatus } from "../constants";

export const transactionInstance = types
  .model({
    hash: types.identifier,
    receipt: types.optional(types.frozen(), {}),
    interval: types.optional(types.frozen(), {}),
    status: types.enumeration([
      txStatus.PENDING,
      txStatus.MINED,
      txStatus.FAILED,
      txStatus.SUCCESS
    ])
  })
  .actions(self => ({
    addReceipt(_receipt) {
      self.receipt = _receipt;
    },
    updateStatus(_status) {
      if (self.status !== txStatus.FAILED && self.status !== txStatus.SUCCESS) {
        self.status = _status;
      }
github zooniverse / front-end-monorepo / packages / lib-classifier / src / store / Subject.js View on Github external
import { getRoot, isValidReference, types } from 'mobx-state-tree'
import Resource from './Resource'
import createLocationCounts from '../helpers/createLocationCounts'
import subjectViewers from '../helpers/subjectViewers'

const Subject = types
  .model('Subject', {
    already_seen: types.optional(types.boolean, false),
    favorite: types.optional(types.boolean, false),
    finished_workflow: types.optional(types.boolean, false),
    locations: types.frozen([]),
    metadata: types.frozen({}),
    retired: types.optional(types.boolean, false),
    selected_at: types.maybe(types.string),
    selection_state: types.maybe(types.string),
    shouldDiscuss: types.maybe(types.frozen()),
    user_has_finished_workflow: types.optional(types.boolean, false)
  })

  .actions(self => {
    function addToCollection () {
      const rootStore = getRoot(self)
      rootStore.onAddToCollection(self.id)
    }

    function openInTalk (newTab = false) {
      self.shouldDiscuss = {
github padraic-X / augesco / src / models / contractModel.js View on Github external
import { types, getRoot, flow } from 'mobx-state-tree'
import { txStatus } from "../constants"

export const ContractInstance = types
  .model({
    name: types.identifier,
    abi: types.frozen(),
    txHash: types.frozen(),
    address: types.string,
    contract: types.optional(types.frozen(), {}),
    methods: types.optional(types.frozen(), {}),
    eventContract: types.optional(types.frozen(), {}),
    events: types.optional(types.frozen(), {}),
  })
  .actions(self => ({
    getMethod(_method) {
      return self.methods[_method]
    }
  }))

export const transactionInstance = types
  .model({
    hash: types.identifier,