@lukekaalim/act-recon 1.1.2 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/delta.ts +1 -1
- package/package.json +2 -2
- package/thread.ts +6 -2
- package/update.ts +26 -11
package/CHANGELOG.md
CHANGED
package/delta.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Commit, CommitRef } from "./commit.ts";
|
|
2
2
|
|
|
3
3
|
export type CreateDelta = { ref: CommitRef, next: Commit };
|
|
4
|
-
export type UpdateDelta = { ref: CommitRef, next: Commit, prev: Commit };
|
|
4
|
+
export type UpdateDelta = { ref: CommitRef, next: Commit, prev: Commit, moved: boolean };
|
|
5
5
|
export type RemoveDelta = { ref: CommitRef, prev: Commit };
|
|
6
6
|
export type SkipDelta = { next: Commit };
|
|
7
7
|
|
package/package.json
CHANGED
package/thread.ts
CHANGED
|
@@ -157,6 +157,8 @@ export const createThreadManager = (
|
|
|
157
157
|
}
|
|
158
158
|
|
|
159
159
|
pendingUpdateTargets.clear();
|
|
160
|
+
currentThread.started = true;
|
|
161
|
+
requestWork();
|
|
160
162
|
}
|
|
161
163
|
}
|
|
162
164
|
|
|
@@ -167,6 +169,8 @@ export const createThreadManager = (
|
|
|
167
169
|
})
|
|
168
170
|
if (updateOnPath) {
|
|
169
171
|
if (updateOnPath.targets.some(target => target.id === target.id)) {
|
|
172
|
+
// not sure whats going on here
|
|
173
|
+
} else {
|
|
170
174
|
updateOnPath.targets.push(target);
|
|
171
175
|
}
|
|
172
176
|
} else {
|
|
@@ -195,7 +199,7 @@ export const createThreadManager = (
|
|
|
195
199
|
requestWork();
|
|
196
200
|
}
|
|
197
201
|
|
|
198
|
-
const applyUpdate = (thread: WorkThread, { next, prev, ref, targets,
|
|
202
|
+
const applyUpdate = (thread: WorkThread, { next, prev, ref, targets, moved }: Update) => {
|
|
199
203
|
thread.visited.add(ref.id);
|
|
200
204
|
|
|
201
205
|
const identicalChange = next && prev && (next.id === prev.element.id);
|
|
@@ -254,7 +258,7 @@ export const createThreadManager = (
|
|
|
254
258
|
const commit = Commit.update(ref, next, childRefs);
|
|
255
259
|
|
|
256
260
|
if (prev)
|
|
257
|
-
thread.deltas.updated.push({ ref, prev, next: commit });
|
|
261
|
+
thread.deltas.updated.push({ ref, prev, next: commit, moved });
|
|
258
262
|
else
|
|
259
263
|
thread.deltas.created.push({ ref, next: commit });
|
|
260
264
|
|
package/update.ts
CHANGED
|
@@ -29,29 +29,30 @@ export type Update = {
|
|
|
29
29
|
targets: CommitRef[];
|
|
30
30
|
|
|
31
31
|
suspend: boolean,
|
|
32
|
+
moved: boolean,
|
|
32
33
|
};
|
|
33
34
|
|
|
34
35
|
export const Update = {
|
|
35
36
|
fresh: (ref: CommitRef, next: Element): Update => ({
|
|
36
|
-
ref, next, prev: null, targets: [], suspend: false,
|
|
37
|
+
ref, next, prev: null, targets: [], suspend: false, moved: false,
|
|
37
38
|
}),
|
|
38
|
-
existing: (prev: Commit, next: Element): Update => ({
|
|
39
|
-
ref: prev, next, prev, targets: [], suspend: false,
|
|
39
|
+
existing: (prev: Commit, next: Element, moved: boolean = false): Update => ({
|
|
40
|
+
ref: prev, next, prev, targets: [], suspend: false, moved,
|
|
40
41
|
}),
|
|
41
42
|
remove: (prev: Commit): Update => ({
|
|
42
|
-
ref: prev, next: null, prev, targets: [], suspend: false,
|
|
43
|
+
ref: prev, next: null, prev, targets: [], suspend: false, moved: false,
|
|
43
44
|
}),
|
|
44
45
|
distant: (root: Commit, targets: CommitRef[]): Update => ({
|
|
45
|
-
ref: root, next: root.element, prev: root, targets, suspend: false,
|
|
46
|
+
ref: root, next: root.element, prev: root, targets, suspend: false, moved: false,
|
|
46
47
|
}),
|
|
47
48
|
skip: (prev: Commit, targets: CommitRef[]): Update => ({
|
|
48
|
-
ref: prev, next: prev.element, prev, targets, suspend: false,
|
|
49
|
+
ref: prev, next: prev.element, prev, targets, suspend: false, moved: false,
|
|
49
50
|
}),
|
|
50
51
|
target: (prev: Commit): Update => ({
|
|
51
|
-
ref: prev, next: prev.element, prev, targets: [prev], suspend: false,
|
|
52
|
+
ref: prev, next: prev.element, prev, targets: [prev], suspend: false, moved: false,
|
|
52
53
|
}),
|
|
53
54
|
suspend: (prev: Commit): Update => ({
|
|
54
|
-
ref: prev, next: prev.element, prev, targets: [], suspend: true,
|
|
55
|
+
ref: prev, next: prev.element, prev, targets: [], suspend: true, moved: false,
|
|
55
56
|
})
|
|
56
57
|
}
|
|
57
58
|
|
|
@@ -89,6 +90,18 @@ export const calculateFastUpdate = (
|
|
|
89
90
|
const simpleElementEqualityTest: ChangeEqualityTest<Commit, Element> = (prev, next, prev_index, next_index) =>
|
|
90
91
|
prev.element.type === next.type && prev_index === next_index;
|
|
91
92
|
|
|
93
|
+
const keyedElementEqualityTest: ChangeEqualityTest<Commit, Element> = (prev, next, prev_index, next_index) => {
|
|
94
|
+
const compatible = prev.element.type === next.type;
|
|
95
|
+
if (!compatible)
|
|
96
|
+
return false;
|
|
97
|
+
const prevKey = prev.element.props.key;
|
|
98
|
+
const nextKey = next.props.key;
|
|
99
|
+
if (prevKey || nextKey)
|
|
100
|
+
return prevKey === nextKey;
|
|
101
|
+
|
|
102
|
+
return prev_index === next_index;
|
|
103
|
+
}
|
|
104
|
+
|
|
92
105
|
/**
|
|
93
106
|
* Returns a list of all updates that should
|
|
94
107
|
* occur -- given a set of commits and a
|
|
@@ -110,7 +123,7 @@ export const calculateUpdates = (
|
|
|
110
123
|
if (commits.length <= 1 && elements.length == 1)
|
|
111
124
|
return calculateFastUpdate(parentRef, commits[0], elements[0])
|
|
112
125
|
|
|
113
|
-
const change_report = calculateChangedElements(commits, elements,
|
|
126
|
+
const change_report = calculateChangedElements(commits, elements, keyedElementEqualityTest);
|
|
114
127
|
|
|
115
128
|
const newOrPersisted = elements.map((next, index) => {
|
|
116
129
|
const prevIndex = change_report.nextToPrev[index];
|
|
@@ -118,8 +131,10 @@ export const calculateUpdates = (
|
|
|
118
131
|
|
|
119
132
|
if (!prev)
|
|
120
133
|
return Update.fresh(CommitRef.new(parentRef.path), next);
|
|
121
|
-
|
|
122
|
-
|
|
134
|
+
|
|
135
|
+
const moved = index === prevIndex;
|
|
136
|
+
|
|
137
|
+
return Update.existing(prev, next, moved);
|
|
123
138
|
});
|
|
124
139
|
const removed = change_report.removed.map((index) => {
|
|
125
140
|
const prev = commits[index];
|