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


TypeScript types.union方法代码示例

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


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

示例1: test

test("can time travel with Mutable object", t => {
    const MutableUnion = types.union(
        types.string,
        types.boolean,
        types.number,
        types.map(types.late(() => MutableUnion)),
        types.array(types.late(() => MutableUnion))
    )
    const MutableStoreModel = types
        .model({
            mutable: MutableUnion
        })
        .actions(self => {
            setUndoManagerDifferentTree(self)
            return {
                setProp(k, v) {
                    self.mutable.set(k, v)
                }
            }
        })
    const store = MutableStoreModel.create({ mutable: {} })
    const mutable = store.mutable

    t.deepEqual(mutable.toJSON(), {})
    t.is(undoManager.canUndo, false)
    t.is(undoManager.canRedo, false)
    t.is(undoManager.history.length, 0)

    store.setProp("foo", 1)
    t.deepEqual(mutable.toJSON(), { foo: 1 })
    t.is(undoManager.canUndo, true)
    t.is(undoManager.canRedo, false)
    t.is(undoManager.history.length, 1)

    store.setProp("foo", {})
    t.deepEqual(mutable.toJSON(), { foo: {} })
    t.is(undoManager.canUndo, true)
    t.is(undoManager.canRedo, false)
    t.is(undoManager.history.length, 2)

    undoManager.undo()
    t.deepEqual(mutable.toJSON(), { foo: 1 })
    t.is(undoManager.canUndo, true)
    t.is(undoManager.canRedo, true)
    t.is(undoManager.history.length, 2)

    undoManager.undo()
    t.deepEqual(mutable.toJSON(), {})
    t.is(undoManager.canUndo, false)
    t.is(undoManager.canRedo, true)
    t.is(undoManager.history.length, 2)
})
开发者ID:lelandyolo,项目名称:mobx-state-tree,代码行数:52,代码来源:UndoManager.ts

示例2: currentUrl

import { types } from 'mobx-state-tree';
import { toJS } from 'mobx';
import { toUrlParams } from 'app/core/utils/url';

const QueryInnerValueType = types.union(types.string, types.boolean, types.number);
const QueryValueType = types.union(QueryInnerValueType, types.array(QueryInnerValueType));

export const ViewStore = types
  .model({
    path: types.string,
    query: types.map(QueryValueType),
    routeParams: types.map(QueryValueType),
  })
  .views(self => ({
    get currentUrl() {
      let path = self.path;

      if (self.query.size) {
        path += '?' + toUrlParams(toJS(self.query));
      }
      return path;
    },
  }))
  .actions(self => {
    // querystring only
    function updateQuery(query: any) {
      self.query.clear();
      for (let key of Object.keys(query)) {
        if (query[key]) {
          self.query.set(key, query[key]);
        }
开发者ID:cboggs,项目名称:grafana,代码行数:31,代码来源:ViewStore.ts

示例3: currentUrl

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

const QueryValueType = types.union(types.string, types.boolean, types.number);
const urlParameterize = queryObj => {
  const keys = Object.keys(queryObj);
  const newQuery = keys.reduce((acc: string, key: string, idx: number) => {
    const preChar = idx === 0 ? '?' : '&';
    return acc + preChar + key + '=' + queryObj[key];
  }, '');

  return newQuery;
};

export const ViewStore = types
  .model({
    path: types.string,
    query: types.map(QueryValueType),
  })
  .views(self => ({
    get currentUrl() {
      let path = self.path;

      if (self.query.size) {
        path += urlParameterize(self.query.toJS());
      }
      return path;
    },
  }))
  .actions(self => {
    function updateQuery(query: any) {
      self.query.clear();
开发者ID:xlson,项目名称:grafana,代码行数:31,代码来源:ViewStore.ts


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