How to use the mobx-state-tree.types.array 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 naguvan / react-mst-form / packages / react-mst-form / src / models / Type / Array / Array.ts View on Github external
export default function createArray(): IModelType<
  Partial,
  IArray
> {
  if (!NArray) {
    const Array: IModelType, IArray> = types
      .compose(
        "Array",
        createValue, "array">(
          "array",
          types.array(types.frozen),
          []
        ),
        types.model({
          minItems: types.maybe(types.number),
          maxItems: types.maybe(types.number),
          // items: types.maybe(
          //     types.union(
          //         types.late(createType),
          //         types.array(types.late(createType))
          //     )
          // ),
          items: types.optional(types.frozen, null),
          uniqueItems: types.maybe(types.boolean),
          additionalItems: types.maybe(types.boolean),
          elements: types.optional(types.array(types.late(createType)), [])
        })
github coderplanets / coderplanets_web / containers / UsersThread / store.js View on Github external
// import R from 'ramda'

import { markStates, buildLog, stripMobx } from '@utils'
/* eslint-disable-next-line */
const log = buildLog('S:UsersThread')

const Geo = t.model('Thread', {
  city: t.string,
  value: t.number,
  long: t.number,
  lant: t.number,
})

const UsersThread = t
  .model('UsersThread', {
    geoInfos: t.optional(t.array(Geo), []),
    geoDataLoading: t.optional(t.boolean, false),
    // { city: '成都', value: 1, long: 104.06, lant: 30.67 }
    showNums: t.optional(t.boolean, false),
  })
  .views(self => ({
    get root() {
      return getParent(self)
    },
    get curTheme() {
      return self.root.theme.curTheme
    },
    get curCommunity() {
      return stripMobx(self.root.viewing.community)
    },
    get geoInfosData() {
      return stripMobx(self.geoInfos)
github coderplanets / coderplanets_web / containers / ErrorBox / store.js View on Github external
.model('ErrorBox', {
    show: t.optional(t.boolean, false),
    type: t.optional(
      t.enumeration('type', [ERR.GRAPHQL, ERR.NETWORK, ERR.TIMEOUT]),
      ERR.GRAPHQL
    ),
    operation: t.optional(t.string, '--'),
    path: t.maybeNull(t.string),

    timeoutError: t.optional(t.string, '--'),
    // spec type of ERR.GRAPHQL
    graphqlType: t.optional(
      t.enumeration('graphqlType', ['changeset', 'parse', 'custom']),
      'changeset'
    ),
    customError: t.maybeNull(t.array(Message)),
    parseError: t.maybeNull(t.array(Message)),
    changesetError: t.maybeNull(t.array(ChangesetError)),
  })
  .views(self => ({
    get root() {
      return getParent(self)
    },
    get changesetErrorData() {
      return stripMobx(self.changesetError)
    },
    get customErrorData() {
      return stripMobx(self.customError)
    },
    get parseErrorData() {
      return stripMobx(self.parseError)
    },
github Feverqwe / tSearch / srcDraft / js / models / tracker.js View on Github external
const trackerMetaModel = types.model('trackerMetaModel', {
  name: types.string,
  version: types.maybe(types.string),
  author: types.maybe(types.string),
  description: types.maybe(types.string),
  homepageURL: types.maybe(types.string),
  icon: types.maybe(types.string),
  icon64: types.maybe(types.string),
  trackerURL: types.maybe(types.string),
  updateURL: types.maybe(types.string),
  downloadURL: types.maybe(types.string),
  supportURL: types.maybe(types.string),
  require: types.optional(types.array(types.string), []),
  connect: types.optional(types.array(types.string), []),
});

const trackerModel = types.model('trackerModel', {
  state: types.optional(types.string, 'idle'),
  id: types.identifier(types.string),
  meta: trackerMetaModel,
  info: types.optional(types.model('trackerInfo', {
    lastUpdate: types.optional(types.number, 0),
    disableAutoUpdate: types.optional(types.boolean, false),
  }), {}),
  code: types.maybe(types.string),
}).preProcessSnapshot(snapshot => {
  if (snapshot) {
    if (!snapshot.meta) {
      snapshot.meta = {};
    }
github naguvan / react-mst-form / src / models / form / Form.ts View on Github external
import { getParent, hasParent, ISimpleType } from 'mobx-state-tree';
import { getSnapshot, applySnapshot } from 'mobx-state-tree';
export type __IModelType = IModelType;

import { IFieldConfig, IField } from '@root/types';
import { IFormConfig, IForm } from '@root/types';

import { Field } from '../field/Field';

import { flatArray } from '../../utils';

export const Form: IModelType, IForm> = types
    .model('Form', {
        title: types.string,
        properties: types.map(Field),
        errors: types.optional(types.array(types.string), []),
        layout: types.frozen
    })
    .volatile(it => ({ _validating: false }))
    .actions(it => ({
        afterCreate() {
            const { properties, layout } = it;
            const items = flatArray(layout);
            const invalids = items.filter(item => !properties.has(item));

            if (invalids.length) {
                throw new TypeError(
                    `[${invalids
                        .map(invalid => `'${invalid}'`)
                        .join(', ')}] layout field${
                        invalids.length === 1 ? ' is' : 's are'
                    } not configured.`
github mobxjs / mst-gql / examples / 3-twitter-clone / src / server / models / MessageModel.base.ts View on Github external
replyTo: MessageModelType;
}

/**
 * MessageBase
 * auto generated base class for the model MessageModel.
 */
export const MessageModelBase = withTypedRefs()(ModelBase
  .named('Message')
  .props({
    __typename: types.optional(types.literal("Message"), "Message"),
    id: types.identifier,
    timestamp: types.union(types.undefined, types.number),
    user: types.union(types.undefined, MSTGQLRef(types.late((): any => UserModel))),
    text: types.union(types.undefined, types.string),
    likes: types.union(types.undefined, types.null, types.array(MSTGQLRef(types.late((): any => UserModel)))),
    replyTo: types.union(types.undefined, types.null, MSTGQLRef(types.late((): any => MessageModel))),
  })
  .views(self => ({
    get store() {
      return self.__getStore()
    }
  })))
github coderplanets / coderplanets_admin / stores / SharedModel / Job.js View on Github external
tags: t.optional(t.array(Tag), []),
  comments: t.optional(t.array(Comment), []),

  commentsCount: t.optional(t.number, 0),
  commentsParticipatorsCount: t.optional(t.number, 0),
  commentsParticipators: t.optional(t.array(User), []),
  views: t.optional(t.number, 0),
  favoritedCount: t.optional(t.number, 0),
  starredCount: t.optional(t.number, 0),

  insertedAt: t.optional(t.string, ''),
  updatedAt: t.optional(t.string, ''),
})

export const PagedJobs = t.model('PagedJobs', {
  entries: t.optional(t.array(Job), []),
  pageNumber: t.optional(t.number, 1),
  pageSize: t.optional(t.number, PAGE_SIZE.D),
  totalCount: t.optional(t.number, 0),
  totalPages: t.optional(t.number, 0),
})
github grafana / grafana / public / app / stores / PermissionsStore / PermissionsStore.ts View on Github external
self.userId = null;
      self.userLogin = null;
      self.teamId = teamId;
      self.team = team;
    },
    setPermission(permission: number) {
      self.permission = permission;
    },
  }));

export const PermissionsStore = types
  .model('PermissionsStore', {
    fetching: types.boolean,
    isFolder: types.maybe(types.boolean),
    dashboardId: types.maybe(types.number),
    items: types.optional(types.array(PermissionsStoreItem), []),
    error: types.maybe(types.string),
    originalItems: types.optional(types.array(PermissionsStoreItem), []),
    newType: types.optional(types.string, defaultNewType),
    newItem: types.maybe(NewPermissionsItem),
    isAddPermissionsVisible: types.optional(types.boolean, false),
    isInRoot: types.maybe(types.boolean),
  })
  .views(self => ({
    isValid: item => {
      const dupe = self.items.find(it => {
        return isDuplicate(it, item);
      });
      if (dupe) {
        self.error = duplicateError;
        return false;
      }
github mobxjs / mst-gql / examples / 4-apollo-tutorial / client / src / models / RootStore.js View on Github external
isBooked
      }
    }
  }
`

const loginStatus = types.enumeration("loginStatus", [
  "loggedOut",
  "pending",
  "error",
  "loggedIn"
])

export const RootStore = RootStoreBase.props({
  loginStatus: loginStatus,
  cartItems: types.array(types.string)
})
  .views(self => ({
    get me() {
      return Array.from(self.users.values())[0]
    },
    get hasTrips() {
      return self.me && self.me.trips.length
    }
  }))
  .actions(self => ({
    addOrRemoveFromCart(id) {
      self.cartItems = self.cartItems.includes(id)
        ? self.cartItems.filter(i => i !== id)
        : [...self.cartItems, id]
    },
    cancelTrip(launchId) {