@lukekaalim/act-backstage 1.3.0 → 2.0.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/package.json +2 -2
- package/render.ts +12 -35
- package/space.ts +13 -2
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
package/render.ts
CHANGED
|
@@ -1,52 +1,29 @@
|
|
|
1
|
-
import { CommitTree, createReconciler } from "@lukekaalim/act-recon";
|
|
1
|
+
import { CommitTree, createReconciler, Scheduler, WorkThread } from "@lukekaalim/act-recon";
|
|
2
2
|
import { RenderSpace } from "./space";
|
|
3
3
|
import * as act from '@lukekaalim/act';
|
|
4
4
|
|
|
5
|
-
export type ScheduleRequestFunc<ID> = (callback: () => void) => ID;
|
|
6
|
-
export type ScheduleCancelFunc<ID> = (id: ID) => void;
|
|
7
|
-
|
|
8
|
-
export type Scheduler<ID> = {
|
|
9
|
-
duration: number,
|
|
10
|
-
|
|
11
|
-
request: ScheduleRequestFunc<ID>,
|
|
12
|
-
cancel: ScheduleCancelFunc<ID>,
|
|
13
|
-
}
|
|
14
|
-
|
|
15
5
|
export type RenderFunction<T> = (node: act.Node, root: T) => { stop: () => void }
|
|
16
6
|
|
|
17
|
-
export const createRenderFunction = <
|
|
18
|
-
scheduler: Scheduler
|
|
7
|
+
export const createRenderFunction = <T>(
|
|
8
|
+
scheduler: Scheduler,
|
|
19
9
|
createSpace: (tree: CommitTree, root: T) => RenderSpace
|
|
20
10
|
): RenderFunction<T> => {
|
|
11
|
+
|
|
21
12
|
const render: RenderFunction<T> = (node: act.Node, root: T) => {
|
|
22
|
-
const
|
|
23
|
-
space.create(deltas).configure();
|
|
24
|
-
}
|
|
25
|
-
scheduler.cancel(id);
|
|
26
|
-
id = scheduler.request(work)
|
|
27
|
-
});
|
|
13
|
+
const onThreadComplete = (thread: WorkThread) => {
|
|
14
|
+
space.create(thread.deltas).configure();
|
|
15
|
+
};
|
|
28
16
|
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
const work = () => {
|
|
32
|
-
const start = performance.now();
|
|
33
|
-
const end = start + scheduler.duration;
|
|
34
|
-
const done = reconciler.threads.work(() => {
|
|
35
|
-
const now = performance.now();
|
|
36
|
-
return now >= end;
|
|
37
|
-
})
|
|
38
|
-
if (done) {
|
|
39
|
-
scheduler.cancel(id)
|
|
40
|
-
}
|
|
41
|
-
}
|
|
17
|
+
const reconciler = createReconciler(scheduler);
|
|
18
|
+
const threadCompleteSub = reconciler.on('on-thread-complete', onThreadComplete);
|
|
42
19
|
|
|
43
|
-
|
|
20
|
+
const space = createSpace(reconciler.tree, root);
|
|
44
21
|
|
|
45
|
-
reconciler.
|
|
22
|
+
reconciler.mount(node);
|
|
46
23
|
|
|
47
24
|
return {
|
|
48
25
|
stop() {
|
|
49
|
-
|
|
26
|
+
threadCompleteSub.cancel();
|
|
50
27
|
},
|
|
51
28
|
}
|
|
52
29
|
};
|
package/space.ts
CHANGED
|
@@ -41,6 +41,18 @@ export type NodeRef<T> = {
|
|
|
41
41
|
node: T,
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
/**
|
|
45
|
+
* A "simple" render space is just a conventional
|
|
46
|
+
* render space where we keep track of each commit
|
|
47
|
+
* in a map - and take a "SimpleRenderSpaceArgs"
|
|
48
|
+
* args object that tells us how we make, link,
|
|
49
|
+
* sort, and update our nodes.
|
|
50
|
+
*
|
|
51
|
+
* @param tree
|
|
52
|
+
* @param args
|
|
53
|
+
* @param nodeByCommit
|
|
54
|
+
* @returns
|
|
55
|
+
*/
|
|
44
56
|
export const createSimpleRenderSpace = <T, R extends string | Symbol>(
|
|
45
57
|
tree: recon.CommitTree,
|
|
46
58
|
args: SimpleRenderSpaceArgs<T, R>,
|
|
@@ -79,7 +91,7 @@ export const createSimpleRenderSpace = <T, R extends string | Symbol>(
|
|
|
79
91
|
if (node)
|
|
80
92
|
return { id, node }
|
|
81
93
|
}
|
|
82
|
-
// this element has no parents - it is probably a "root" commit
|
|
94
|
+
// this element has no "node" parents - it is probably a "root" commit
|
|
83
95
|
return null;
|
|
84
96
|
}
|
|
85
97
|
const findRootId = (ref: recon.CommitRef) => {
|
|
@@ -121,7 +133,6 @@ export const createSimpleRenderSpace = <T, R extends string | Symbol>(
|
|
|
121
133
|
commitByNode.set(node, delta.ref.id)
|
|
122
134
|
}
|
|
123
135
|
}
|
|
124
|
-
|
|
125
136
|
}
|
|
126
137
|
|
|
127
138
|
return {
|