@visactor/vrender-core
Version:
```typescript import { xxx } from '@visactor/vrender-core'; ```
70 lines (59 loc) • 2.95 kB
JavaScript
import { StateDefinitionCompiler } from "./state-definition-compiler";
const compiler = new StateDefinitionCompiler;
function buildEffectiveSourceDefinitions(parentScope, localStateDefinitions, themeStateDefinitions) {
return Object.assign({}, parentScope ? parentScope.effectiveSourceDefinitions : themeStateDefinitions, localStateDefinitions);
}
export function createRootSharedStateScope(stage, themeStateDefinitions) {
return rebuildSharedStateScope({
ownerStage: stage,
themeStateDefinitions: themeStateDefinitions,
effectiveSourceDefinitions: {},
effectiveCompiledDefinitions: new Map,
revision: 0,
dirty: !1,
subtreeActiveDescendants: new Set
}, 0);
}
export 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);
}
export function setSharedStateScopeParent(scope, parentScope) {
return scope.parentScope !== parentScope && (scope.parentScope = parentScope, scope.dirty = !0,
!0);
}
export function setSharedStateScopeLocalDefinitions(scope, localStateDefinitions) {
return scope.localStateDefinitions !== localStateDefinitions && (scope.localStateDefinitions = localStateDefinitions,
rebuildSharedStateScope(scope), !0);
}
export function setRootSharedStateScopeThemeDefinitions(scope, themeStateDefinitions) {
return scope.themeStateDefinitions !== themeStateDefinitions && (scope.themeStateDefinitions = themeStateDefinitions,
rebuildSharedStateScope(scope), !0);
}
export 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;
}
export function ensureSharedStateScopeFresh(scope) {
if (scope) return scope.parentScope && ensureSharedStateScopeFresh(scope.parentScope),
(scope.dirty || scope.parentScope && scope.parentRevisionAtBuild !== scope.parentScope.revision) && rebuildSharedStateScope(scope),
scope;
}
export function collectSharedStateScopeChain(scope) {
const chain = [];
let current = scope;
for (;current; ) chain.push(current), current = current.parentScope;
return chain;
}
//# sourceMappingURL=shared-state-scope.js.map