stillflow.engine 0.4.5 → 0.4.7
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 +2 -2
- package/dist/jsx-runtime.d.ts +1 -0
- package/dist/jsx-runtime.js +3 -0
- package/dist/stillflow-adapters/dom/base.dom.d.ts +1 -0
- package/dist/stillflow-adapters/dom/base.dom.js +11 -1
- package/dist/stillflow-adapters/dom/jsx.dom.js +3 -0
- package/dist/stillflow-adapters/dom/vm/compile/dom.apply.js +0 -1
- package/dist/stillflow-adapters/dom/vm/compile/dom.apply.keyed.d.ts +3 -0
- package/dist/stillflow-adapters/dom/vm/compile/dom.apply.keyed.js +10 -0
- package/dist/stillflow-adapters/dom/vm/compile/dom.compile-vm.keyed.d.ts +2 -0
- package/dist/stillflow-adapters/dom/vm/compile/dom.compile-vm.keyed.js +170 -0
- package/dist/stillflow-examples/app.js +4 -9
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -30,11 +30,11 @@ Also I think that **explicit reactivity is better than implicit reactivity**. So
|
|
|
30
30
|
|
|
31
31
|
*Note 2*: The results of jsx version of **Stillflow** is done without micro- or macro- tasks.
|
|
32
32
|
|
|
33
|
-

|
|
34
34
|
|
|
35
35
|
**Stillflow** memory usage score is below
|
|
36
36
|
|
|
37
|
-

