@davidcal/frosth 1.6.1 → 1.7.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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Frosth - Yet another UI framework
2
2
 
3
- **Latest version**: v1.6.1
3
+ **Latest version**: v1.7.0
4
4
 
5
5
  ## Motivation
6
6
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@davidcal/frosth",
3
- "version": "1.6.1",
3
+ "version": "1.7.0",
4
4
  "description": "Async-first CRUD-last UI framework that treats encapsulation as a solved problem.",
5
5
  "type": "module",
6
6
  "main": "./src/sigew.js",
@@ -25,6 +25,7 @@
25
25
  "url": "https://github.com/davidcallanan/frosth"
26
26
  },
27
27
  "dependencies": {
28
+ "immutable": "^5.1.10",
28
29
  "unsuspended-promise": "^1.0.1"
29
30
  }
30
31
  }
@@ -0,0 +1,95 @@
1
+ import * as Immutable from "immutable";
2
+ import { create_producer } from "./create_producer.js";
3
+
4
+ const wrap = (initial_uly_list) => {
5
+ let uly_list = initial_uly_list;
6
+
7
+ const producer = create_producer();
8
+
9
+ const contract = {
10
+ stream: producer.stream,
11
+ size: () => uly_list.size,
12
+ get: (index) => uly_list.get(index),
13
+ first: () => uly_list.first(),
14
+ last: () => uly_list.last(),
15
+ to_array: () => uly_list.toArray(),
16
+ fresh: () => wrap(uly_list),
17
+ };
18
+
19
+ const perform_elementary = (method, args, new_list) => {
20
+ const old_contract = wrap(uly_list);
21
+ uly_list = new_list;
22
+ const new_contract = wrap(uly_list);
23
+
24
+ console.log("performing elementgary", method, args, new_contract, old_contract);
25
+
26
+ producer.emit([{ method, args }, new_contract, old_contract]);
27
+ };
28
+
29
+ contract.mutate = ({ method, args }) => {
30
+ switch (method) {
31
+ case "insert": {
32
+ const [index, value] = args;
33
+ perform_elementary("insert", [index, value], uly_list.insert(index, value));
34
+ return;
35
+ }
36
+ case "remove": {
37
+ const [index] = args;
38
+ perform_elementary("remove", [index], uly_list.remove(index));
39
+ return;
40
+ }
41
+ case "push": {
42
+ const [value] = args;
43
+ contract.mutate({ method: "insert", args: [uly_list.size, value] });
44
+ return;
45
+ }
46
+ case "unshift": {
47
+ const [value] = args;
48
+ contract.mutate({ method: "insert", args: [0, value] });
49
+ return;
50
+ }
51
+ case "pop": {
52
+ contract.mutate({ method: "remove", args: [uly_list.size - 1] });
53
+ return;
54
+ }
55
+ case "shift": {
56
+ contract.mutate({ method: "remove", args: [0] });
57
+ return;
58
+ }
59
+ case "set": {
60
+ const [index, value] = args;
61
+ contract.mutate({ method: "remove", args: [index] });
62
+ contract.mutate({ method: "insert", args: [index, value] });
63
+ return;
64
+ }
65
+ case "update": {
66
+ const [index, updater] = args;
67
+ contract.mutate({ method: "set", args: [index, updater(uly_list.get(index))] });
68
+ return;
69
+ }
70
+ case "clear": {
71
+ while (uly_list.size > 0) {
72
+ contract.mutate({ method: "remove", args: [uly_list.size - 1] });
73
+ }
74
+ return;
75
+ }
76
+
77
+ default:
78
+ throw new Error(`Unknown method: ${method}`);
79
+ }
80
+ };
81
+
82
+ contract.insert = (index, value) => contract.mutate({ method: "insert", args: [index, value] });
83
+ contract.remove = (index) => contract.mutate({ method: "remove", args: [index] });
84
+ contract.push = (value) => contract.mutate({ method: "push", args: [value] });
85
+ contract.unshift = (value) => contract.mutate({ method: "unshift", args: [value] });
86
+ contract.pop = () => contract.mutate({ method: "pop", args: [] });
87
+ contract.shift = () => contract.mutate({ method: "shift", args: [] });
88
+ contract.set = (index, value) => contract.mutate({ method: "set", args: [index, value] });
89
+ contract.update = (index, updater) => contract.mutate({ method: "update", args: [index, updater] });
90
+ contract.clear = () => contract.mutate({ method: "clear", args: [] });
91
+
92
+ return contract;
93
+ };
94
+
95
+ export const create_array = (initial) => wrap(Immutable.List(initial ?? []));
package/src/sigew.js CHANGED
@@ -13,6 +13,7 @@ import { stream_filter } from "./stream_filter.js";
13
13
  import { stream_map } from "./stream_map.js";
14
14
  import { stream_reduce } from "./stream_reduce.js";
15
15
  import { stream_latest } from "./stream_latest.js";
16
+ import { create_array } from "./create_array.js";
16
17
 
17
18
  export { create_self };
18
19
  export { create_signal };
@@ -25,6 +26,7 @@ export { stream_filter };
25
26
  export { stream_map };
26
27
  export { stream_reduce };
27
28
  export { stream_latest };
29
+ export { create_array };
28
30
 
29
31
  export const installarea = (s) => {
30
32
  const storage = s.create_housed_signal(() => undefined);