stillflow.engine 0.2.0 → 0.2.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
CHANGED
|
@@ -53,7 +53,7 @@ You can test some benchmarks on [**CodeSandBox**](https://codesandbox.io/p/sandb
|
|
|
53
53
|
| **Lazy remove every 2nd row** | 10,000 rows (60k removed) | **~242ms max** ($O(k \log n)$ scaling) |
|
|
54
54
|
|
|
55
55
|
```ts
|
|
56
|
-
import { Stillflow, State,
|
|
56
|
+
import { Stillflow, State, collection, operators, adapters } from 'stillflow.engine'
|
|
57
57
|
|
|
58
58
|
type AppState = {
|
|
59
59
|
input: string
|
|
@@ -65,7 +65,7 @@ type TodoItem = {
|
|
|
65
65
|
|
|
66
66
|
type TodoState = {
|
|
67
67
|
input: string,
|
|
68
|
-
items:
|
|
68
|
+
items: collection.Flushable<TodoItem>
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
const { jsxdom, dom } = adapters
|
|
@@ -74,11 +74,11 @@ const state = new State()
|
|
|
74
74
|
const stillflow = new Stillflow<AppState>(state)
|
|
75
75
|
const factory = stillflow.factory()
|
|
76
76
|
|
|
77
|
-
factory.add(
|
|
77
|
+
factory.add(collection.Flushable.name, () => new collection.Flushable(new collection.Fenwick(100)))
|
|
78
78
|
|
|
79
79
|
const source = {
|
|
80
80
|
input: stillflow.variable('input').backref(),
|
|
81
|
-
items: operators.is(
|
|
81
|
+
items: operators.is(collection.Flushable.name)
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
const view = stillflow.compile(source)
|
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
import { transform } from "../transformers/transform.js";
|
|
2
2
|
import { compile, markup_template } from "../compiler/compile.js";
|
|
3
3
|
import { SF_CACHE, SF_CACHE_TEXT, SF_LISTENED, SF_CONTEXT, SF_HANDLERS } from "../dom.symbols.js";
|
|
4
|
+
const ANY = new Proxy({}, {
|
|
5
|
+
get(target, name) {
|
|
6
|
+
if (name === 'toString') {
|
|
7
|
+
return () => String();
|
|
8
|
+
}
|
|
9
|
+
return ANY;
|
|
10
|
+
},
|
|
11
|
+
apply(target, thisArg, argArray) {
|
|
12
|
+
return ANY;
|
|
13
|
+
}
|
|
14
|
+
});
|
|
4
15
|
export function apply(node, delegator, pool) {
|
|
5
16
|
const instructions = compile(node);
|
|
6
17
|
const payload = (id) => `p${id}`;
|
|
@@ -65,6 +76,7 @@ export function apply(node, delegator, pool) {
|
|
|
65
76
|
const pIndex = payloads.length;
|
|
66
77
|
payloads.push({
|
|
67
78
|
node,
|
|
79
|
+
any: ANY,
|
|
68
80
|
elements: [],
|
|
69
81
|
template,
|
|
70
82
|
applier: undefined,
|
|
@@ -74,11 +86,11 @@ export function apply(node, delegator, pool) {
|
|
|
74
86
|
pool
|
|
75
87
|
});
|
|
76
88
|
code += `iter_${labels++}: {`;
|
|
89
|
+
code += `const items = ${payload(pIndex)}.select(context);`;
|
|
77
90
|
code += `if (${payload(pIndex)}.applier === undefined) {`;
|
|
78
91
|
code += `${payload(pIndex)}.applier = ${payload(pIndex)}.generator(${payload(pIndex)}.node, ${payload(pIndex)}.delegator, ${payload(pIndex)}.pool);`;
|
|
79
|
-
code += `${payload(pIndex)}.applier(${payload(pIndex)}.template);`;
|
|
92
|
+
code += `${payload(pIndex)}.applier(${payload(pIndex)}.template, ${payload(pIndex)}.any);`;
|
|
80
93
|
code += '}';
|
|
81
|
-
code += `const items = ${payload(pIndex)}.select(context);`;
|
|
82
94
|
code += `const target = root.${SF_CACHE}[${index}];`;
|
|
83
95
|
code += `const { replaces, clears, addes, swaps, removes, updates } = items.flush();`;
|
|
84
96
|
code += `if (replaces) {`;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Stillflow, State, collection, operators, adapters } from '../index.js';
|
|
2
|
+
const { jsxdom, dom } = adapters;
|
|
3
|
+
const state = new State();
|
|
4
|
+
const stillflow = new Stillflow(state);
|
|
5
|
+
const factory = stillflow.factory();
|
|
6
|
+
factory.add(collection.Flushable.name, () => new collection.Flushable(new collection.Fenwick(100)));
|
|
7
|
+
const source = {
|
|
8
|
+
input: stillflow.variable('input').backref(),
|
|
9
|
+
items: operators.is(collection.Flushable.name)
|
|
10
|
+
};
|
|
11
|
+
const view = stillflow.compile(source);
|
|
12
|
+
const instance = stillflow.instantiate(view, factory);
|
|
13
|
+
function change(event) {
|
|
14
|
+
instance.input = event.target.value;
|
|
15
|
+
stillflow.commit();
|
|
16
|
+
}
|
|
17
|
+
function add() {
|
|
18
|
+
instance.items.add({ label: instance.input });
|
|
19
|
+
instance.input = String();
|
|
20
|
+
stillflow.commit();
|
|
21
|
+
}
|
|
22
|
+
function TodoItem() {
|
|
23
|
+
return (adapters.jsx(jsxdom.div, null, (context) => context.label));
|
|
24
|
+
}
|
|
25
|
+
function App() {
|
|
26
|
+
return (adapters.jsx(jsxdom.div, null,
|
|
27
|
+
adapters.jsx(jsxdom.input, { "sf:value": (context) => context.input, "on:change": change }),
|
|
28
|
+
adapters.jsx(jsxdom.button, { "on:click": add }, "Add"),
|
|
29
|
+
adapters.jsx(jsxdom.div, { "sf:for": (context) => context.items, "sf:each": () => adapters.jsx(TodoItem, null) })));
|
|
30
|
+
}
|
|
31
|
+
const { element: app, update } = dom.$(adapters.jsx(App, null));
|
|
32
|
+
stillflow.on(() => update(instance));
|
|
33
|
+
instance.input = String();
|
|
34
|
+
stillflow.commit();
|
|
35
|
+
document.body.appendChild(app);
|