一些小的修正

This commit is contained in:
Xu Chang 2022-05-26 11:03:44 +08:00
parent e5320e868d
commit c4971901b8
3 changed files with 44 additions and 26 deletions

View File

@ -219,7 +219,14 @@ class ListNode<ED extends EntityDict,
getChild(path: string): SingleNode<ED, T, Cxt, AD> {
const idx = parseInt(path, 10);
assert(typeof idx === 'number');
return this.children[idx];
if (idx < this.children.length) {
return this.children[idx];
}
else {
const idx2 = idx - this.children.length;
// assert(idx2 < this.newBorn.length); // 在删除结点时可能还是会跑到
return this.newBorn[idx2];
}
}
getChildren() {
@ -242,16 +249,12 @@ class ListNode<ED extends EntityDict,
}
setValue(value: SelectRowShape<ED[T]['OpSchema'], ED[T]['Selection']['data']>[]) {
this.children = [];
value.forEach(
(ele, idx) => {
if (this.children[idx]) {
this.children[idx].setValue(ele);
}
else {
const node = new SingleNode(this.entity, this.schema, this.cache, this.projection, this.projectionShape, this);
this.children[idx] = node;
node.setValue(ele);
}
const node = new SingleNode(this.entity, this.schema, this.cache, this.projection, this.projectionShape, this);
this.children[idx] = node;
node.setValue(ele);
}
);
}
@ -562,7 +565,7 @@ class SingleNode<ED extends EntityDict,
const projection2 = await projection();
return projection2[attr].filter;
} : projection[attr].filter;
const sorters = typeof projection === 'function' ? async () => {
const sorters = typeof projection === 'function' ? async () => {
const projection2 = await projection();
return projection2[attr].sorter;
} : projection[attr].sorter;
@ -686,7 +689,7 @@ class SingleNode<ED extends EntityDict,
const projection = await this.getProjection();
if (this.id) {
this.refreshing = true;
const { result: [ value ]} = await this.cache.refresh(this.entity, {
const { result: [value] } = await this.cache.refresh(this.entity, {
data: projection,
filter: {
id: this.id,
@ -980,15 +983,18 @@ export class RunningTree<ED extends EntityDict, Cxt extends Context<ED>, AD exte
async getValue(path: string) {
const node = this.findNode(path);
let value: ReturnType<typeof node.getValue> | undefined = node.getValue();
if (node) {
let value: ReturnType<typeof node.getValue> | undefined = node.getValue();
if (node.isDirty()) {
const operation = await node.composeOperation();
const projection = await node.getProjection();
value = (await this.applyOperation(node.getEntity(), cloneDeep(value), operation!, projection, path));
if (node.isDirty()) {
const operation = await node.composeOperation();
const projection = await node.getProjection();
value = (await this.applyOperation(node.getEntity(), cloneDeep(value), operation!, projection, path));
}
return value instanceof Array ? value : [value];
}
return value instanceof Array ? value : [value];
return [undefined];
}
isDirty(path: string) {
@ -1227,7 +1233,7 @@ export class RunningTree<ED extends EntityDict, Cxt extends Context<ED>, AD exte
const parentNode = this.findNode(parent);
const node = parentNode.getChild(path);
assert (parentNode instanceof ListNode && node instanceof SingleNode); // 现在应该不可能remove一个list吧未来对list的处理还要细化
assert(parentNode instanceof ListNode && node instanceof SingleNode); // 现在应该不可能remove一个list吧未来对list的处理还要细化
if (node.getValue().id) {
// 如果有id说明是删除数据
await this.getAspectProxy().operate({

View File

@ -9,3 +9,4 @@ export * from './types/Feature';
export * from './types/ExceptionRoute';
export { BasicFeatures } from './features';
export * from './features/cache';
export * from './features/upload';

View File

@ -89,7 +89,7 @@ type OakComponentMethods<ED extends EntityDict, T extends keyof ED> = {
subscribed?: () => void;
subscribe: () => void;
unsubscribe: () => void;
reRender: (extra?: any) => Promise<void>;
reRender: (extra?: Record<string, any>) => Promise<void>;
pushNode: (path?: string, options?: Pick<CreateNodeOptions<ED, keyof ED>, 'updateData' | 'beforeExecute' | 'afterExecute'>) => void;
removeNode: (parent: string, path: string) => void;
setUpdateData: (attr: string, input: any) => void;
@ -223,7 +223,7 @@ function createPageOptions<ED extends EntityDict,
newOakActions: Array,
},
methods: {
async reRender() {
async reRender(extra) {
if (this.data.oakFullpath) {
const $rows = await features.runningTree.getValue(this.data.oakFullpath);
const data = await formData.call(this, $rows as any, features);
@ -254,6 +254,9 @@ function createPageOptions<ED extends EntityDict,
oakLegalActions,
});
}
if (extra) {
assign(data, extra);
}
this.setData(data);
}
@ -679,7 +682,7 @@ function createComponentOptions<ED extends EntityDict,
}
},
async reRender() {
async reRender(extra) {
if (this.data.oakFullpath) {
const $rows = await features.runningTree.getValue(this.data.oakFullpath);
const data = await formData.call(this, $rows as any, features);
@ -711,6 +714,9 @@ function createComponentOptions<ED extends EntityDict,
});
} */
if (extra) {
assign(data, extra);
}
this.setData(data);
}
},
@ -721,7 +727,9 @@ function createComponentOptions<ED extends EntityDict,
if (path2 && parent2) {
const oakFullpath2 = `${parent2}.${path2}`;
if (oakFullpath2 !== this.data.oakFullpath) {
this.data.oakFullpath = oakFullpath2;
this.setData({
oakFullpath: oakFullpath2,
});
this.reRender();
}
}
@ -852,7 +860,10 @@ function createComponentOptions<ED extends EntityDict,
async ready() {
const { oakPath, oakParent } = this.data;
if (oakParent && oakPath) {
this.data.oakFullpath = `${oakParent}.${oakPath}`;
const oakFullpath = `${oakParent}.${oakPath}`;
this.setData({
oakFullpath,
});
this.reRender();
}
},