@lukekaalim/act-backstage 1.2.1 → 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 CHANGED
@@ -1,5 +1,28 @@
1
1
  # @lukekaalim/act-backstage
2
2
 
3
+ ## 2.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - Scheduling refactor
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies
12
+ - @lukekaalim/act-recon@2.0.0
13
+
14
+ ## 1.3.0
15
+
16
+ ### Minor Changes
17
+
18
+ - Added support for keys/reordering elements without unmounting them
19
+
20
+ ### Patch Changes
21
+
22
+ - Updated dependencies
23
+ - @lukekaalim/act-recon@1.2.0
24
+ - @lukekaalim/act@3.2.0
25
+
3
26
  ## 1.2.1
4
27
 
5
28
  ### Patch Changes
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@lukekaalim/act-backstage",
3
- "version": "1.2.1",
3
+ "version": "2.0.0",
4
4
  "main": "mod.ts",
5
5
  "dependencies": {
6
- "@lukekaalim/act": "^3.1.0",
7
- "@lukekaalim/act-recon": "^1.1.1"
6
+ "@lukekaalim/act": "^3.2.0",
7
+ "@lukekaalim/act-recon": "^2.0.0"
8
8
  }
9
9
  }
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 = <S, T>(
18
- scheduler: Scheduler<S>,
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 reconciler = createReconciler(deltas => {
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 space = createSpace(reconciler.tree, root);
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
- let id = scheduler.request(work);
20
+ const space = createSpace(reconciler.tree, root);
44
21
 
45
- reconciler.threads.mount(node);
22
+ reconciler.mount(node);
46
23
 
47
24
  return {
48
25
  stop() {
49
- scheduler.cancel(id);
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 {
@@ -146,6 +157,13 @@ export const createSimpleRenderSpace = <T, R extends string | Symbol>(
146
157
  if (!node)
147
158
  continue;
148
159
  args.update(node, delta.next.element, delta.prev.element);
160
+ if (delta.moved) {
161
+ const parent = findParent(delta.ref);
162
+ const parentNode = parent && parent.node;
163
+ if (parentNode) {
164
+ needsReorder.add(parent.id)
165
+ }
166
+ }
149
167
  }
150
168
  for (const delta of deltas.created) {
151
169
  const node = nodeByCommit.get(delta.ref.id);