|
|
38
38
|
|
|
39
39
|
## Quick Start
|
|
40
40
|
|
package/dist/jsx-runtime.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import { Binding } from "./stillflow-vm/binding.js";
|
|
2
2
|
export declare function jsx<T>(type: (properties: Record<string, any>, children: Binding<any>[]) => Binding<T>, properties: Record<string, any>): Binding<T>;
|
|
3
|
+
export declare function jsxs<T>(type: (properties: Record<string, any>, children: Binding<any>[]) => Binding<T>, properties: Record<string, any>): Binding<T>;
|
package/dist/jsx-runtime.js
CHANGED
|
@@ -4,6 +4,7 @@ import { Properties } from "./properties/properties.js";
|
|
|
4
4
|
import { Binding } from "../../stillflow-vm/binding.js";
|
|
5
5
|
type PropertiesWithoutServices<V, K extends keyof HTMLElementTagNameMap> = Omit<Properties<V, K>, 'name'>;
|
|
6
6
|
type Options = {
|
|
7
|
+
mode?: 'keyed' | 'non-keyed';
|
|
7
8
|
container: HTMLElement;
|
|
8
9
|
};
|
|
9
10
|
export type DOMRegistry = {
|
|
@@ -1,12 +1,22 @@
|
|
|
1
1
|
import { HTML_TAGS } from "./tags.js";
|
|
2
2
|
import { describe } from "./description/describe.js";
|
|
3
3
|
import { apply } from "./vm/compile/dom.apply.js";
|
|
4
|
+
import { apply_keyed } from './vm/compile/dom.apply.keyed.js';
|
|
4
5
|
const DEFAULT_OPTIONS = {
|
|
6
|
+
mode: undefined,
|
|
5
7
|
container: document.body
|
|
6
8
|
};
|
|
7
9
|
export const DOM_REGISTRY = Object.create(null);
|
|
8
10
|
DOM_REGISTRY.$ = function $(root, options = DEFAULT_OPTIONS) {
|
|
9
|
-
|
|
11
|
+
let runner;
|
|
12
|
+
switch (options.mode) {
|
|
13
|
+
case 'keyed':
|
|
14
|
+
runner = apply_keyed(root);
|
|
15
|
+
break;
|
|
16
|
+
case 'non-keyed':
|
|
17
|
+
default:
|
|
18
|
+
runner = apply(root);
|
|
19
|
+
}
|
|
10
20
|
const update = (context) => runner.applier(runner.root, context);
|
|
11
21
|
options.container.appendChild(runner.root);
|
|
12
22
|
return update;
|
|
@@ -16,6 +16,9 @@ class JSXDOMUtilities {
|
|
|
16
16
|
const dynamic_content = new Array();
|
|
17
17
|
const static_content = new Array();
|
|
18
18
|
const children = new Array();
|
|
19
|
+
if (Array.isArray(all) == false) {
|
|
20
|
+
all = [all];
|
|
21
|
+
}
|
|
19
22
|
for (const child of all) {
|
|
20
23
|
if (typeof child === 'string' || typeof child === 'number') {
|
|
21
24
|
static_content.push(child.toString());
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { run_dom_vm_keyed } from "./dom.compile-vm.keyed.js";
|
|
2
|
+
import { compile } from "./dom.compile.js";
|
|
3
|
+
export const apply_keyed = (node) => {
|
|
4
|
+
const compilation = compile(node);
|
|
5
|
+
const applier = run_dom_vm_keyed(compilation);
|
|
6
|
+
return {
|
|
7
|
+
root: compilation.root,
|
|
8
|
+
applier: (root, context) => applier(root, context),
|
|
9
|
+
};
|
|
10
|
+
};
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import * as vm from "../../../../stillflow-vm/index.js";
|
|
2
|
+
import { EventDelegator } from "../utilities/dom.delegator.js";
|
|
3
|
+
import { SF_ANY, SF_CACHE, SF_CACHE_TEXT, SF_CONTEXT, SF_HANDLERS, SF_LISTENED } from "../dom.symbols.js";
|
|
4
|
+
import { markup_template } from "./dom.markup.js";
|
|
5
|
+
const generators = {
|
|
6
|
+
[6 /* Codes.VM */](bytecode, offset, context) {
|
|
7
|
+
const anchor = bytecode[offset + 2];
|
|
8
|
+
const select = context.functions[bytecode[offset + 2]];
|
|
9
|
+
const node = context.nodes[bytecode[offset + 3]];
|
|
10
|
+
const selectIndex = context.payload.add_payload(select);
|
|
11
|
+
const nodeIndex = context.payload.add_payload(node);
|
|
12
|
+
const slotIndex = context.payload.add_payload({
|
|
13
|
+
active: undefined,
|
|
14
|
+
cache: new Map()
|
|
15
|
+
});
|
|
16
|
+
let code = String();
|
|
17
|
+
code += `{`;
|
|
18
|
+
code += `const compile = ${selectIndex}(context);`;
|
|
19
|
+
code += `if (${slotIndex}.active !== undefined) {`;
|
|
20
|
+
code += `${slotIndex}.active.root.remove();`;
|
|
21
|
+
code += `}`;
|
|
22
|
+
code += `let next = ${slotIndex}.cache.get(compile);`;
|
|
23
|
+
code += `if (next === undefined) {`;
|
|
24
|
+
code += `next = compile(${nodeIndex});`;
|
|
25
|
+
code += `${slotIndex}.cache.set(compile, next);`;
|
|
26
|
+
code += `}`;
|
|
27
|
+
code += `${slotIndex}.active = next;`;
|
|
28
|
+
code += `if (next !== undefined) {`;
|
|
29
|
+
code += `const anchor = sf_node_cache[${anchor}];`;
|
|
30
|
+
code += `anchor.parentNode.insertBefore(next.root, anchor);`;
|
|
31
|
+
code += `}`;
|
|
32
|
+
code += `if (${slotIndex}.active !== undefined) {`;
|
|
33
|
+
code += `${slotIndex}.active.applier(${slotIndex}.active.root, context);`;
|
|
34
|
+
code += `}`;
|
|
35
|
+
code += `}`;
|
|
36
|
+
return code;
|
|
37
|
+
},
|
|
38
|
+
[5 /* Codes.PROPERTY */](bytecode, offset, context) {
|
|
39
|
+
const container = bytecode[offset + 2];
|
|
40
|
+
const property = context.strings[bytecode[offset + 3]];
|
|
41
|
+
const handler = context.functions[bytecode[offset + 4]];
|
|
42
|
+
const propertyIndex = context.payload.add(property);
|
|
43
|
+
const handlerIndex = context.payload.add(handler);
|
|
44
|
+
const payload = context.payload.payload;
|
|
45
|
+
return `sf_node_cache[${container}][${payload(propertyIndex)}] = ${payload(handlerIndex)}(context);`;
|
|
46
|
+
},
|
|
47
|
+
[3 /* Codes.TEXT */](bytecode, offset, context) {
|
|
48
|
+
const container = bytecode[offset + 2];
|
|
49
|
+
const handler = context.functions[bytecode[offset + 3]];
|
|
50
|
+
const handlerIndex = context.payload.add(handler);
|
|
51
|
+
return `sf_text_cache[${container}].data = ${context.payload.payload(handlerIndex)}(context);`;
|
|
52
|
+
},
|
|
53
|
+
[4 /* Codes.EVENT */](bytecode, offset, context) {
|
|
54
|
+
const container = bytecode[offset + 2];
|
|
55
|
+
const event = context.strings[bytecode[offset + 3]];
|
|
56
|
+
const handler = context.functions[bytecode[offset + 4]];
|
|
57
|
+
const eventIndex = context.payload.add(event);
|
|
58
|
+
const handlerIndex = context.payload.add(handler);
|
|
59
|
+
const delegatorIndex = context.payload.add(context.delegator);
|
|
60
|
+
const payload = context.payload.payload;
|
|
61
|
+
let code = String();
|
|
62
|
+
code += `{`;
|
|
63
|
+
code += `const element = sf_node_cache[${container}];`;
|
|
64
|
+
code += `element.${SF_CONTEXT} = context;`;
|
|
65
|
+
code += `if (!element.${SF_LISTENED}) {`;
|
|
66
|
+
code += `element.${SF_LISTENED} = true;`;
|
|
67
|
+
code += `${payload(delegatorIndex)}.add(element, ${payload(eventIndex)}, ${payload(handlerIndex)});`;
|
|
68
|
+
code += `}`;
|
|
69
|
+
code += `}`;
|
|
70
|
+
return code;
|
|
71
|
+
},
|
|
72
|
+
[0 /* Codes.IF */](bytecode, offset, context) {
|
|
73
|
+
const container = bytecode[offset + 2];
|
|
74
|
+
const handler = context.functions[bytecode[offset + 3]];
|
|
75
|
+
const payload = context.payload.payload;
|
|
76
|
+
let code = String();
|
|
77
|
+
const handlerIndex = context.payload.add(handler);
|
|
78
|
+
code += `{`;
|
|
79
|
+
code += `const element = sf_node_cache[${container}];`;
|
|
80
|
+
code += `const condition = ${payload(handlerIndex)}(context);`;
|
|
81
|
+
code += `element.style.display = condition ? String() : 'none';`;
|
|
82
|
+
code += `}`;
|
|
83
|
+
return code;
|
|
84
|
+
},
|
|
85
|
+
[2 /* Codes.FOR */](bytecode, offset, context) {
|
|
86
|
+
const container = bytecode[offset + 2];
|
|
87
|
+
const select = context.functions[bytecode[offset + 3]];
|
|
88
|
+
const template = context.templates[bytecode[offset + 4]];
|
|
89
|
+
const item_applier = run_dom_vm_keyed(template);
|
|
90
|
+
item_applier(template.root, SF_ANY);
|
|
91
|
+
const selectIndex = context.payload.add_payload(select);
|
|
92
|
+
const applierIndex = context.payload.add_payload(item_applier);
|
|
93
|
+
const templateIndex = context.payload.add_payload(template.root);
|
|
94
|
+
const elementsIndex = context.payload.add_payload([]);
|
|
95
|
+
let code = String();
|
|
96
|
+
code += `{`;
|
|
97
|
+
code += `const items = ${selectIndex}(context);`;
|
|
98
|
+
code += `const target = sf_node_cache[${container}];`;
|
|
99
|
+
code += `const { clears, addes, swaps, removes, updates } = items.flush();`;
|
|
100
|
+
code += `}`;
|
|
101
|
+
code += `else {`;
|
|
102
|
+
code += `if (clears) {`;
|
|
103
|
+
code += `const freelist = ${elementsIndex}.splice(0);`;
|
|
104
|
+
code += `for (const element of freelist) {`;
|
|
105
|
+
code += `element.${SF_HANDLERS} = undefined;`;
|
|
106
|
+
code += `}`;
|
|
107
|
+
code += `target.textContent = String();`;
|
|
108
|
+
code += `}`;
|
|
109
|
+
code += `if (addes > 0) {`;
|
|
110
|
+
code += `const fragment = document.createDocumentFragment();`;
|
|
111
|
+
code += `const elements = new Array(addes);`;
|
|
112
|
+
code += `const old_size = ${elementsIndex}.length;`;
|
|
113
|
+
code += `for (let i = 0; i < addes; i++) {`;
|
|
114
|
+
code += `const element = ${templateIndex}.cloneNode(true);`;
|
|
115
|
+
code += `element.${SF_HANDLERS} = ${templateIndex}.${SF_HANDLERS};`;
|
|
116
|
+
code += `element.${SF_CONTEXT} = items.at(i + old_size);`;
|
|
117
|
+
code += `${applierIndex}(element, items.at(i + old_size));`;
|
|
118
|
+
code += `elements[i] = element;`;
|
|
119
|
+
code += `fragment.appendChild(element);`;
|
|
120
|
+
code += `}`;
|
|
121
|
+
code += `${elementsIndex}.push(...elements);`;
|
|
122
|
+
code += `target.appendChild(fragment);`;
|
|
123
|
+
code += `}`;
|
|
124
|
+
code += `for (const [i, j] of swaps.entries()) {`;
|
|
125
|
+
code += `const x = ${elementsIndex}[i];`;
|
|
126
|
+
code += `const y = ${elementsIndex}[j];`;
|
|
127
|
+
code += `target.insertBefore(x, ${elementsIndex}[j + 1]);`;
|
|
128
|
+
code += `target.insertBefore(y, ${elementsIndex}[i + 1]);`;
|
|
129
|
+
code += `}`;
|
|
130
|
+
code += `for (const id of removes) {`;
|
|
131
|
+
code += `const element = ${elementsIndex}[id];`;
|
|
132
|
+
code += `element.${SF_HANDLERS} = undefined;`;
|
|
133
|
+
code += `element.remove();`;
|
|
134
|
+
code += `}`;
|
|
135
|
+
code += `for (const id of updates) {`;
|
|
136
|
+
code += `${applierIndex}(${elementsIndex}[id], items.at(id));`;
|
|
137
|
+
code += `}`;
|
|
138
|
+
code += `}`;
|
|
139
|
+
code += `}`;
|
|
140
|
+
return code;
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
const DELEGATOR = new EventDelegator();
|
|
144
|
+
const create_context = (payload, input) => {
|
|
145
|
+
return {
|
|
146
|
+
node: input.node,
|
|
147
|
+
nodes: input.nodes,
|
|
148
|
+
payload,
|
|
149
|
+
strings: input.strings,
|
|
150
|
+
functions: input.functions,
|
|
151
|
+
templates: input.templates,
|
|
152
|
+
delegator: DELEGATOR
|
|
153
|
+
};
|
|
154
|
+
};
|
|
155
|
+
const dom_vm = vm.create({
|
|
156
|
+
generators,
|
|
157
|
+
preamble(context) {
|
|
158
|
+
let code = String();
|
|
159
|
+
const markupIndex = context.payload.add_payload(markup_template(context.node));
|
|
160
|
+
code += `return function(root, context) {`;
|
|
161
|
+
code += `${markupIndex}(root);`;
|
|
162
|
+
code += `const sf_node_cache = root.${SF_CACHE};`;
|
|
163
|
+
code += `const sf_text_cache = root.${SF_CACHE_TEXT};`;
|
|
164
|
+
return code;
|
|
165
|
+
},
|
|
166
|
+
epilogue() {
|
|
167
|
+
return `}`;
|
|
168
|
+
},
|
|
169
|
+
});
|
|
170
|
+
export const run_dom_vm_keyed = (template) => dom_vm(template.bytecode, template, create_context);
|
|
@@ -114,15 +114,10 @@ function BenchmarkApplicationView(context) {
|
|
|
114
114
|
const { controller } = context;
|
|
115
115
|
return (_jsxs(jsxdom.div, { id: "app", className: "container", children: [_jsx(jsxdom.div, { className: "jumbotron", children: _jsxs(jsxdom.div, { className: "row", children: [_jsx(BenchmarkApplicationHeader, {}), _jsx(jsxdom.div, { className: "row", children: _jsxs(jsxdom.div, { className: "col-md-6", children: [_jsx(BenchmarkApplicationButton, { text: "Create 1,000 rows", id: "run", handle: () => controller.run() }), _jsx(BenchmarkApplicationButton, { text: "Create 10,000 rows", id: "runlots", handle: () => controller.run_lots() }), _jsx(BenchmarkApplicationButton, { text: "Append 1,000 rows", id: "add", handle: () => controller.add() }), _jsx(BenchmarkApplicationButton, { text: "Update every 10th row", id: "update", handle: () => controller.update() }), _jsx(BenchmarkApplicationButton, { text: "Clear", id: "clear", handle: () => controller.clear() }), _jsx(BenchmarkApplicationButton, { text: "Swap rows", id: "swaprows", handle: () => controller.swap() })] }) })] }) }), _jsx(BenchmarkApplicationTable, { controller: controller }), _jsx(jsxdom.span, { ariaHidden: "true", className: "preloadicon glyphicon glyphicon-remove" })] }));
|
|
116
116
|
}
|
|
117
|
-
function custom_compiler(node) {
|
|
118
|
-
return {
|
|
119
|
-
root: document.createElement('canvas'),
|
|
120
|
-
applier(root, context) {
|
|
121
|
-
root.getContext('2d').fillRect(0, 0, 100, 100);
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
117
|
const controller = new BenchmarkApplicationController();
|
|
126
|
-
const update = dom.$(_jsx(
|
|
118
|
+
const update = dom.$(_jsx(BenchmarkApplicationView, { controller: controller }), {
|
|
119
|
+
mode: 'keyed',
|
|
120
|
+
container: document.body
|
|
121
|
+
});
|
|
127
122
|
controller.core.on(() => update({}));
|
|
128
123
|
update({});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "stillflow.engine",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.7",
|
|
4
4
|
"description": "A headless, transaction-based UI engine with AOT compilation.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"homepage": "https://github.com/SampleUserD/Stillflow.Engine#readme",
|
|
63
63
|
"scripts": {
|
|
64
64
|
"build": "tsc --build && tsc-alias && tsc-esm-fix",
|
|
65
|
-
"watch": "concurrently \"tsc -w\" \"tsc-alias -w\"",
|
|
65
|
+
"watch": "npx concurrently \"tsc -w\" \"tsc-alias -w\"",
|
|
66
66
|
"prepublishOnly": "npm run build"
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|