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


TypeScript types.late方法代码示例

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


在下文中一共展示了types.late方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: new

export function polymorphic<PROPS extends ModelProperties, OTHERS, TYPE>(Code: new() => TYPE, Model: IModelType<PROPS, OTHERS>, name?: string): IModelType<PROPS, TYPE> {
	// Union of this class and all of its subclasses.
	// Late evaluation allows subclasses to add themselves to the type list
	// before any instances are created.
	const Union: ClassyUnion<PROPS, TYPE> = types.late(() => types.union.apply(types, Union.$typeList)) as any;

	// First item in the type list is a dispatcher function
	// for parsing type tags in snapshots.
	Union.$typeList = [ { dispatcher: (snap: any) =>
		(snap && typeTag && snap[typeTag] && Union.$typeTbl[snap[typeTag]]) || Model
	} ];

	Union.$typeTbl = {};
	Union.$proto = Code.prototype;

	// Copy methods from model object into returned union,
	// making it work like a regular model.

	for(let mixin: { [key: string]: any } = Model; mixin; mixin = Object.getPrototypeOf(mixin)) {
		for(let key of Object.getOwnPropertyNames(mixin)) {
			const desc = Object.getOwnPropertyDescriptor && Object.getOwnPropertyDescriptor(mixin, key);

			if(!desc || (desc.configurable && desc.writable && !desc.get && !desc.set)) {
				const value = !(key in Union) && mixin[key];

				if(typeof(value) == 'function') {
					(Union as { [key: string]: any })[key] = function() {
						return(value.apply(Model, arguments));
					};
				}
			}
		}
	}

	// Initialize union of allowed class substitutes with the class itself,
	// and augment unions of all parent classes with this subclass,
	// to allow polymorphism.

	for(let Class = Union; Class; Class = Class.$proto.$parent) {
		const typeList = Class.$typeList;
		const typeTbl = Class.$typeTbl;

		if(typeList) typeList.push(Model);
		if(typeTbl && name) typeTbl[name] = Model;
	}

	return(Union);
}
开发者ID:ksjogo,项目名称:classy-mst,代码行数:48,代码来源:classy-mst.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:

ďťż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),
  children: types.optional(types.array(types.late(() => NavItem)), []),
});
开发者ID:xiequanqin,项目名称:grafana,代码行数:12,代码来源:NavItem.ts


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