UNPKG

@visactor/vrender-core

Version:

```typescript import { xxx } from '@visactor/vrender-core'; ```

39 lines (34 loc) 1.56 kB
export const ContributionProvider = Symbol("ContributionProvider"); class ContributionProviderCache { constructor(serviceIdentifier, container) { this.serviceIdentifier = serviceIdentifier, this.container = container, ContributionStore.setStore(this.serviceIdentifier, this); } getContributions() { return this.caches || (this.caches = [], this.container && this.container.isBound(this.serviceIdentifier) && this.caches.push(...this.container.getAll(this.serviceIdentifier))), this.caches; } refresh() { this.caches && (this.caches.length = 0, this.container && this.container.isBound(this.serviceIdentifier) && this.caches.push(...this.container.getAll(this.serviceIdentifier))); } } export function bindContributionProvider(bind, id) { bind(ContributionProvider).toDynamicValue((({container: container}) => new ContributionProviderCache(id, container))).inSingletonScope().whenTargetNamed(id); } export function bindContributionProviderNoSingletonScope(bind, id) { bind(ContributionProvider).toDynamicValue((({container: container}) => new ContributionProviderCache(id, container))).whenTargetNamed(id); } export class ContributionStore { static getStore(id) { return this.store.get(id); } static setStore(id, cache) { this.store.set(id, cache); } static refreshAllContributions() { this.store.forEach((cache => { cache.refresh(); })); } } ContributionStore.store = new Map; //# sourceMappingURL=contribution-provider.js.map