stillflow.engine 0.1.7 → 0.1.8
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.
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
import { HTML_TAGS } from "./tags.js";
|
|
2
2
|
import { Compiler } from "./compiler/compile.js";
|
|
3
|
-
import { Appliers } from "./compiler/apply.js";
|
|
3
|
+
import { Appliers, Listeners, Pool } from "./compiler/apply.js";
|
|
4
4
|
import { transform } from "./compiler/transform.js";
|
|
5
5
|
import { describe } from "./description/describe.js";
|
|
6
6
|
export const DOM_REGISTRY = Object.create(null);
|
|
7
7
|
DOM_REGISTRY.$ = function $(root) {
|
|
8
8
|
const element = transform(root);
|
|
9
|
+
const pool = new Pool(new Listeners());
|
|
9
10
|
const compiler = new Compiler();
|
|
10
11
|
const compilation = compiler.compile(root);
|
|
11
|
-
const appliers = new Appliers();
|
|
12
|
+
const appliers = new Appliers(pool);
|
|
12
13
|
const applier = appliers.apply(compilation);
|
|
13
14
|
const update = (context) => applier(element, context);
|
|
14
|
-
|
|
15
|
+
const clean = () => pool.tick();
|
|
16
|
+
return { element, update, clean };
|
|
15
17
|
};
|
|
16
18
|
for (const tag of HTML_TAGS) {
|
|
17
19
|
DOM_REGISTRY[tag] = (properties, children = []) => {
|
|
@@ -1,7 +1,30 @@
|
|
|
1
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
|
+
}
|
|
2
23
|
type Applier<V> = (root: HTMLElement, context: V) => void;
|
|
3
24
|
export declare class Appliers<V> {
|
|
25
|
+
private _pool;
|
|
4
26
|
private _listeners;
|
|
27
|
+
constructor(_pool: Pool);
|
|
5
28
|
private find_element_by;
|
|
6
29
|
private apply_conditional;
|
|
7
30
|
private apply_text;
|
|
@@ -4,7 +4,7 @@ const SF_LISTENED = '__stillflow_listened__';
|
|
|
4
4
|
const SF_CONTEXT = '__stillflow_context__';
|
|
5
5
|
const SF_CACHE_TEXT = '__stillflow_cache_text__';
|
|
6
6
|
const SF_CACHE = '__stillflow_cache__';
|
|
7
|
-
class Listeners {
|
|
7
|
+
export class Listeners {
|
|
8
8
|
_listeners = new WeakMap();
|
|
9
9
|
_actives = new Set();
|
|
10
10
|
ensure(type) {
|
|
@@ -37,7 +37,7 @@ class Listeners {
|
|
|
37
37
|
this.ensure(type);
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
|
-
class Pool {
|
|
40
|
+
export class Pool {
|
|
41
41
|
_listeners;
|
|
42
42
|
static TIME_TO_EVICT = 2;
|
|
43
43
|
_hots = [];
|
|
@@ -85,9 +85,11 @@ class Pool {
|
|
|
85
85
|
}
|
|
86
86
|
tick() {
|
|
87
87
|
this.evict();
|
|
88
|
-
console.log(this._frame);
|
|
89
88
|
this._frame++;
|
|
90
89
|
}
|
|
90
|
+
get listeners() {
|
|
91
|
+
return this._listeners;
|
|
92
|
+
}
|
|
91
93
|
}
|
|
92
94
|
class CollectionApplier {
|
|
93
95
|
_pool;
|
|
@@ -104,22 +106,12 @@ class CollectionApplier {
|
|
|
104
106
|
this._payload = _payload;
|
|
105
107
|
const node = this._payload.each();
|
|
106
108
|
const compiler = new Compiler();
|
|
107
|
-
const appliers = new Appliers();
|
|
109
|
+
const appliers = new Appliers(this._pool);
|
|
108
110
|
const template = transform(node);
|
|
109
111
|
const compilation = compiler.compile(node);
|
|
110
112
|
this._appliers = appliers;
|
|
111
113
|
this._compilation = compilation;
|
|
112
114
|
this._template = template;
|
|
113
|
-
const pool = this._pool;
|
|
114
|
-
function schedule() {
|
|
115
|
-
requestIdleCallback(function clean(deadline) {
|
|
116
|
-
if (deadline.timeRemaining() > 0 || deadline.didTimeout) {
|
|
117
|
-
pool.tick();
|
|
118
|
-
}
|
|
119
|
-
schedule();
|
|
120
|
-
}, { timeout: 1000 });
|
|
121
|
-
}
|
|
122
|
-
schedule();
|
|
123
115
|
}
|
|
124
116
|
apply(root, context) {
|
|
125
117
|
if (this._applier === undefined) {
|
|
@@ -192,7 +184,12 @@ class CollectionApplier {
|
|
|
192
184
|
}
|
|
193
185
|
}
|
|
194
186
|
export class Appliers {
|
|
195
|
-
|
|
187
|
+
_pool;
|
|
188
|
+
_listeners;
|
|
189
|
+
constructor(_pool) {
|
|
190
|
+
this._pool = _pool;
|
|
191
|
+
this._listeners = this._pool.listeners;
|
|
192
|
+
}
|
|
196
193
|
find_element_by(root, path) {
|
|
197
194
|
let current = root;
|
|
198
195
|
for (let id = 0; id < path.length; id++) {
|
|
@@ -241,8 +238,7 @@ export class Appliers {
|
|
|
241
238
|
};
|
|
242
239
|
}
|
|
243
240
|
apply_iterate(id, payload) {
|
|
244
|
-
const
|
|
245
|
-
const appliers = new CollectionApplier(pool, id, payload);
|
|
241
|
+
const appliers = new CollectionApplier(this._pool, id, payload);
|
|
246
242
|
return (root, context) => appliers.apply(root, context);
|
|
247
243
|
}
|
|
248
244
|
markup(root, paths) {
|