@aitianyu.cn/tianyu-store
Version:
tianyu storage for nodejs.
63 lines • 2.97 kB
JavaScript
;
/** @format */
Object.defineProperty(exports, "__esModule", { value: true });
exports.GetChildInstances = exports.GetParentInstance = exports.GetInstanceExist = void 0;
const SelectorFactor_1 = require("../SelectorFactor");
const StoreState_1 = require("./interface/StoreState");
const InstanceIdImpl_1 = require("../impl/InstanceIdImpl");
const RedoUndoStack_1 = require("./interface/RedoUndoStack");
exports.GetInstanceExist = SelectorFactor_1.SelectorFactor.makeParameterSelector(function (state, instanceId) {
if (InstanceIdImpl_1.InstanceIdImpl.isAncestor(instanceId)) {
return true;
}
const storeType = instanceId.storeType;
const instanceId2String = instanceId.toString();
return Boolean(state[StoreState_1.STORE_STATE_INSTANCE][storeType]?.[instanceId2String]);
});
exports.GetParentInstance = SelectorFactor_1.SelectorFactor.makeParameterSelector(function (state, instanceId, isRedoUndo) {
let parentString = null;
if (!isRedoUndo) {
parentString = state[StoreState_1.STORE_STATE_SYSTEM].instanceMap.parentMap[instanceId.toString()];
}
else {
const parentIns = instanceId.parent;
if (InstanceIdImpl_1.InstanceIdImpl.isAncestor(parentIns)) {
parentString = null;
}
else {
const storeType = parentIns.storeType;
const parentInsString = parentIns.toString();
if (state[StoreState_1.STORE_STATE_INSTANCE][storeType]?.[parentInsString]) {
parentString = parentInsString;
}
}
}
return parentString ? new InstanceIdImpl_1.InstanceIdImpl(parentString) : null;
}, function (register) {
const redoUndoStack = register.get(RedoUndoStack_1.STORE_STATE_EXTERNAL_REDOUNDO_STACK);
return Boolean(redoUndoStack?.canRedo);
});
exports.GetChildInstances = SelectorFactor_1.SelectorFactor.makeParameterSelector(function (state, instanceId, isRedoUndo) {
const childIns = [];
if (!isRedoUndo) {
for (const child of state[StoreState_1.STORE_STATE_SYSTEM].instanceMap.childrenMap[instanceId.toString()] || []) {
childIns.push(new InstanceIdImpl_1.InstanceIdImpl(child));
}
}
else {
for (const storeType of Object.keys(state[StoreState_1.STORE_STATE_INSTANCE])) {
const storeIns = state[StoreState_1.STORE_STATE_INSTANCE][storeType];
for (const instanceString of Object.keys(storeIns)) {
const ins = new InstanceIdImpl_1.InstanceIdImpl(instanceString);
if (ins.parent.equals(instanceId)) {
childIns.push(ins);
}
}
}
}
return childIns;
}, function (register) {
const redoUndoStack = register.get(RedoUndoStack_1.STORE_STATE_EXTERNAL_REDOUNDO_STACK);
return Boolean(redoUndoStack?.canRedo);
});
//# sourceMappingURL=StoreEntitySelector.js.map