stillflow.engine 0.1.8 → 0.2.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 +10 -0
- package/dist/index.d.ts +2 -4
- package/dist/index.js +2 -3
- package/dist/stillflow/kernel/buffer.d.ts +1 -0
- package/dist/stillflow/kernel/buffer.js +3 -0
- package/dist/stillflow/tools/batcher.d.ts +1 -0
- package/dist/stillflow/tools/batcher.js +5 -1
- package/dist/stillflow-adapters/dom/aot/appliers/apply.d.ts +6 -0
- package/dist/stillflow-adapters/dom/aot/appliers/apply.js +155 -0
- package/dist/stillflow-adapters/dom/aot/compiler/compile.d.ts +11 -0
- package/dist/stillflow-adapters/dom/aot/compiler/compile.js +71 -0
- package/dist/stillflow-adapters/dom/aot/dom.delegator.d.ts +6 -0
- package/dist/stillflow-adapters/dom/aot/dom.delegator.js +39 -0
- package/dist/stillflow-adapters/dom/aot/dom.directives.d.ts +16 -0
- package/dist/stillflow-adapters/dom/aot/dom.operations.d.ts +3 -0
- package/dist/stillflow-adapters/dom/aot/dom.operations.js +1 -0
- package/dist/stillflow-adapters/dom/aot/dom.pool.d.ts +11 -0
- package/dist/stillflow-adapters/dom/aot/dom.pool.js +47 -0
- package/dist/stillflow-adapters/dom/aot/dom.resources.d.ts +3 -0
- package/dist/stillflow-adapters/dom/aot/dom.resources.js +3 -0
- package/dist/stillflow-adapters/dom/aot/dom.symbols.d.ts +5 -0
- package/dist/stillflow-adapters/dom/aot/dom.symbols.js +5 -0
- package/dist/stillflow-adapters/dom/{dom.d.ts → aot/dom.types.d.ts} +2 -2
- package/dist/stillflow-adapters/dom/aot/transformers/transform.d.ts +3 -0
- package/dist/stillflow-adapters/dom/aot/transformers/transform.js +42 -0
- package/dist/stillflow-adapters/dom/base.dom.d.ts +5 -3
- package/dist/stillflow-adapters/dom/base.dom.js +20 -12
- package/dist/stillflow-adapters/dom/description/describe.d.ts +1 -1
- package/dist/stillflow-adapters/dom/jsx.dom.d.ts +3 -3
- package/dist/stillflow-adapters/dom/properties/modifiers.d.ts +3 -4
- package/dist/stillflow-collection/index.d.ts +3 -0
- package/dist/stillflow-collection/index.js +2 -0
- package/dist/stillflow-examples/app.js +7 -5
- package/package.json +1 -1
- package/dist/stillflow-adapters/dom/compiler/apply.d.ts +0 -37
- package/dist/stillflow-adapters/dom/compiler/apply.js +0 -289
- package/dist/stillflow-adapters/dom/compiler/compile.d.ts +0 -18
- package/dist/stillflow-adapters/dom/compiler/compile.js +0 -47
- package/dist/stillflow-adapters/dom/compiler/transform.d.ts +0 -2
- package/dist/stillflow-adapters/dom/compiler/transform.js +0 -41
- package/dist/stillflow-adapters/dom/index.d.ts +0 -15
- package/dist/stillflow-adapters/dom/index.js +0 -22
- package/dist/stillflow-adapters/dom/types.d.ts +0 -4
- package/dist/stillflow-examples/files.d.ts +0 -1
- package/dist/stillflow-examples/files.js +0 -29
- package/dist/stillflow-examples/test.d.ts +0 -1
- package/dist/stillflow-examples/test.js +0 -35
- package/dist/stillflow-vm/analyze.d.ts +0 -7
- package/dist/stillflow-vm/analyze.js +0 -22
- package/dist/stillflow-vm/buffer.d.ts +0 -1
- package/dist/stillflow-vm/buffer.js +0 -1
- package/dist/stillflow-vm/instruction.d.ts +0 -1
- package/dist/stillflow-vm/instruction.js +0 -1
- package/dist/stillflow-vm/pool.d.ts +0 -1
- package/dist/stillflow-vm/pool.js +0 -1
- package/dist/stillflow-vm/resources.d.ts +0 -14
- package/dist/stillflow-vm/resources.js +0 -16
- /package/dist/stillflow-adapters/dom/{dom.js → aot/dom.directives.js} +0 -0
- /package/dist/stillflow-adapters/dom/{types.js → aot/dom.types.js} +0 -0
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { AnyDOM } from "../types.js";
|
|
1
|
+
import { collection } from "../../../index.js";
|
|
2
|
+
import { AnyDOM } from "../aot/dom.types.js";
|
|
3
3
|
export type Modifiers<Context, K extends keyof HTMLElementTagNameMap = any> = Partial<{
|
|
4
4
|
text: (context: Context) => string;
|
|
5
|
-
lens: <Another>(context: Context) => Another;
|
|
6
5
|
conditional: (context: Context) => boolean;
|
|
7
6
|
events: Partial<{
|
|
8
7
|
[L in keyof HTMLElementEventMap]: (event: HTMLElementEventMap[L], context: Context) => void;
|
|
@@ -11,7 +10,7 @@ export type Modifiers<Context, K extends keyof HTMLElementTagNameMap = any> = Pa
|
|
|
11
10
|
[L in keyof HTMLElementTagNameMap[K]]: (context: Context) => string;
|
|
12
11
|
}>;
|
|
13
12
|
iterate: {
|
|
14
|
-
select: <V>(context: Context) =>
|
|
13
|
+
select: <V>(context: Context) => collection.Flushable<V>;
|
|
15
14
|
each: () => AnyDOM<any>;
|
|
16
15
|
};
|
|
17
16
|
}>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Stillflow, State, Batcher, operators, adapters,
|
|
1
|
+
import { Stillflow, State, Batcher, operators, adapters, collection } from "../index.js";
|
|
2
2
|
import { buildData } from "./data.js";
|
|
3
3
|
const { jsxdom, dom } = adapters;
|
|
4
4
|
class BenchmarkApplicationController {
|
|
@@ -29,13 +29,13 @@ class BenchmarkApplicationController {
|
|
|
29
29
|
current_id: current_id.backref()
|
|
30
30
|
}),
|
|
31
31
|
data: data.backref(),
|
|
32
|
-
items: operators.is(
|
|
32
|
+
items: operators.is(collection.Flushable.name)
|
|
33
33
|
};
|
|
34
34
|
}
|
|
35
35
|
constructor() {
|
|
36
|
-
const
|
|
36
|
+
const col = new collection.Flushable(new collection.Fenwick(10000));
|
|
37
37
|
const view = this._stillflow.compile(this.source);
|
|
38
|
-
this._factory.add(
|
|
38
|
+
this._factory.add(collection.Flushable.name, view => col);
|
|
39
39
|
this._view = this._stillflow.instantiate(view, this._factory);
|
|
40
40
|
}
|
|
41
41
|
is_selected(id) {
|
|
@@ -52,7 +52,9 @@ class BenchmarkApplicationController {
|
|
|
52
52
|
this.create(10000);
|
|
53
53
|
}
|
|
54
54
|
remove(id) {
|
|
55
|
-
this._view.items.
|
|
55
|
+
for (let index = 0, size = this._view.items.size; index < size; index += 2) {
|
|
56
|
+
this._view.items.mark_removed(index);
|
|
57
|
+
}
|
|
56
58
|
this._stillflow.commit();
|
|
57
59
|
}
|
|
58
60
|
select(id) {
|
package/package.json
CHANGED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { Template } from "./compile.js";
|
|
2
|
-
export declare class Listeners {
|
|
3
|
-
private _listeners;
|
|
4
|
-
private _actives;
|
|
5
|
-
private ensure;
|
|
6
|
-
remove(root: HTMLElement): void;
|
|
7
|
-
add(root: HTMLElement, type: string, listener: (event: Event, context: any) => void): void;
|
|
8
|
-
}
|
|
9
|
-
export declare class Pool {
|
|
10
|
-
private _listeners;
|
|
11
|
-
private static TIME_TO_EVICT;
|
|
12
|
-
private _hots;
|
|
13
|
-
private _colds;
|
|
14
|
-
private _frame;
|
|
15
|
-
constructor(_listeners: Listeners);
|
|
16
|
-
private evict;
|
|
17
|
-
private retrieve;
|
|
18
|
-
get(): HTMLElement | undefined;
|
|
19
|
-
add(root: HTMLElement): void;
|
|
20
|
-
tick(): void;
|
|
21
|
-
get listeners(): Listeners;
|
|
22
|
-
}
|
|
23
|
-
type Applier<V> = (root: HTMLElement, context: V) => void;
|
|
24
|
-
export declare class Appliers<V> {
|
|
25
|
-
private _pool;
|
|
26
|
-
private _listeners;
|
|
27
|
-
constructor(_pool: Pool);
|
|
28
|
-
private find_element_by;
|
|
29
|
-
private apply_conditional;
|
|
30
|
-
private apply_text;
|
|
31
|
-
private apply_properties;
|
|
32
|
-
private apply_events;
|
|
33
|
-
private apply_iterate;
|
|
34
|
-
private markup;
|
|
35
|
-
apply(template: Template<V>): Applier<V>;
|
|
36
|
-
}
|
|
37
|
-
export {};
|
|
@@ -1,289 +0,0 @@
|
|
|
1
|
-
import { Compiler } from "./compile.js";
|
|
2
|
-
import { transform } from "./transform.js";
|
|
3
|
-
const SF_LISTENED = '__stillflow_listened__';
|
|
4
|
-
const SF_CONTEXT = '__stillflow_context__';
|
|
5
|
-
const SF_CACHE_TEXT = '__stillflow_cache_text__';
|
|
6
|
-
const SF_CACHE = '__stillflow_cache__';
|
|
7
|
-
export class Listeners {
|
|
8
|
-
_listeners = new WeakMap();
|
|
9
|
-
_actives = new Set();
|
|
10
|
-
ensure(type) {
|
|
11
|
-
if (this._actives.has(type)) {
|
|
12
|
-
return;
|
|
13
|
-
}
|
|
14
|
-
this._actives.add(type);
|
|
15
|
-
document.body.addEventListener(type, event => {
|
|
16
|
-
let target = event.target;
|
|
17
|
-
while (target && target !== document.body) {
|
|
18
|
-
const listeners = this._listeners.get(target);
|
|
19
|
-
if (listeners !== undefined) {
|
|
20
|
-
const callback = listeners.get(type);
|
|
21
|
-
callback?.(event, target[SF_CONTEXT]);
|
|
22
|
-
if (event.cancelBubble) {
|
|
23
|
-
break;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
target = target.parentElement;
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
remove(root) {
|
|
31
|
-
this._listeners.delete(root);
|
|
32
|
-
}
|
|
33
|
-
add(root, type, listener) {
|
|
34
|
-
const listeners = this._listeners.get(root) || new Map();
|
|
35
|
-
listeners.set(type, listener);
|
|
36
|
-
this._listeners.set(root, listeners);
|
|
37
|
-
this.ensure(type);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
export class Pool {
|
|
41
|
-
_listeners;
|
|
42
|
-
static TIME_TO_EVICT = 2;
|
|
43
|
-
_hots = [];
|
|
44
|
-
_colds = [];
|
|
45
|
-
_frame = 0;
|
|
46
|
-
constructor(_listeners) {
|
|
47
|
-
this._listeners = _listeners;
|
|
48
|
-
}
|
|
49
|
-
evict() {
|
|
50
|
-
for (let id = this._hots.length - 1; id >= 0; id--) {
|
|
51
|
-
const hot = this._hots[id];
|
|
52
|
-
if (this._frame - hot.frame >= Pool.TIME_TO_EVICT) {
|
|
53
|
-
this._listeners.remove(hot.root);
|
|
54
|
-
const element = hot.root;
|
|
55
|
-
element[SF_CONTEXT] = null;
|
|
56
|
-
element[SF_LISTENED] = false;
|
|
57
|
-
this._colds.push(new WeakRef(hot.root));
|
|
58
|
-
this._hots.splice(id, 1);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
retrieve() {
|
|
63
|
-
if (this._hots.length <= 0) {
|
|
64
|
-
while (this._colds.length > 0) {
|
|
65
|
-
const cold = this._colds.pop();
|
|
66
|
-
const element = cold.deref();
|
|
67
|
-
if (element !== undefined) {
|
|
68
|
-
this._hots.push({ root: element, frame: this._frame });
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
get() {
|
|
75
|
-
this.retrieve();
|
|
76
|
-
const element = this._hots.pop();
|
|
77
|
-
if (element === undefined) {
|
|
78
|
-
return undefined;
|
|
79
|
-
}
|
|
80
|
-
element.frame = this._frame;
|
|
81
|
-
return element.root;
|
|
82
|
-
}
|
|
83
|
-
add(root) {
|
|
84
|
-
this._hots.push({ root, frame: this._frame });
|
|
85
|
-
}
|
|
86
|
-
tick() {
|
|
87
|
-
this.evict();
|
|
88
|
-
this._frame++;
|
|
89
|
-
}
|
|
90
|
-
get listeners() {
|
|
91
|
-
return this._listeners;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
class CollectionApplier {
|
|
95
|
-
_pool;
|
|
96
|
-
_id;
|
|
97
|
-
_payload;
|
|
98
|
-
_compilation;
|
|
99
|
-
_template;
|
|
100
|
-
_elements = [];
|
|
101
|
-
_appliers;
|
|
102
|
-
_applier;
|
|
103
|
-
constructor(_pool, _id, _payload) {
|
|
104
|
-
this._pool = _pool;
|
|
105
|
-
this._id = _id;
|
|
106
|
-
this._payload = _payload;
|
|
107
|
-
const node = this._payload.each();
|
|
108
|
-
const compiler = new Compiler();
|
|
109
|
-
const appliers = new Appliers(this._pool);
|
|
110
|
-
const template = transform(node);
|
|
111
|
-
const compilation = compiler.compile(node);
|
|
112
|
-
this._appliers = appliers;
|
|
113
|
-
this._compilation = compilation;
|
|
114
|
-
this._template = template;
|
|
115
|
-
}
|
|
116
|
-
apply(root, context) {
|
|
117
|
-
if (this._applier === undefined) {
|
|
118
|
-
this._applier = this._appliers.apply(this._compilation);
|
|
119
|
-
}
|
|
120
|
-
const items = this._payload.select(context);
|
|
121
|
-
const nodes = root[SF_CACHE];
|
|
122
|
-
const target = nodes[this._id];
|
|
123
|
-
const { replaces, clears, addes, swaps, removes, updates } = items.flush();
|
|
124
|
-
if (replaces) {
|
|
125
|
-
const items_count = items.size;
|
|
126
|
-
const child_count = this._elements.length;
|
|
127
|
-
const common_count = Math.min(items_count, child_count);
|
|
128
|
-
for (let index = 0; index < common_count; index++) {
|
|
129
|
-
this._applier(this._elements[index], items.at(index));
|
|
130
|
-
}
|
|
131
|
-
if (items_count < child_count) {
|
|
132
|
-
for (let index = items_count; index < child_count; index++) {
|
|
133
|
-
const element = this._elements[index];
|
|
134
|
-
this._pool.add(element);
|
|
135
|
-
element.remove();
|
|
136
|
-
}
|
|
137
|
-
this._elements.length = items_count;
|
|
138
|
-
}
|
|
139
|
-
else if (child_count < items_count) {
|
|
140
|
-
const fragment = document.createDocumentFragment();
|
|
141
|
-
const elements = new Array(items_count - child_count);
|
|
142
|
-
for (let index = child_count; index < items_count; index++) {
|
|
143
|
-
const element = this._pool.get() || this._template.cloneNode(true);
|
|
144
|
-
this._applier(element, items.at(index));
|
|
145
|
-
elements[index - child_count] = element;
|
|
146
|
-
fragment.appendChild(element);
|
|
147
|
-
}
|
|
148
|
-
this._elements = this._elements.concat(elements);
|
|
149
|
-
target.appendChild(fragment);
|
|
150
|
-
}
|
|
151
|
-
return;
|
|
152
|
-
}
|
|
153
|
-
if (clears) {
|
|
154
|
-
const free = this._elements.splice(0);
|
|
155
|
-
for (const element of free) {
|
|
156
|
-
this._pool.add(element);
|
|
157
|
-
}
|
|
158
|
-
target.innerHTML = String();
|
|
159
|
-
}
|
|
160
|
-
if (addes > 0) {
|
|
161
|
-
const fragment = document.createDocumentFragment();
|
|
162
|
-
const elements = new Array(addes);
|
|
163
|
-
for (let index = 0; index < addes; index++) {
|
|
164
|
-
const element = this._template.cloneNode(true);
|
|
165
|
-
this._applier(element, items.at(index));
|
|
166
|
-
elements[index] = element;
|
|
167
|
-
fragment.appendChild(element);
|
|
168
|
-
}
|
|
169
|
-
this._elements = this._elements.concat(elements);
|
|
170
|
-
target.appendChild(fragment);
|
|
171
|
-
}
|
|
172
|
-
for (const [i, j] of swaps.entries()) {
|
|
173
|
-
this._applier(this._elements[i], items.at(i));
|
|
174
|
-
this._applier(this._elements[j], items.at(j));
|
|
175
|
-
}
|
|
176
|
-
for (const id of removes) {
|
|
177
|
-
const element = this._elements[id];
|
|
178
|
-
this._pool.add(element);
|
|
179
|
-
element.remove();
|
|
180
|
-
}
|
|
181
|
-
for (const id of updates) {
|
|
182
|
-
this._applier(this._elements[id], items.at(id));
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
export class Appliers {
|
|
187
|
-
_pool;
|
|
188
|
-
_listeners;
|
|
189
|
-
constructor(_pool) {
|
|
190
|
-
this._pool = _pool;
|
|
191
|
-
this._listeners = this._pool.listeners;
|
|
192
|
-
}
|
|
193
|
-
find_element_by(root, path) {
|
|
194
|
-
let current = root;
|
|
195
|
-
for (let id = 0; id < path.length; id++) {
|
|
196
|
-
current = current.children[path[id]];
|
|
197
|
-
}
|
|
198
|
-
return current;
|
|
199
|
-
}
|
|
200
|
-
apply_conditional(id, payload) {
|
|
201
|
-
return (root, context) => {
|
|
202
|
-
const nodes = root[SF_CACHE];
|
|
203
|
-
const target = nodes[id];
|
|
204
|
-
const condition = payload(context);
|
|
205
|
-
target.style.display = condition ? String() : 'none';
|
|
206
|
-
};
|
|
207
|
-
}
|
|
208
|
-
apply_text(id, payload) {
|
|
209
|
-
return (root, context) => {
|
|
210
|
-
const text = payload(context);
|
|
211
|
-
const nodes = root[SF_CACHE_TEXT];
|
|
212
|
-
const textnode = nodes[id];
|
|
213
|
-
textnode.nodeValue = text;
|
|
214
|
-
};
|
|
215
|
-
}
|
|
216
|
-
apply_properties(id, payload) {
|
|
217
|
-
return (root, context) => {
|
|
218
|
-
const nodes = root[SF_CACHE];
|
|
219
|
-
const element = nodes[id];
|
|
220
|
-
for (const key in payload) {
|
|
221
|
-
element[key] = payload[key](context);
|
|
222
|
-
}
|
|
223
|
-
};
|
|
224
|
-
}
|
|
225
|
-
apply_events(id, payload) {
|
|
226
|
-
return (root, context) => {
|
|
227
|
-
const nodes = root[SF_CACHE];
|
|
228
|
-
const element = nodes[id];
|
|
229
|
-
if (element[SF_LISTENED]) {
|
|
230
|
-
element[SF_CONTEXT] = context;
|
|
231
|
-
return;
|
|
232
|
-
}
|
|
233
|
-
element[SF_LISTENED] = true;
|
|
234
|
-
element[SF_CONTEXT] = context;
|
|
235
|
-
for (let key in payload) {
|
|
236
|
-
this._listeners.add(element, key, payload[key]);
|
|
237
|
-
}
|
|
238
|
-
};
|
|
239
|
-
}
|
|
240
|
-
apply_iterate(id, payload) {
|
|
241
|
-
const appliers = new CollectionApplier(this._pool, id, payload);
|
|
242
|
-
return (root, context) => appliers.apply(root, context);
|
|
243
|
-
}
|
|
244
|
-
markup(root, paths) {
|
|
245
|
-
const node = root;
|
|
246
|
-
if (node[SF_CACHE]) {
|
|
247
|
-
return node[SF_CACHE];
|
|
248
|
-
}
|
|
249
|
-
const cache = new Array(paths.length);
|
|
250
|
-
const text_cache = new Array(paths.length);
|
|
251
|
-
for (let id = 0; id < paths.length; id++) {
|
|
252
|
-
cache[id] = this.find_element_by(root, paths[id]);
|
|
253
|
-
text_cache[id] = cache[id].firstChild;
|
|
254
|
-
}
|
|
255
|
-
node[SF_CACHE] = cache;
|
|
256
|
-
node[SF_CACHE_TEXT] = text_cache;
|
|
257
|
-
return cache;
|
|
258
|
-
}
|
|
259
|
-
apply(template) {
|
|
260
|
-
const { instructions, paths } = template;
|
|
261
|
-
const appliers = new Array(instructions.length);
|
|
262
|
-
let fill_index = 0;
|
|
263
|
-
for (let index = 0; index < instructions.length; index++) {
|
|
264
|
-
const instruction = instructions[index];
|
|
265
|
-
const id = instruction.id;
|
|
266
|
-
if (instruction.text !== undefined) {
|
|
267
|
-
appliers[fill_index++] = this.apply_text(id, instruction.text);
|
|
268
|
-
}
|
|
269
|
-
if (instruction.iterate !== undefined) {
|
|
270
|
-
appliers[fill_index++] = this.apply_iterate(id, instruction.iterate);
|
|
271
|
-
}
|
|
272
|
-
if (instruction.events !== undefined) {
|
|
273
|
-
appliers[fill_index++] = this.apply_events(id, instruction.events);
|
|
274
|
-
}
|
|
275
|
-
if (instruction.properties !== undefined) {
|
|
276
|
-
appliers[fill_index++] = this.apply_properties(id, instruction.properties);
|
|
277
|
-
}
|
|
278
|
-
if (instruction.conditional !== undefined) {
|
|
279
|
-
appliers[fill_index++] = this.apply_conditional(id, instruction.conditional);
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
return (root, context) => {
|
|
283
|
-
this.markup(root, paths);
|
|
284
|
-
for (const applier of appliers) {
|
|
285
|
-
applier(root, context);
|
|
286
|
-
}
|
|
287
|
-
};
|
|
288
|
-
}
|
|
289
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { AnyDOM } from "../types.js";
|
|
2
|
-
import { Modifiers } from "../properties/modifiers.js";
|
|
3
|
-
export type Instructions<V> = Partial<{
|
|
4
|
-
[L in keyof Modifiers<V>]: Modifiers<V>[L];
|
|
5
|
-
}> & {
|
|
6
|
-
id: number;
|
|
7
|
-
};
|
|
8
|
-
export type Template<V> = {
|
|
9
|
-
paths: number[][];
|
|
10
|
-
instructions: Instructions<V>[];
|
|
11
|
-
};
|
|
12
|
-
export declare class Compiler<V> {
|
|
13
|
-
private ID_COUNTER;
|
|
14
|
-
private _paths;
|
|
15
|
-
private _instructions;
|
|
16
|
-
private recursive_compile;
|
|
17
|
-
compile(root: AnyDOM<V>): Template<V>;
|
|
18
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
export class Compiler {
|
|
2
|
-
ID_COUNTER = 0;
|
|
3
|
-
_paths = [];
|
|
4
|
-
_instructions = [];
|
|
5
|
-
recursive_compile(node, path) {
|
|
6
|
-
const modifiers = node.properties.modifiers || {};
|
|
7
|
-
const has_modifiers = modifiers.text !== undefined ||
|
|
8
|
-
modifiers.properties !== undefined ||
|
|
9
|
-
modifiers.events !== undefined ||
|
|
10
|
-
modifiers.iterate !== undefined ||
|
|
11
|
-
modifiers.conditional !== undefined;
|
|
12
|
-
if (has_modifiers) {
|
|
13
|
-
const current_id = this.ID_COUNTER++;
|
|
14
|
-
this._paths.push(path);
|
|
15
|
-
const instruction = { id: current_id };
|
|
16
|
-
if (modifiers.text !== undefined) {
|
|
17
|
-
instruction.text = modifiers.text;
|
|
18
|
-
}
|
|
19
|
-
if (modifiers.properties !== undefined) {
|
|
20
|
-
instruction.properties = modifiers.properties;
|
|
21
|
-
}
|
|
22
|
-
if (modifiers.events !== undefined) {
|
|
23
|
-
instruction.events = modifiers.events;
|
|
24
|
-
}
|
|
25
|
-
if (modifiers.iterate !== undefined) {
|
|
26
|
-
instruction.iterate = modifiers.iterate;
|
|
27
|
-
}
|
|
28
|
-
if (modifiers.conditional !== undefined) {
|
|
29
|
-
instruction.conditional = modifiers.conditional;
|
|
30
|
-
}
|
|
31
|
-
this._instructions.push(instruction);
|
|
32
|
-
}
|
|
33
|
-
for (let index = 0; index < node.children.length; index++) {
|
|
34
|
-
this.recursive_compile(node.children[index], [...path, index]);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
compile(root) {
|
|
38
|
-
this.ID_COUNTER = 0;
|
|
39
|
-
this._instructions = [];
|
|
40
|
-
this._paths = [];
|
|
41
|
-
this.recursive_compile(root, []);
|
|
42
|
-
return {
|
|
43
|
-
paths: this._paths,
|
|
44
|
-
instructions: this._instructions
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
function apply_text(description, root) {
|
|
2
|
-
const text = description.properties.text || String();
|
|
3
|
-
if (root.firstChild === null || root.firstChild.nodeType !== Node.TEXT_NODE) {
|
|
4
|
-
root.insertBefore(document.createTextNode(text), null);
|
|
5
|
-
return;
|
|
6
|
-
}
|
|
7
|
-
root.firstChild.nodeValue = text;
|
|
8
|
-
}
|
|
9
|
-
function apply_properties(description, root) {
|
|
10
|
-
let { properties } = description.properties;
|
|
11
|
-
properties = properties || {};
|
|
12
|
-
for (const key in properties) {
|
|
13
|
-
root[key] = properties[key];
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
function apply_styles(description, root) {
|
|
17
|
-
let { styles } = description.properties;
|
|
18
|
-
styles = styles || {};
|
|
19
|
-
for (const key in styles) {
|
|
20
|
-
root.style[key] = styles[key];
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
function apply_events(description, root) {
|
|
24
|
-
let { events } = description.properties;
|
|
25
|
-
events = events || {};
|
|
26
|
-
for (const key in events) {
|
|
27
|
-
root.addEventListener(key, events[key]);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
export function transform(description) {
|
|
31
|
-
let { name } = description.properties;
|
|
32
|
-
const root = document.createElement(name);
|
|
33
|
-
apply_properties(description, root);
|
|
34
|
-
apply_styles(description, root);
|
|
35
|
-
apply_events(description, root);
|
|
36
|
-
apply_text(description, root);
|
|
37
|
-
for (const child of description.children) {
|
|
38
|
-
root.appendChild(transform(child));
|
|
39
|
-
}
|
|
40
|
-
return root;
|
|
41
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { AnyDOM } from "./dom.js";
|
|
2
|
-
import { Properties } from "./properties/properties.js";
|
|
3
|
-
import { Binding } from "../binding.js";
|
|
4
|
-
type PropertiesWithoutServices<V, K extends keyof HTMLElementTagNameMap> = Omit<Properties<V, K>, 'name'>;
|
|
5
|
-
export type DOMRegistry = {
|
|
6
|
-
[K in keyof HTMLElementTagNameMap]: <V>(properties: Partial<PropertiesWithoutServices<V, K>>, children?: Binding<any>[]) => AnyDOM<V>;
|
|
7
|
-
};
|
|
8
|
-
export declare const DOM_REGISTRY: DOMRegistry;
|
|
9
|
-
export declare class DOMAdapter<V> {
|
|
10
|
-
$(root: AnyDOM<V>): {
|
|
11
|
-
element: HTMLAnchorElement | HTMLAreaElement | HTMLAudioElement | HTMLBRElement | HTMLBaseElement | HTMLBodyElement | HTMLButtonElement | HTMLCanvasElement | HTMLDListElement | HTMLDataElement | HTMLDataListElement | HTMLDetailsElement | HTMLDialogElement | HTMLDivElement | HTMLElement | HTMLEmbedElement | HTMLFieldSetElement | HTMLFormElement | HTMLHRElement | HTMLHeadElement | HTMLHeadingElement | HTMLHtmlElement | HTMLIFrameElement | HTMLImageElement | HTMLInputElement | HTMLLIElement | HTMLLabelElement | HTMLLegendElement | HTMLLinkElement | HTMLMapElement | HTMLMenuElement | HTMLMetaElement | HTMLMeterElement | HTMLModElement | HTMLOListElement | HTMLObjectElement | HTMLOptGroupElement | HTMLOptionElement | HTMLOutputElement | HTMLParagraphElement | HTMLPictureElement | HTMLPreElement | HTMLProgressElement | HTMLQuoteElement | HTMLScriptElement | HTMLSelectElement | HTMLSlotElement | HTMLSourceElement | HTMLSpanElement | HTMLStyleElement | HTMLTableCaptionElement | HTMLTableCellElement | HTMLTableColElement | HTMLTableElement | HTMLTableRowElement | HTMLTableSectionElement | HTMLTemplateElement | HTMLTextAreaElement | HTMLTimeElement | HTMLTitleElement | HTMLTrackElement | HTMLUListElement | HTMLVideoElement;
|
|
12
|
-
update: (context: V) => void;
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
export {};
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { HTML_TAGS } from "./tags.js";
|
|
2
|
-
import { Compiler } from "./compiler/compile.js";
|
|
3
|
-
import { Appliers } from "./compiler/apply.js";
|
|
4
|
-
import { transform } from "./compiler/transform.js";
|
|
5
|
-
import { describe } from "./description/describe.js";
|
|
6
|
-
export const DOM_REGISTRY = Object.create(null);
|
|
7
|
-
export class DOMAdapter {
|
|
8
|
-
$(root) {
|
|
9
|
-
const element = transform(root);
|
|
10
|
-
const compiler = new Compiler();
|
|
11
|
-
const compilation = compiler.compile(root);
|
|
12
|
-
const appliers = new Appliers();
|
|
13
|
-
const applier = appliers.apply(compilation);
|
|
14
|
-
const update = (context) => applier(element, context);
|
|
15
|
-
return { element, update };
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
for (const tag of HTML_TAGS) {
|
|
19
|
-
DOM_REGISTRY[tag] = (properties, children = []) => {
|
|
20
|
-
return describe({ ...properties, name: tag }, children);
|
|
21
|
-
};
|
|
22
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { Stillflow, State, adapters, FlushableCollection, FenwickCollection } from "../index.js";
|
|
2
|
-
const { jsxdom, dom } = adapters;
|
|
3
|
-
const core = new Stillflow(new State());
|
|
4
|
-
const factory = core.factory();
|
|
5
|
-
factory.add('collection', () => new FlushableCollection(new FenwickCollection(100)));
|
|
6
|
-
function FileView({ depth }) {
|
|
7
|
-
return (adapters.jsx(jsxdom.div, { styles: { 'padding': `${depth * 4}px` } },
|
|
8
|
-
adapters.jsx(jsxdom.span, null, (context) => context.name),
|
|
9
|
-
adapters.jsx(jsxdom.div, { "sf:for": (context) => context.files, "sf:each": () => adapters.jsx(FileView, { depth: depth + 1 }) })));
|
|
10
|
-
}
|
|
11
|
-
const root = {
|
|
12
|
-
name: 'test',
|
|
13
|
-
files: factory.get('collection', {})
|
|
14
|
-
};
|
|
15
|
-
root.files.add({
|
|
16
|
-
name: 'test-0',
|
|
17
|
-
files: factory.get('collection', {})
|
|
18
|
-
});
|
|
19
|
-
root.files.at(0).files.add({
|
|
20
|
-
name: 'test-0-1',
|
|
21
|
-
files: factory.get('collection', {})
|
|
22
|
-
});
|
|
23
|
-
root.files.add({
|
|
24
|
-
name: 'test-1',
|
|
25
|
-
files: factory.get('collection', {})
|
|
26
|
-
});
|
|
27
|
-
const { element, update } = dom.$(adapters.jsx(FileView, { depth: 0 }));
|
|
28
|
-
update(root);
|
|
29
|
-
document.body.append(element);
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { Stillflow, State, FenwickCollection, FlushableCollection, 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(FlushableCollection.name, () => new FlushableCollection(new FenwickCollection(100)));
|
|
7
|
-
const source = {
|
|
8
|
-
input: stillflow.variable('input').backref(),
|
|
9
|
-
items: operators.is(FlushableCollection.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
|
-
document.body.appendChild(app);
|
|
35
|
-
update(instance);
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
export class Analyzer {
|
|
2
|
-
static MAXIMAL_SIZE = 2 ** 16;
|
|
3
|
-
static ID_COUNTER = 0;
|
|
4
|
-
traverse(binding, callback, path = []) {
|
|
5
|
-
callback(binding, path);
|
|
6
|
-
for (let index = 0, length = binding.children.length; index < length; index++) {
|
|
7
|
-
const child = binding.children[index];
|
|
8
|
-
if (typeof child === 'object') {
|
|
9
|
-
this.traverse(child, callback, [...path, index]);
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
analyze(binding) {
|
|
14
|
-
const buffer = new Uint32Array(Analyzer.MAXIMAL_SIZE);
|
|
15
|
-
let offset = 0;
|
|
16
|
-
let length = 0;
|
|
17
|
-
buffer[offset++] = length;
|
|
18
|
-
this.traverse(binding, (binding, path) => {
|
|
19
|
-
});
|
|
20
|
-
return buffer;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|