当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript types.optional方法代码示例

本文整理汇总了TypeScript中mobx-state-tree.types.optional方法的典型用法代码示例。如果您正苦于以下问题:TypeScript types.optional方法的具体用法?TypeScript types.optional怎么用?TypeScript types.optional使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mobx-state-tree.types的用法示例。


在下文中一共展示了types.optional方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: test

test("it can time travel same store and persist state", t => {
    const W = types.model({
        model: types.optional(TestModel, {}),
        traveler: types.optional(TimeTraveller, { targetPath: "../model" })
    })
    const w = W.create()
    const m = w.model
    const tt = w.traveler

    t.is(tt.canUndo, false)
    t.is(tt.canRedo, false)
    t.is(m.x, 1)

    m.inc()
    t.is(tt.canUndo, true)
    t.is(tt.canRedo, false)
    t.is(m.x, 2)

    m.inc()
    t.is(tt.canUndo, true)
    t.is(tt.canRedo, false)
    t.is(m.x, 3)

    tt.undo()
    t.is(m.x, 2)
    t.is(tt.canUndo, true)
    t.is(tt.canRedo, true)

    // Clone of the store should inherit the same state!
    const w2 = clone(w)
    const m2 = w2.model
    const tt2 = w2.traveler

    tt2.undo()
    t.is(m2.x, 1)
    t.is(tt2.canUndo, false)
    t.is(tt2.canRedo, true)

    tt2.redo()
    t.is(m2.x, 2)
    t.is(tt2.canUndo, true)
    t.is(tt2.canRedo, true)

    // resets 'future'
    m2.inc()
    t.is(m2.x, 3)
    t.is(tt2.canUndo, true)
    t.is(tt2.canRedo, false)
})
开发者ID:lelandyolo,项目名称:mobx-state-tree,代码行数:49,代码来源:TimeTraveller.ts

示例2: test

test("on tree - group", t => {
    const HistoryOnTreeStoreModel = types
        .model({
            x: 1,
            history: types.optional(UndoManager, {})
        })
        .actions(self => {
            setUndoManagerSameTree(self)
            return {
                inc() {
                    self.x += 1
                }
            }
        })
    const store = HistoryOnTreeStoreModel.create()

    t.is(undoManager.canUndo, false)
    t.is(undoManager.canRedo, false)
    t.is(store.x, 1)

    undoManager.startGroup(() => {
        store.inc()
        store.inc()
        store.inc()
        store.inc()
    })
    undoManager.stopGroup()
    t.is(store.x, 5)
    t.is(undoManager.canUndo, true)

    undoManager.undo()
    t.is(undoManager.canUndo, false)
    t.is(undoManager.canRedo, true)
    t.is(store.x, 2)
})
开发者ID:lelandyolo,项目名称:mobx-state-tree,代码行数:35,代码来源:UndoManager.ts

示例3:

import { types } from 'mobx-state-tree';

export const NavItem = types.model('NavItem', {
  id: types.identifier(types.string),
  text: types.string,
  url: types.optional(types.string, ''),
  subTitle: types.optional(types.string, ''),
  icon: types.optional(types.string, ''),
  img: types.optional(types.string, ''),
  active: types.optional(types.boolean, false),
  hideFromTabs: types.optional(types.boolean, false),
  breadcrumbs: types.optional(types.array(types.late(() => Breadcrumb)), []),
  children: types.optional(types.array(types.late(() => NavItem)), []),
});

export const Breadcrumb = types.model('Breadcrumb', {
  title: types.string,
  url: types.string,
});
开发者ID:cboggs,项目名称:grafana,代码行数:19,代码来源:NavItem.ts

示例4: canUndo

    IModelType,
    ISnapshottable,
    IMiddlewareEvent,
    IPatchRecorder,
    IJsonPatch
} from "mobx-state-tree"
import { IObservableArray } from "mobx"

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

const UndoManager = types
    .model("UndoManager", {
        history: types.optional(types.array(Entry), []),
        undoIdx: 0
    })
    .views(self => ({
        get canUndo() {
            return self.undoIdx > 0
        },
        get canRedo() {
            return self.undoIdx < self.history.length
        }
    }))
    .actions(self => {
        let skipping = false
        let flagSkipping = false
        let targetStore: IStateTreeNode
        let replaying = false
开发者ID:lelandyolo,项目名称:mobx-state-tree,代码行数:31,代码来源:undo-manager.ts

示例5:

  'POST_PRODUCTION',
]);

export const MovieLocale = types.model('MovieLocale', {
  id: types.identifier,
  locale: Locale,
  contentRating: types.maybeNull(types.string),
  title: types.maybeNull(types.string),
  summary: types.maybeNull(types.string),
  alternateTitle: types.maybeNull(types.string),
  releaseDate: types.maybeNull(types.string),
});

export const Movie = types.model('Movie', {
  id: types.identifier,
  isPartial: types.optional(types.boolean, true),
  title: types.maybeNull(types.string),
  year: types.maybeNull(types.number),
  summary: types.maybeNull(types.string),
  runtime: types.maybeNull(types.number),
  backdropUrl: types.maybeNull(types.string),
  posterUrl: types.maybeNull(types.string),
  releaseDate: types.maybeNull(types.string),
  adult: types.maybeNull(types.boolean),
  imdbId: types.maybeNull(types.string),
  externalId: types.maybeNull(types.number),
  tmdbId: types.maybeNull(types.number),
  budget: types.maybeNull(types.number),
  revenue: types.maybeNull(types.number),
  homepage: types.maybeNull(types.string),
  originalLanguage: types.maybeNull(types.string),
开发者ID:birkir,项目名称:kvikmyndr-app,代码行数:31,代码来源:Movie.ts

示例6: flow

ďťżimport { types, getEnv, flow } from 'mobx-state-tree';
import { ServerStat } from './ServerStat';

export const ServerStatsStore = types
  .model('ServerStatsStore', {
    stats: types.array(ServerStat),
    error: types.optional(types.string, ''),
  })
  .actions(self => ({
    load: flow(function* load() {
      const backendSrv = getEnv(self).backendSrv;
      const res = yield backendSrv.get('/api/admin/stats');
      self.stats.clear();
      self.stats.push(ServerStat.create({ name: 'Total dashboards', value: res.dashboards }));
      self.stats.push(ServerStat.create({ name: 'Total users', value: res.users }));
      self.stats.push(ServerStat.create({ name: 'Active users (seen last 30 days)', value: res.activeUsers }));
      self.stats.push(ServerStat.create({ name: 'Total orgs', value: res.orgs }));
      self.stats.push(ServerStat.create({ name: 'Total playlists', value: res.playlists }));
      self.stats.push(ServerStat.create({ name: 'Total snapshots', value: res.snapshots }));
      self.stats.push(ServerStat.create({ name: 'Total dashboard tags', value: res.tags }));
      self.stats.push(ServerStat.create({ name: 'Total starred dashboards', value: res.stars }));
      self.stats.push(ServerStat.create({ name: 'Total alerts', value: res.alerts }));
    }),
  }));
开发者ID:GPegel,项目名称:grafana,代码行数:24,代码来源:ServerStatsStore.ts


注:本文中的mobx-state-tree.types.optional方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。