How to use the mobx-state-tree.types.enumeration 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 coderplanets / coderplanets_admin / containers / ArticleViwer / store.js View on Github external
views: t.optional(t.number, 0),
  // author: Author,
  tags: t.optional(t.string, ''), // TODO: ArrayOf Tag
  comments: t.optional(t.string, ''), // TODO: ArrayOf comments
  favoritedCount: t.optional(t.number, 0),
  starredCount: t.optional(t.number, 0),
  viewerHasFavorited: t.optional(t.boolean, false),
  viewerHasStarred: t.optional(t.boolean, false),
  insertedAt: t.optional(t.string, ''),
  updatedAt: t.optional(t.string, ''),
})

const ArticleViwerStore = t
  .model('ArticleViwerStore', {
    type: t.optional(
      t.enumeration('type', [
        TYPE.POST,
        TYPE.JOB,
        // ...
      ]),
      TYPE.POST
    ),
    post: t.optional(Post, {}),
    postLoading: t.optional(t.boolean, false),
  })
  .views(self => ({
    get root() {
      return getParent(self)
    },
    get curPost() {
      return self.post.toJSON()
    },
github coderplanets / coderplanets_web / containers / ErrorBox / store.js View on Github external
const Message = t.model('Message', {
  message: t.string,
  key: t.optional(t.string, ''),
  code: t.optional(t.number, 0),
})

const ChangesetError = t.model('ChangesetError', {
  code: t.maybeNull(t.number),
  message: t.array(Message),
})

const ErrorBox = t
  .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 => ({
github coderplanets / coderplanets_web / containers / JobsThread / store.js View on Github external
import R from 'ramda'

import { TYPE } from '@constant'
import { markStates, buildLog, stripMobx, nilOrEmpty } from '@utils'
import { PagedJobs, Tag, ContentFilter, emptyPagiData } from '@model'

/* eslint-disable-next-line */
const log = buildLog('S:JobsThreadStore')

const JobsThreadStore = t
  .model('JobsThreadStore', {
    pagedJobs: t.optional(PagedJobs, emptyPagiData),
    filters: t.optional(ContentFilter, {}),
    activeTag: t.maybeNull(Tag),
    curView: t.optional(
      t.enumeration('curView', [
        TYPE.RESULT,
        TYPE.LOADING,
        TYPE.NOT_FOUND,
        TYPE.RESULT_EMPTY,
      ]),
      TYPE.RESULT
    ),
    showPublishNote: t.optional(t.boolean, false),
    // runtime: ..
    // data: ...
    // TODO: rename to activeArticle
  })
  .views(self => ({
    get root() {
      return getParent(self)
    },
github coderplanets / coderplanets_web / containers / UserPublished / store.js View on Github external
import { markStates, buildLog, stripMobx } from '@utils'
import {
  PagedPosts,
  PagedJobs,
  PagedVideos,
  PagedRepos,
  emptyPagiData,
} from '@model'

/* eslint-disable-next-line */
const log = buildLog('S:UserPublished')

const UserPublished = t
  .model('UserPublished', {
    curThread: t.optional(
      t.enumeration('curThread', [
        THREAD.POST,
        THREAD.JOB,
        THREAD.VIDEO,
        THREAD.REPO,
      ]),
      THREAD.POST
    ),

    curView: t.optional(
      t.enumeration('curView', [
        TYPE.RESULT,
        TYPE.LOADING,
        TYPE.NOT_FOUND,
        TYPE.RESULT_EMPTY,
      ]),
      TYPE.LOADING
github coderplanets / coderplanets_web / containers / Doraemon / store.js View on Github external
t.enumeration('descType', ['text', 'component']),
    'text'
  ),
})

const DoraemonStore = t
  .model('DoraemonStore', {
    visible: t.optional(t.boolean, false),
    searching: t.optional(t.boolean, false),
    showAlert: t.optional(t.boolean, false),
    showUtils: t.optional(t.boolean, false),
    showThreadSelector: t.optional(t.boolean, false),
    searchedTotalCount: t.optional(t.number, 0),

    searchThread: t.optional(
      t.enumeration('searchThread', [...R.values(THREAD), 'community']),
      'community'
    ),

    inputValue: t.optional(t.string, ''),
    suggestions: t.optional(t.array(Suggestion), []),
    activeRaw: t.maybeNull(t.string),
    // TODO: prefix -> cmdPrefix, and prefix be a getter
    prefix: t.optional(t.string, ''),
    // for log config, input login/password ... etc
    inputForOtherUse: t.optional(t.boolean, false),
    cmdChain: t.maybeNull(t.array(t.string)),
  })
  .views(self => ({
    get root() {
      return getParent(self)
    },
github codesandbox / codesandbox-client / packages / app / src / app / store / modules / dashboard / model.js View on Github external
import { types } from 'mobx-state-tree';

export default {
  selectedSandboxes: types.array(types.string),
  trashSandboxIds: types.array(types.string),
  isDragging: types.boolean,
  orderBy: types.model({
    order: types.enumeration('order', ['desc', 'asc']),
    field: types.string,
  }),
  filters: types.model({
    blacklistedTemplates: types.array(types.string),
    search: types.string,
  }),
};
github zooniverse / front-end-monorepo / packages / lib-classifier / src / plugins / drawingTools / models / tools / PointTool / PointTool.js View on Github external
import { types } from 'mobx-state-tree'
import Tool from '../Tool'
import { Point } from '../../marks'

const PointTool = types.model('Point', {
  marks: types.map(Point),
  size: types.optional(types.enumeration(['large', 'small']), 'large'),
  type: types.literal('point')
})
  .actions(self => {
    function createMark (mark) {
      const newMark = Point.create(mark)
      self.marks.put(newMark)
      return newMark
    }

    return {
      createMark
    }
  })

export default types.compose('PointTool', Tool, PointTool)
github fluid-notion / fluid-outliner / core / models / Note.ts View on Github external
import { types as t } from "mobx-state-tree"
import { v4 as uuid } from "uuid"

const Format = t.enumeration(["markdown", "html", "text"])

export const Note = t
    .model({
        id: t.optional(t.maybe(t.identifier(t.string)), uuid),
        format: Format,
        content: t.optional(t.string, ""),
        placement: t.enumeration(["side", "main"]),
    })
    .actions(self => ({
        setContent(content: string) {
            self.content = content
        },
    }))

export type INote = typeof Note.Type
export type INoteFormat = typeof Format.Type
github birkir / hekla / src / stores / enums / Font.ts View on Github external
}

if (Platform.OS === 'ios') {
  font['American Typewriter'] = 'American Typewriter';
  font['Avenir Next'] = 'Avenir Next';
  font['Georgia'] = 'Georgia';
  font['Iowan Old Style'] = 'Iowan';
  font['Palatino'] = 'Palatino';
  font['Times New Roman'] = 'Times New Roman';
}

export const formatFont = (key: string) => {
  return font[key];
};

export default types.enumeration('Font', Object.keys(font));
github kitze / JSUI / src / utils / mst-utils.js View on Github external
export const typeFromEnum = (name, enumz) => types.enumeration(name, map(enumz, e => e));