@visactor/vrender-core
Version:
```typescript import { xxx } from '@visactor/vrender-core'; ```
72 lines (60 loc) • 3.13 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: !0
}), exports.getContributionStoreState = exports.CONTRIBUTION_STORE_STATE_SYMBOL = exports.ContributionStore = exports.bindContributionProviderNoSingletonScope = exports.bindContributionProvider = exports.createContributionProvider = exports.ContributionProvider = void 0;
const contribution_store_state_1 = require("./contribution-store-state");
exports.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)));
}
}
function createContributionProvider(serviceIdentifier, container) {
return new ContributionProviderCache(serviceIdentifier, container);
}
function bindContributionProvider(bind, id) {
bind(exports.ContributionProvider).toDynamicValue((({container: container}) => createContributionProvider(id, container))).inSingletonScope().whenTargetNamed(id);
}
function bindContributionProviderNoSingletonScope(bind, id) {
bind(exports.ContributionProvider).toDynamicValue((({container: container}) => createContributionProvider(id, container))).whenTargetNamed(id);
}
exports.createContributionProvider = createContributionProvider, exports.bindContributionProvider = bindContributionProvider,
exports.bindContributionProviderNoSingletonScope = bindContributionProviderNoSingletonScope;
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();
}));
}));
}
}
exports.ContributionStore = ContributionStore, ContributionStore.store = (0, contribution_store_state_1.getContributionStoreState)().store;
var contribution_store_state_2 = require("./contribution-store-state");
Object.defineProperty(exports, "CONTRIBUTION_STORE_STATE_SYMBOL", {
enumerable: !0,
get: function() {
return contribution_store_state_2.CONTRIBUTION_STORE_STATE_SYMBOL;
}
}), Object.defineProperty(exports, "getContributionStoreState", {
enumerable: !0,
get: function() {
return contribution_store_state_2.getContributionStoreState;
}
});
//# sourceMappingURL=contribution-provider.js.map