@visactor/vrender-core
Version:
```typescript import { xxx } from '@visactor/vrender-core'; ```
80 lines (67 loc) • 3.9 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: !0
}), exports.collectSharedStateScopeChain = exports.ensureSharedStateScopeFresh = exports.rebuildSharedStateScope = exports.setRootSharedStateScopeThemeDefinitions = exports.setSharedStateScopeLocalDefinitions = exports.setSharedStateScopeParent = exports.createGroupSharedStateScope = exports.createRootSharedStateScope = void 0;
const state_definition_compiler_1 = require("./state-definition-compiler"), compiler = new state_definition_compiler_1.StateDefinitionCompiler;
function buildEffectiveSourceDefinitions(parentScope, localStateDefinitions, themeStateDefinitions) {
return Object.assign({}, parentScope ? parentScope.effectiveSourceDefinitions : themeStateDefinitions, localStateDefinitions);
}
function createRootSharedStateScope(stage, themeStateDefinitions) {
return rebuildSharedStateScope({
ownerStage: stage,
themeStateDefinitions: themeStateDefinitions,
effectiveSourceDefinitions: {},
effectiveCompiledDefinitions: new Map,
revision: 0,
dirty: !1,
subtreeActiveDescendants: new Set
}, 0);
}
function createGroupSharedStateScope(group, parentScope, localStateDefinitions) {
return rebuildSharedStateScope({
ownerStage: group.stage,
parentScope: parentScope,
localStateDefinitions: localStateDefinitions,
effectiveSourceDefinitions: {},
effectiveCompiledDefinitions: new Map,
revision: 0,
dirty: !1,
subtreeActiveDescendants: new Set
}, 0);
}
function setSharedStateScopeParent(scope, parentScope) {
return scope.parentScope !== parentScope && (scope.parentScope = parentScope, scope.dirty = !0,
!0);
}
function setSharedStateScopeLocalDefinitions(scope, localStateDefinitions) {
return scope.localStateDefinitions !== localStateDefinitions && (scope.localStateDefinitions = localStateDefinitions,
rebuildSharedStateScope(scope), !0);
}
function setRootSharedStateScopeThemeDefinitions(scope, themeStateDefinitions) {
return scope.themeStateDefinitions !== themeStateDefinitions && (scope.themeStateDefinitions = themeStateDefinitions,
rebuildSharedStateScope(scope), !0);
}
function rebuildSharedStateScope(scope, revision = scope.revision + 1) {
var _a;
const effectiveSourceDefinitions = buildEffectiveSourceDefinitions(scope.parentScope, scope.localStateDefinitions, scope.themeStateDefinitions);
return scope.effectiveSourceDefinitions = effectiveSourceDefinitions, scope.effectiveCompiledDefinitions = compiler.compile(effectiveSourceDefinitions),
scope.parentRevisionAtBuild = null === (_a = scope.parentScope) || void 0 === _a ? void 0 : _a.revision,
scope.revision = revision, scope.dirty = !1, scope;
}
function ensureSharedStateScopeFresh(scope) {
if (scope) return scope.parentScope && ensureSharedStateScopeFresh(scope.parentScope),
(scope.dirty || scope.parentScope && scope.parentRevisionAtBuild !== scope.parentScope.revision) && rebuildSharedStateScope(scope),
scope;
}
function collectSharedStateScopeChain(scope) {
const chain = [];
let current = scope;
for (;current; ) chain.push(current), current = current.parentScope;
return chain;
}
exports.createRootSharedStateScope = createRootSharedStateScope, exports.createGroupSharedStateScope = createGroupSharedStateScope,
exports.setSharedStateScopeParent = setSharedStateScopeParent, exports.setSharedStateScopeLocalDefinitions = setSharedStateScopeLocalDefinitions,
exports.setRootSharedStateScopeThemeDefinitions = setRootSharedStateScopeThemeDefinitions,
exports.rebuildSharedStateScope = rebuildSharedStateScope, exports.ensureSharedStateScopeFresh = ensureSharedStateScopeFresh,
exports.collectSharedStateScopeChain = collectSharedStateScopeChain;
//# sourceMappingURL=shared-state-scope.js.map