From 68982ebcb048a961e9af1997ef43b8bff9339864 Mon Sep 17 00:00:00 2001 From: cjc <431909623@qq.com> Date: Fri, 29 Apr 2022 22:42:03 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=B8=8A=E4=B8=80=E6=AD=A5?= =?UTF-8?q?=E9=AB=98=E4=BA=AE=E7=9A=84Model=E4=B8=8E=E5=8E=9F=E6=9D=A5?= =?UTF-8?q?=E7=9A=84Model=E4=B8=80=E6=A0=B7=E7=9A=84=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/View/reconcile.ts | 28 ++++++++++++++++++++++++++-- src/View/viewContainer.ts | 8 +++++++- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/View/reconcile.ts b/src/View/reconcile.ts index 7f1b5d5..e5bdf71 100644 --- a/src/View/reconcile.ts +++ b/src/View/reconcile.ts @@ -23,6 +23,7 @@ export class Reconcile { private engine: Engine; private renderer: Renderer; private isFirstPatch: boolean; + private prevUpdate: string[][] = []; constructor(engine: Engine, renderer: Renderer) { this.engine = engine; @@ -167,6 +168,14 @@ export class Reconcile { return removedModels; } + private getModelsById(ids: string[], modelList: SVModel[]): SVModel[] { + return modelList.filter(item => + ids?.find(id => { + return id === item.id; + }) + ); + } + /** * 找出重新指向的外部指针 * @param prevModelList @@ -231,6 +240,10 @@ export class Reconcile { return freedNodes; } + public setPrevUpdataId(prevUpdataId: string[]) { + this.prevUpdate.push(prevUpdataId); + } + // ------------------------------------------------------------------------------------------------ /** @@ -392,18 +405,29 @@ export class Reconcile { prevModelList: SVModel[], modelList: SVModel[], accumulateLeakModels: SVModel[], - isDiffLeak: boolean + isDiffLeak: boolean, + hasTriggerLastStep: boolean ): DiffResult { + if (hasTriggerLastStep) { + this.prevUpdate.pop(); + } const continuousModels: SVModel[] = this.getContinuousModels(prevModelList, modelList); const leakModels: SVModel[] = isDiffLeak ? [] : this.getLeakModels(layoutGroupTable, prevModelList, modelList); const appendModels: SVModel[] = this.getAppendModels(prevModelList, modelList, accumulateLeakModels); const removeModels: SVModel[] = this.getRemoveModels(prevModelList, modelList, accumulateLeakModels); - const updateModels: SVModel[] = [ + const updateModels: SVModel[] = hasTriggerLastStep ? [...this.getModelsById(this.prevUpdate.pop(), modelList)]: [ ...this.getReTargetMarkers(prevModelList, modelList), ...this.getLabelChangeModels(prevModelList, modelList), ...this.filterUnChangeModelsOfAppend(appendModels, prevModelList), ...leakModels, ]; + + let UpdataModelsId: string [] =[]; + for (let model of updateModels) { + UpdataModelsId.push(model.id); + } + this.prevUpdate?.push(UpdataModelsId); + const freedModels: SVNode[] = this.getFreedModels(prevModelList, modelList); return { diff --git a/src/View/viewContainer.ts b/src/View/viewContainer.ts index a39a67b..977b86e 100644 --- a/src/View/viewContainer.ts +++ b/src/View/viewContainer.ts @@ -168,6 +168,10 @@ export class ViewContainer { }); } + private setPrevUpdateId(prevUpdataId: string[]) { + this.reconcile.setPrevUpdataId(prevUpdataId) + } + /** * 渲染所有视图 * @param models @@ -184,6 +188,7 @@ export class ViewContainer { // 如果数据没变的话,直接退出 if (isSameSources) { + this.setPrevUpdateId([]) return; } @@ -196,7 +201,8 @@ export class ViewContainer { modelList, this.accumulateLeakModels, // handleUpdate?.isEnterFunction - isDiffLeak + isDiffLeak, + handleUpdate?.hasTriggerLastStep ), renderModelList = [...modelList, ...diffResult.REMOVE, ...diffResult.LEAKED, ...this.accumulateLeakModels];