@davidcal/frosth 1.6.1 → 1.7.1
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 +1 -1
- package/package.json +2 -1
- package/src/create_array.js +114 -0
- package/src/sigew.js +2 -0
package/README.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@davidcal/frosth",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.1",
|
|
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,114 @@
|
|
|
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 stream = {
|
|
10
|
+
subscribe: (handler) => {
|
|
11
|
+
let replay_list = Immutable.List();
|
|
12
|
+
let prev_contract = wrap(replay_list);
|
|
13
|
+
|
|
14
|
+
uly_list.forEach((value, index) => {
|
|
15
|
+
const next_list = replay_list.insert(index, value);
|
|
16
|
+
const next_contract = wrap(next_list);
|
|
17
|
+
|
|
18
|
+
handler([{ method: "insert", args: [index, value] }, next_contract, prev_contract]);
|
|
19
|
+
|
|
20
|
+
replay_list = next_list;
|
|
21
|
+
prev_contract = next_contract;
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
return producer.stream.subscribe(handler);
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const contract = {
|
|
29
|
+
stream,
|
|
30
|
+
size: () => uly_list.size,
|
|
31
|
+
get: (index) => uly_list.get(index),
|
|
32
|
+
first: () => uly_list.first(),
|
|
33
|
+
last: () => uly_list.last(),
|
|
34
|
+
to_array: () => uly_list.toArray(),
|
|
35
|
+
fresh: () => wrap(uly_list),
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const perform_elementary = (method, args, new_list) => {
|
|
39
|
+
const old_contract = wrap(uly_list);
|
|
40
|
+
uly_list = new_list;
|
|
41
|
+
const new_contract = wrap(uly_list);
|
|
42
|
+
|
|
43
|
+
console.log("performing elementgary", method, args, new_contract, old_contract);
|
|
44
|
+
|
|
45
|
+
producer.emit([{ method, args }, new_contract, old_contract]);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
contract.mutate = ({ method, args }) => {
|
|
49
|
+
switch (method) {
|
|
50
|
+
case "insert": {
|
|
51
|
+
const [index, value] = args;
|
|
52
|
+
perform_elementary("insert", [index, value], uly_list.insert(index, value));
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
case "remove": {
|
|
56
|
+
const [index] = args;
|
|
57
|
+
perform_elementary("remove", [index], uly_list.remove(index));
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
case "push": {
|
|
61
|
+
const [value] = args;
|
|
62
|
+
contract.mutate({ method: "insert", args: [uly_list.size, value] });
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
case "unshift": {
|
|
66
|
+
const [value] = args;
|
|
67
|
+
contract.mutate({ method: "insert", args: [0, value] });
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
case "pop": {
|
|
71
|
+
contract.mutate({ method: "remove", args: [uly_list.size - 1] });
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
case "shift": {
|
|
75
|
+
contract.mutate({ method: "remove", args: [0] });
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
case "set": {
|
|
79
|
+
const [index, value] = args;
|
|
80
|
+
contract.mutate({ method: "remove", args: [index] });
|
|
81
|
+
contract.mutate({ method: "insert", args: [index, value] });
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
case "update": {
|
|
85
|
+
const [index, updater] = args;
|
|
86
|
+
contract.mutate({ method: "set", args: [index, updater(uly_list.get(index))] });
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
case "clear": {
|
|
90
|
+
while (uly_list.size > 0) {
|
|
91
|
+
contract.mutate({ method: "remove", args: [uly_list.size - 1] });
|
|
92
|
+
}
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
default:
|
|
97
|
+
throw new Error(`Unknown method: ${method}`);
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
contract.insert = (index, value) => contract.mutate({ method: "insert", args: [index, value] });
|
|
102
|
+
contract.remove = (index) => contract.mutate({ method: "remove", args: [index] });
|
|
103
|
+
contract.push = (value) => contract.mutate({ method: "push", args: [value] });
|
|
104
|
+
contract.unshift = (value) => contract.mutate({ method: "unshift", args: [value] });
|
|
105
|
+
contract.pop = () => contract.mutate({ method: "pop", args: [] });
|
|
106
|
+
contract.shift = () => contract.mutate({ method: "shift", args: [] });
|
|
107
|
+
contract.set = (index, value) => contract.mutate({ method: "set", args: [index, value] });
|
|
108
|
+
contract.update = (index, updater) => contract.mutate({ method: "update", args: [index, updater] });
|
|
109
|
+
contract.clear = () => contract.mutate({ method: "clear", args: [] });
|
|
110
|
+
|
|
111
|
+
return contract;
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
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);
|