UNPKG

@visactor/vrender-core

Version:

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

51 lines (43 loc) 2.15 kB
import { getContributionStoreState } from "./contribution-store-state"; 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 createContributionProvider(serviceIdentifier, container) { return new ContributionProviderCache(serviceIdentifier, container); } export function bindContributionProvider(bind, id) { bind(ContributionProvider).toDynamicValue((({container: container}) => createContributionProvider(id, container))).inSingletonScope().whenTargetNamed(id); } export function bindContributionProviderNoSingletonScope(bind, id) { bind(ContributionProvider).toDynamicValue((({container: container}) => createContributionProvider(id, container))).whenTargetNamed(id); } export class ContributionStore { static getStore(id) { var _a; return null === (_a = this.store.get(id)) || void 0 === _a ? void 0 : _a.values().next().value; } static setStore(id, cache) { let caches = this.store.get(id); caches || (caches = new Set, this.store.set(id, caches)), caches.add(cache); } static refreshAllContributions() { this.store.forEach((caches => { caches.forEach((cache => { cache.refresh(); })); })); } } ContributionStore.store = getContributionStoreState().store; export { CONTRIBUTION_STORE_STATE_SYMBOL, getContributionStoreState } from "./contribution-store-state"; //# sourceMappingURL=contribution-provider.js.map