本文整理汇总了TypeScript中@dojo/shim/WeakMap.get函数的典型用法代码示例。如果您正苦于以下问题:TypeScript get函数的具体用法?TypeScript get怎么用?TypeScript get使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: beforeProperties
beforeProperties(function(this: WidgetBase & { own: Function }, properties: any) {
const injectorItem = this.registry.getInjector<Store<S>>(name);
if (injectorItem) {
const { injector } = injectorItem;
const store = injector();
const registeredInjectors = registeredInjectorsMap.get(this) || [];
if (registeredInjectors.length === 0) {
registeredInjectorsMap.set(this, registeredInjectors);
}
if (registeredInjectors.indexOf(injectorItem) === -1) {
if (paths) {
const handle = store.onChange(paths.map((path: any) => store.path(path.join('/'))), () =>
this.invalidate()
);
this.own({
destroy: () => {
handle.remove();
}
});
} else {
this.own(
store.on('invalidate', () => {
this.invalidate();
})
);
}
registeredInjectors.push(injectorItem);
}
return getProperties(store, properties);
}
})(target);
示例2: Promise
return new Promise((resolve) => {
handlesWeakMap.get(this).forEach((handle) => {
handle && handle.destroy && handle.destroy();
});
this.destroy = noop;
this.own = destroyed;
resolve(true);
});
示例3: findRouter
export function findRouter(route: Route<Context, Parameters>): Router<Context> {
while (route.parent) {
route = route.parent;
}
const router = parentMap.get(route);
if (!router) {
throw new Error('Cannot generate link for route that is not in the hierarchy');
}
else {
return router;
}
}
示例4: do
/**
* A weak map of `do` methods
*/
const doFunctions = new WeakMap<AnyAction, DoFunction<any>>();
/**
* A weak map of `configure` methods
*/
const configureFunctions = new WeakMap<AnyAction, (configuration: Object) => Promise<void> | void>();
/**
* A factory which creates instances of Action
*/
const createAction: ActionFactory = compose<ActionMixin<any, DoOptions<any, TargettedEventObject<any>>>, ActionOptions<any, ActionState>>({
do(this: AnyAction, options?: DoOptions<any, TargettedEventObject<any>>): Task<any> {
const doFn = doFunctions.get(this);
if (doFn && this.state.enabled) {
const result = doFn.call(this, options);
return isTask(result) ? result : Task.resolve(result);
}
return Task.resolve();
},
enable(this: AnyAction): void {
if (!this.state.enabled) {
this.setState({ enabled: true });
}
},
disable(this: AnyAction): void {
if (this.state.enabled) {
this.setState({ enabled: false });
}
示例5: return
function getListItems<T>(list: List<T>): T[] {
return (listItems.get(list) || []) as T[];
}
示例6: parent
get parent() {
return parentMap.get(this);
}
示例7:
function getState<V extends object>(instance: IdentityRegistry<V>): State<V> {
return privateStateMap.get(instance)!;
}
示例8: isDestroyable
* A type guard that determines if the value is a destroyableMixin
*
* @param value The value to guard for
*/
export function isDestroyable(value: any): value is Destroyable {
return Boolean(value && 'destroy' in value && typeof value.destroy === 'function');
}
/**
* A mixin which adds the concepts of being able to *destroy* handles which the instance
* *owns*
*/
const destroyableMixin: DestroyableMixin = compose.createMixin()
.extend('Destroyable', {
own(this: Destroyable, handle: Handle): Handle {
const handles = handlesWeakMap.get(this);
handles.push(handle);
return {
destroy() {
handles.splice(handles.indexOf(handle));
handle.destroy();
}
};
},
destroy(this: Destroyable) {
return new Promise((resolve) => {
handlesWeakMap.get(this).forEach((handle) => {
handle && handle.destroy && handle.destroy();
});
this.destroy = noop;
示例9: state
* Private map of internal instance state.
*/
const instanceStateMap = new WeakMap<Stateful<State>, State>();
/**
* State change event type
*/
const stateChangedEventType = 'state:changed';
/**
* Create an instance of a stateful object
*/
const statefulMixin: StatefulMixin = eventedMixin
.extend('Stateful', {
get state(this: Stateful<State>) {
return instanceStateMap.get(this);
},
setState<S extends State>(this: Stateful<S>, value: Partial<S>) {
const oldState = instanceStateMap.get(this);
const state = deepAssign({}, oldState, value);
const eventObject = {
type: stateChangedEventType,
state,
target: this
};
instanceStateMap.set(this, state);
this.emit(eventObject);
}
})
.init((instance: Stateful<State>) => {
instanceStateMap.set(instance, Object.create(null));