stillflow.engine 0.0.0-stage → 0.1.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.
Files changed (97) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +114 -2
  3. package/dist/index.d.ts +9 -0
  4. package/dist/index.js +8 -0
  5. package/dist/stillflow/abstracts/IR.d.ts +7 -0
  6. package/dist/stillflow/abstracts/IR.js +1 -0
  7. package/dist/stillflow/abstracts/meta.d.ts +8 -0
  8. package/dist/stillflow/abstracts/meta.js +1 -0
  9. package/dist/stillflow/abstracts/operators.d.ts +22 -0
  10. package/dist/stillflow/abstracts/operators.js +1 -0
  11. package/dist/stillflow/abstracts/state.d.ts +7 -0
  12. package/dist/stillflow/abstracts/state.js +1 -0
  13. package/dist/stillflow/abstracts/view.d.ts +8 -0
  14. package/dist/stillflow/abstracts/view.js +1 -0
  15. package/dist/stillflow/compiler/compile.d.ts +11 -0
  16. package/dist/stillflow/compiler/compile.js +84 -0
  17. package/dist/stillflow/compiler/instantiate.d.ts +3 -0
  18. package/dist/stillflow/compiler/instantiate.js +40 -0
  19. package/dist/stillflow/factories/factories.d.ts +10 -0
  20. package/dist/stillflow/factories/factories.js +20 -0
  21. package/dist/stillflow/kernel/buffer.d.ts +9 -0
  22. package/dist/stillflow/kernel/buffer.js +13 -0
  23. package/dist/stillflow/kernel/kernel.d.ts +20 -0
  24. package/dist/stillflow/kernel/kernel.js +44 -0
  25. package/dist/stillflow/kernel/signal.d.ts +5 -0
  26. package/dist/stillflow/kernel/signal.js +12 -0
  27. package/dist/stillflow/operators.d.ts +15 -0
  28. package/dist/stillflow/operators.js +31 -0
  29. package/dist/stillflow/state.d.ts +9 -0
  30. package/dist/stillflow/state.js +12 -0
  31. package/dist/stillflow/stillflow.d.ts +27 -0
  32. package/dist/stillflow/stillflow.js +59 -0
  33. package/dist/stillflow/tools/batcher.d.ts +8 -0
  34. package/dist/stillflow/tools/batcher.js +17 -0
  35. package/dist/stillflow/variable.d.ts +12 -0
  36. package/dist/stillflow/variable.js +24 -0
  37. package/dist/stillflow-adapters/binding.d.ts +4 -0
  38. package/dist/stillflow-adapters/binding.js +1 -0
  39. package/dist/stillflow-adapters/dom/compiler/apply.d.ts +16 -0
  40. package/dist/stillflow-adapters/dom/compiler/apply.js +212 -0
  41. package/dist/stillflow-adapters/dom/compiler/compile.d.ts +18 -0
  42. package/dist/stillflow-adapters/dom/compiler/compile.js +47 -0
  43. package/dist/stillflow-adapters/dom/compiler/transform.d.ts +2 -0
  44. package/dist/stillflow-adapters/dom/compiler/transform.js +41 -0
  45. package/dist/stillflow-adapters/dom/description/describe.d.ts +3 -0
  46. package/dist/stillflow-adapters/dom/description/describe.js +6 -0
  47. package/dist/stillflow-adapters/dom/dom.d.ts +4 -0
  48. package/dist/stillflow-adapters/dom/dom.js +1 -0
  49. package/dist/stillflow-adapters/dom/index.d.ts +15 -0
  50. package/dist/stillflow-adapters/dom/index.js +22 -0
  51. package/dist/stillflow-adapters/dom/jsx.dom.d.ts +32 -0
  52. package/dist/stillflow-adapters/dom/jsx.dom.js +77 -0
  53. package/dist/stillflow-adapters/dom/properties/modifiers.d.ts +17 -0
  54. package/dist/stillflow-adapters/dom/properties/modifiers.js +1 -0
  55. package/dist/stillflow-adapters/dom/properties/properties.d.ts +15 -0
  56. package/dist/stillflow-adapters/dom/properties/properties.js +1 -0
  57. package/dist/stillflow-adapters/dom/tags.d.ts +7 -0
  58. package/dist/stillflow-adapters/dom/tags.js +5 -0
  59. package/dist/stillflow-adapters/index.d.ts +3 -0
  60. package/dist/stillflow-adapters/index.js +3 -0
  61. package/dist/stillflow-adapters/runtime/jsx.runtime.d.ts +2 -0
  62. package/dist/stillflow-adapters/runtime/jsx.runtime.js +3 -0
  63. package/dist/stillflow-collection/abstract/collection.d.ts +15 -0
  64. package/dist/stillflow-collection/abstract/collection.js +1 -0
  65. package/dist/stillflow-collection/delta.d.ts +10 -0
  66. package/dist/stillflow-collection/delta.js +18 -0
  67. package/dist/stillflow-collection/fenwick.d.ts +24 -0
  68. package/dist/stillflow-collection/fenwick.js +102 -0
  69. package/dist/stillflow-collection/flushable.d.ts +21 -0
  70. package/dist/stillflow-collection/flushable.js +70 -0
  71. package/dist/stillflow-collection/utilities/disjointed-set.d.ts +10 -0
  72. package/dist/stillflow-collection/utilities/disjointed-set.js +45 -0
  73. package/dist/stillflow-collection/utilities/fenwick-tree.d.ts +9 -0
  74. package/dist/stillflow-collection/utilities/fenwick-tree.js +27 -0
  75. package/dist/stillflow-collection/utilities/interval-merger.d.ts +7 -0
  76. package/dist/stillflow-collection/utilities/interval-merger.js +70 -0
  77. package/dist/stillflow-collection/utilities/range-fenwick-tree.d.ts +11 -0
  78. package/dist/stillflow-collection/utilities/range-fenwick-tree.js +28 -0
  79. package/dist/stillflow-examples/app.d.ts +1 -0
  80. package/dist/stillflow-examples/app.js +140 -0
  81. package/dist/stillflow-examples/data.d.ts +5 -0
  82. package/dist/stillflow-examples/data.js +73 -0
  83. package/dist/stillflow-examples/test.d.ts +1 -0
  84. package/dist/stillflow-examples/test.js +35 -0
  85. package/dist/stillflow-scripts/gen-tags.d.ts +1 -0
  86. package/dist/stillflow-scripts/gen-tags.js +50 -0
  87. package/dist/stillflow-vm/analyze.d.ts +7 -0
  88. package/dist/stillflow-vm/analyze.js +22 -0
  89. package/dist/stillflow-vm/buffer.d.ts +1 -0
  90. package/dist/stillflow-vm/buffer.js +1 -0
  91. package/dist/stillflow-vm/instruction.d.ts +1 -0
  92. package/dist/stillflow-vm/instruction.js +1 -0
  93. package/dist/stillflow-vm/pool.d.ts +1 -0
  94. package/dist/stillflow-vm/pool.js +1 -0
  95. package/dist/stillflow-vm/resources.d.ts +14 -0
  96. package/dist/stillflow-vm/resources.js +16 -0
  97. package/package.json +38 -4
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 SampleUserD
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,115 @@
1
- # Temporary Holding Version
1
+ # Stillflow
2
+ > A headless, transaction-based UI engine with AOT compilation with predictable performance and memory usage.
2
3
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
4
+ ## Reasons
5
+ I built **Stillflow** to solve my own architectural problems. I wanted explicit control over the life cycle of application with predictable performance with serializable state out of box. My solution does not use **Virtual DOM**, because it's a single most *unpredictable* thing in **UI-heavy applications**, because it does diffing and patch by **O(n)** with a heavy constant.
6
+
7
+ ## Philosophy
8
+
9
+ > UI = State + Projections + Bindings + Feedback loop.
10
+
11
+ I think it is a **misconception** that `UI = f(state)`, because every `UI` has *user and document events* (`click`, `input`, `load` and *etc.*). So I derive that `state = g(UI)`, where `g` **is not** and inverse function of `f`, because we cannot restore *state* from `UI` fully in the most cases, because **UI is a subset of state**.
12
+
13
+ Also I think of a `state` as a `global state` and a simple `"map"` ([Read about it here](http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)) with filled with `primitives` (`number`, `string`, `object` and `array`, but not `symbol`, `function` or `class instances`) as I call it `"map-state"`. You could have thought that it is antipattern and a bad practice so it is out of consideration. But it makes the `state` the **single source of truth** so we can restore `UI` from the *state* fully [`UI = f(state)`]. The *map-state* makes the *serialization* of *state* easier and predictable.
14
+
15
+ Also I think that **explicit reactivity is better than implicit reactivity**. So **Stillflow** has *`commit()` method that controls the update time. Before *commit* buffer is full, but changes are not applied to the *map-state*. It makes *state-between-state* an impossible occurense. It makes the **Stillflow** model transactional and atomic.
16
+
17
+ ## Features
18
+
19
+ 1. **AOT-Compilation** --- Compiles JSX into flat object instructions at build time.
20
+ 2. **Transactional kernel** --- Explicit `commit()`, multi-buffers `buffer()` and atomic updates.
21
+ 3. **Pluggable Collections** --- Built-in Fenwick-based collections for fast clear/remove and Flushable with `flush()` collection for fast `delta` calculations.
22
+ 4. **Headless core** --- The core is completely independent of `DOM`
23
+ 5. **Type-safe JSX** --- Full autocomplete for `DOM` properties and directives (`sf:`)
24
+
25
+ ## Benchmarks
26
+
27
+ **Stillflow** performs within *1% of VanillaJS* in the Krause benchmark on my notepad in the Krause benchmark, while providing a full transactional state model.
28
+ ![Benchmark scores of Stillflow](images/1.png)
29
+
30
+ ## Quick Start
31
+
32
+ ### Let's make some simple Todo application
33
+ ```ts
34
+ import { Stillflow, State, FenwickCollection, FlushableCollection, operators, adapters } from 'stillflow.engine'
35
+
36
+ type AppState = {
37
+ input: string
38
+ }
39
+
40
+ type TodoItem = {
41
+ label: string
42
+ }
43
+
44
+ type TodoState = {
45
+ input: string,
46
+ items: FlushableCollection<TodoItem>
47
+ }
48
+
49
+ const { jsxdom, DOM } = adapters
50
+
51
+ const state = new State()
52
+ const stillflow = new Stillflow<AppState>(state)
53
+ const factory = stillflow.factory()
54
+
55
+ factory.add(FlushableCollection.name, () => new FlushableCollection(new FenwickCollection(100)))
56
+
57
+ const source = {
58
+ input: stillflow.variable('input').backref(),
59
+ items: operators.is(FlushableCollection.name)
60
+ }
61
+
62
+ const view = stillflow.compile(source)
63
+ const instance: TodoState = stillflow.instantiate(view, factory)
64
+
65
+ function change(event: any) {
66
+ instance.input = event.target.value
67
+ stillflow.commit()
68
+ }
69
+
70
+ function add() {
71
+ instance.items.add({ label: instance.input })
72
+ instance.input = String()
73
+ stillflow.commit()
74
+ }
75
+
76
+ function TodoItem() {
77
+ return (
78
+ <jsxdom.div>
79
+ {(context: TodoItem) => context.label}
80
+ </jsxdom.div>
81
+ )
82
+ }
83
+
84
+ function App() {
85
+ return (
86
+ <jsxdom.div>
87
+ <jsxdom.input sf:value={(context: TodoState) => context.input} on:change={change}/>
88
+ <jsxdom.button on:click={add}>
89
+ Add
90
+ </jsxdom.button>
91
+ <jsxdom.div sf:for={(context: TodoState) => context.items} sf:each={() => <TodoItem />}/>
92
+ </jsxdom.div>
93
+ )
94
+ }
95
+
96
+ const { element: app, update } = new DOM().$(<App />)
97
+
98
+ stillflow.on(() => update(instance))
99
+
100
+ instance.input = String()
101
+ stillflow.commit()
102
+
103
+ document.body.appendChild(app)
104
+ ```
105
+
106
+ ## How it works
107
+
108
+ 1. **Compile** --- JSX is parsed into an Intermediate Representation (IR).
109
+ 2. **Instantiate** --- State bindings are created.
110
+ 3. **Commit** --- Changes are batched and applied to the DOM via highly optimized appliers.
111
+ 4. **Collections** -- Delta are calculated and `clear/remove` are logical via Fenwick tree and binary lifting, but `shrink` is physical.
112
+
113
+ ## License
114
+
115
+ MIT
@@ -0,0 +1,9 @@
1
+ import * as adapters from './stillflow-adapters/index.js';
2
+ import operators from './stillflow/operators.js';
3
+ export { FlushableCollection } from './stillflow-collection/flushable.js';
4
+ export { AbstractCollection } from './stillflow-collection/abstract/collection.js';
5
+ export { FenwickCollection } from './stillflow-collection/fenwick.js';
6
+ export { Stillflow } from './stillflow/stillflow.js';
7
+ export { State } from './stillflow/state.js';
8
+ export { Batcher } from './stillflow/tools/batcher.js';
9
+ export { operators, adapters };
package/dist/index.js ADDED
@@ -0,0 +1,8 @@
1
+ import * as adapters from './stillflow-adapters/index.js';
2
+ import operators from './stillflow/operators.js';
3
+ export { FlushableCollection } from './stillflow-collection/flushable.js';
4
+ export { FenwickCollection } from './stillflow-collection/fenwick.js';
5
+ export { Stillflow } from './stillflow/stillflow.js';
6
+ export { State } from './stillflow/state.js';
7
+ export { Batcher } from './stillflow/tools/batcher.js';
8
+ export { operators, adapters };
@@ -0,0 +1,7 @@
1
+ export type IR = {
2
+ refs: Record<string, string>;
3
+ links: Record<string, any>;
4
+ locals: Record<string, any>;
5
+ backrefs: Record<string, string>;
6
+ behaviors: Record<string, string>;
7
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ import { IR } from "./IR.js";
2
+ export type Meta = {
3
+ meta: {
4
+ instantiated: boolean;
5
+ behaviors: Record<string, string>;
6
+ source: IR;
7
+ };
8
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,22 @@
1
+ type Mapping = Record<string, any>;
2
+ export type Ref<T extends Mapping, P extends keyof T> = {
3
+ type: 'ref';
4
+ path: P;
5
+ };
6
+ export type Backref<T extends Mapping, P extends keyof T> = {
7
+ type: 'backref';
8
+ path: P;
9
+ };
10
+ export type Local<T> = {
11
+ type: 'local';
12
+ value: T;
13
+ };
14
+ export type Link<V extends Mapping> = {
15
+ type: 'link';
16
+ source: V;
17
+ };
18
+ export type Is = {
19
+ type: 'is';
20
+ factory: string;
21
+ };
22
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ type Mapping = Record<string, any>;
2
+ export interface AbstractState<T extends Mapping = Mapping> {
3
+ write<K extends keyof T>(path: K, value: T[K]): void;
4
+ read<K extends keyof T>(path: K): T[K];
5
+ remove<K extends keyof T>(path: K): void;
6
+ }
7
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ import { Meta } from "./meta.js";
2
+ import { Backref, Link, Local, Ref } from "./operators.js";
3
+ type Mapping = Record<string, any>;
4
+ type OperatorView<V extends Mapping, T extends Mapping, K extends keyof V> = V[K] extends Ref<T, infer K0> ? T[K0] : V[K] extends Backref<T, infer K1> ? T[K1] : V[K] extends Local<infer K2> ? K2 : V[K] extends Link<infer K3> ? View<K3, T> : any;
5
+ export type View<V extends Mapping, T extends Mapping> = Meta & {
6
+ [K in keyof V]: OperatorView<V, T, K>;
7
+ };
8
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,11 @@
1
+ import { Backref, Is, Link, Local, Ref } from "../abstracts/operators.js";
2
+ import { Kernel } from "../kernel/kernel.js";
3
+ import { IR } from "../abstracts/IR.js";
4
+ import { Meta } from "../abstracts/meta.js";
5
+ import { View } from "../abstracts/view.js";
6
+ type Mapping = Record<string, any>;
7
+ type Source = Record<string, Link<any> | Ref<any, any> | Backref<any, any> | Local<any> | Is>;
8
+ export declare function $ProcessWrite<T extends Mapping>(kernel: Kernel<T>, source: IR, view: Mapping): void;
9
+ export declare function $ProcessRead<T extends Mapping>(kernel: Kernel<T>, source: IR, view: Mapping): void;
10
+ export declare function $Compile<V extends Source, T extends Mapping>(kernel: Kernel<T>, source: V): View<V, T> & Meta;
11
+ export {};
@@ -0,0 +1,84 @@
1
+ function $CompileIR(source) {
2
+ const ir = {
3
+ refs: Object.create(null),
4
+ links: Object.create(null),
5
+ locals: Object.create(null),
6
+ backrefs: Object.create(null),
7
+ behaviors: Object.create(null)
8
+ };
9
+ for (const key in source) {
10
+ const operator = source[key];
11
+ switch (operator.type) {
12
+ case 'is':
13
+ ir.behaviors[key] = operator.factory;
14
+ break;
15
+ case 'ref':
16
+ ir.refs[key] = operator.path;
17
+ break;
18
+ case 'link':
19
+ ir.links[key] = operator.source;
20
+ break;
21
+ case 'local':
22
+ ir.locals[key] = operator.value;
23
+ break;
24
+ case 'backref':
25
+ ir.backrefs[key] = operator.path;
26
+ break;
27
+ default:
28
+ throw new Error(`Undefined operator '${operator}'`);
29
+ }
30
+ }
31
+ return ir;
32
+ }
33
+ function $ProcessBackrefs(kernel, source, view) {
34
+ for (const key in source.backrefs) {
35
+ kernel.write(source.backrefs[key], view[key]);
36
+ }
37
+ }
38
+ function $ProcessLocals(source, view) {
39
+ for (const key in source.locals) {
40
+ view[key] = source.locals[key];
41
+ }
42
+ }
43
+ function $ProcessLinks(kernel, source, view) {
44
+ for (const key in source.links) {
45
+ view[key] = view[key] || {};
46
+ $Process(kernel, source.links[key], view[key]);
47
+ }
48
+ }
49
+ function $ProcessRef(kernel, source, view) {
50
+ for (const key in source.refs) {
51
+ view[key] = kernel.read(source.refs[key]);
52
+ }
53
+ }
54
+ function $ProcessIs(source, view) {
55
+ for (const key in source.behaviors) {
56
+ view.meta.behaviors[key] = source.behaviors[key];
57
+ }
58
+ }
59
+ function $Process(kernel, source, view) {
60
+ view.meta = {
61
+ instantiated: false,
62
+ behaviors: Object.create(null),
63
+ source
64
+ };
65
+ $ProcessBackrefs(kernel, source, view);
66
+ $ProcessLocals(source, view);
67
+ $ProcessLinks(kernel, source, view);
68
+ $ProcessRef(kernel, source, view);
69
+ $ProcessIs(source, view);
70
+ }
71
+ export function $ProcessWrite(kernel, source, view) {
72
+ $ProcessBackrefs(kernel, source, view);
73
+ $ProcessLinks(kernel, source, view);
74
+ }
75
+ export function $ProcessRead(kernel, source, view) {
76
+ $ProcessRef(kernel, source, view);
77
+ $ProcessLinks(kernel, source, view);
78
+ }
79
+ export function $Compile(kernel, source) {
80
+ const view = Object.create(null);
81
+ const ir = $CompileIR(source);
82
+ $Process(kernel, ir, view);
83
+ return view;
84
+ }
@@ -0,0 +1,3 @@
1
+ import { Meta } from "../abstracts/meta.js";
2
+ import { Factories } from "../factories/factories.js";
3
+ export declare function $Instantiate<V extends Meta>(view: V, factories: Factories): Meta;
@@ -0,0 +1,40 @@
1
+ export function $Instantiate(view, factories) {
2
+ function copy(view) {
3
+ return {
4
+ ...view,
5
+ meta: {
6
+ ...view.meta,
7
+ behaviors: {
8
+ ...view.meta.behaviors
9
+ }
10
+ }
11
+ };
12
+ }
13
+ function deepcopy(view, cache) {
14
+ if (cache.has(view)) {
15
+ return cache.get(view);
16
+ }
17
+ const instance = copy(view);
18
+ cache.set(view, instance);
19
+ for (const key in view.meta.source.links) {
20
+ instance[key] = deepcopy(view[key], cache);
21
+ }
22
+ return instance;
23
+ }
24
+ function instantiate(view, seen) {
25
+ if (seen.has(view) || view.meta.instantiated) {
26
+ return;
27
+ }
28
+ seen.add(view);
29
+ for (const key in view.meta.behaviors) {
30
+ view[key] = factories.get(view.meta.behaviors[key], view);
31
+ }
32
+ for (const key in view.meta.source.links) {
33
+ instantiate(view[key], seen);
34
+ }
35
+ view.meta.instantiated = true;
36
+ }
37
+ const instance = deepcopy(view, new WeakMap());
38
+ instantiate(instance, new Set());
39
+ return instance;
40
+ }
@@ -0,0 +1,10 @@
1
+ type Mapping = Record<string, any>;
2
+ export declare class Factories {
3
+ private _parent;
4
+ private _factories;
5
+ constructor(_parent?: Factories | null);
6
+ add<T, V extends Mapping>(type: string, factory: (view: V, factories: Factories) => T): void;
7
+ get<T, V extends Mapping>(type: string, view: V): T;
8
+ make(): Factories;
9
+ }
10
+ export {};
@@ -0,0 +1,20 @@
1
+ export class Factories {
2
+ _parent;
3
+ _factories = new Map();
4
+ constructor(_parent = null) {
5
+ this._parent = _parent;
6
+ }
7
+ add(type, factory) {
8
+ this._factories.set(type, factory);
9
+ }
10
+ get(type, view) {
11
+ const factory = this._factories.get(type);
12
+ if (factory === undefined) {
13
+ return this._parent?.get(type, view);
14
+ }
15
+ return factory(view, this);
16
+ }
17
+ make() {
18
+ return new Factories(this);
19
+ }
20
+ }
@@ -0,0 +1,9 @@
1
+ import { AbstractState } from "../abstracts/state.js";
2
+ type Mapping = Record<string, any>;
3
+ export declare class Buffer<T extends Mapping = Mapping> {
4
+ private _messages;
5
+ constructor();
6
+ write<K extends keyof T>(path: K, value: T[K]): void;
7
+ commit(state: AbstractState<T>): void;
8
+ }
9
+ export {};
@@ -0,0 +1,13 @@
1
+ export class Buffer {
2
+ _messages = new Map();
3
+ constructor() { }
4
+ write(path, value) {
5
+ this._messages.set(path, value);
6
+ }
7
+ commit(state) {
8
+ for (const [path, value] of this._messages.entries()) {
9
+ state.write(path, value);
10
+ }
11
+ this._messages.clear();
12
+ }
13
+ }
@@ -0,0 +1,20 @@
1
+ import { Buffer } from "./buffer.js";
2
+ import { AbstractState } from "../abstracts/state.js";
3
+ type Mapping = Record<string, any>;
4
+ export declare class Kernel<T extends Mapping = Mapping> implements AbstractState<T> {
5
+ private _state;
6
+ private _before;
7
+ private _after;
8
+ private _commiting;
9
+ private _additional;
10
+ private _buffers;
11
+ constructor(_state: AbstractState<T>);
12
+ bind(buffer: Buffer<T>): () => void;
13
+ before(site: () => void): () => void;
14
+ after(site: () => void): () => void;
15
+ write<K extends keyof T>(path: K, value: T[K]): void;
16
+ read<K extends keyof T>(path: K): T[K];
17
+ remove<K extends keyof T>(path: K): void;
18
+ commit(): void;
19
+ }
20
+ export {};
@@ -0,0 +1,44 @@
1
+ import { Signal } from "./signal.js";
2
+ import { Buffer } from "./buffer.js";
3
+ export class Kernel {
4
+ _state;
5
+ _before = new Signal();
6
+ _after = new Signal();
7
+ _commiting = false;
8
+ _additional = new Buffer();
9
+ _buffers = new Set([this._additional]);
10
+ constructor(_state) {
11
+ this._state = _state;
12
+ }
13
+ bind(buffer) {
14
+ this._buffers.add(buffer);
15
+ return () => this._buffers.delete(buffer);
16
+ }
17
+ before(site) {
18
+ return this._before.subscribe(site);
19
+ }
20
+ after(site) {
21
+ return this._after.subscribe(site);
22
+ }
23
+ write(path, value) {
24
+ this._additional.write(path, value);
25
+ }
26
+ read(path) {
27
+ return this._state.read(path);
28
+ }
29
+ remove(path) {
30
+ this._state.remove(path);
31
+ }
32
+ commit() {
33
+ if (this._commiting) {
34
+ throw new Error(`Can not "kernel.commit()" within commit`);
35
+ }
36
+ this._commiting = true;
37
+ this._before.dispatch();
38
+ for (const buffer of this._buffers) {
39
+ buffer.commit(this._state);
40
+ }
41
+ this._after.dispatch();
42
+ this._commiting = false;
43
+ }
44
+ }
@@ -0,0 +1,5 @@
1
+ export declare class Signal<T> {
2
+ private _subscribers;
3
+ subscribe(site: (payload: T) => void): () => void;
4
+ dispatch(payload: T): void;
5
+ }
@@ -0,0 +1,12 @@
1
+ export class Signal {
2
+ _subscribers = new Set();
3
+ subscribe(site) {
4
+ this._subscribers.add(site);
5
+ return () => this._subscribers.delete(site);
6
+ }
7
+ dispatch(payload) {
8
+ for (const subscriber of this._subscribers) {
9
+ subscriber(payload);
10
+ }
11
+ }
12
+ }
@@ -0,0 +1,15 @@
1
+ import { Backref, Is, Link, Local, Ref } from "./abstracts/operators.js";
2
+ type Mapping = Record<string, any>;
3
+ declare function ref<T extends Mapping, K extends keyof T>(path: K): Ref<T, K>;
4
+ declare function backref<T extends Mapping, K extends keyof T>(path: K): Backref<T, K>;
5
+ declare function local<T>(value: T): Local<T>;
6
+ declare function link<V extends Mapping>(source: V): Link<V>;
7
+ declare function is(factory: string): Is;
8
+ declare const _default: {
9
+ ref: typeof ref;
10
+ backref: typeof backref;
11
+ link: typeof link;
12
+ local: typeof local;
13
+ is: typeof is;
14
+ };
15
+ export default _default;
@@ -0,0 +1,31 @@
1
+ function ref(path) {
2
+ return {
3
+ type: 'ref',
4
+ path
5
+ };
6
+ }
7
+ function backref(path) {
8
+ return {
9
+ type: 'backref',
10
+ path
11
+ };
12
+ }
13
+ function local(value) {
14
+ return {
15
+ type: 'local',
16
+ value
17
+ };
18
+ }
19
+ function link(source) {
20
+ return {
21
+ type: 'link',
22
+ source
23
+ };
24
+ }
25
+ function is(factory) {
26
+ return {
27
+ type: 'is',
28
+ factory
29
+ };
30
+ }
31
+ export default { ref, backref, link, local, is };
@@ -0,0 +1,9 @@
1
+ import { AbstractState } from "./abstracts/state.js";
2
+ type Mapping = Record<string, any>;
3
+ export declare class State<T extends Mapping = Mapping> implements AbstractState<T> {
4
+ private _state;
5
+ write<K extends keyof T>(path: K, value: T[K]): void;
6
+ read<K extends keyof T>(path: K): T[K];
7
+ remove<K extends keyof T>(path: K): void;
8
+ }
9
+ export {};
@@ -0,0 +1,12 @@
1
+ export class State {
2
+ _state = new Map();
3
+ write(path, value) {
4
+ this._state.set(path, value);
5
+ }
6
+ read(path) {
7
+ return this._state.get(path);
8
+ }
9
+ remove(path) {
10
+ this._state.delete(path);
11
+ }
12
+ }
@@ -0,0 +1,27 @@
1
+ import { Meta } from "./abstracts/meta.js";
2
+ import { AbstractState } from "./abstracts/state.js";
3
+ import { View } from "./abstracts/view.js";
4
+ import { Factories } from "./factories/factories.js";
5
+ import { Buffer } from "./kernel/buffer.js";
6
+ import { Variable } from "./variable.js";
7
+ type Mapping = Record<string, any>;
8
+ type Options = {
9
+ strategy: (site: () => void) => void;
10
+ };
11
+ export declare class Stillflow<T extends Mapping = Mapping> {
12
+ private _state;
13
+ private _options;
14
+ private _views;
15
+ private _kernel;
16
+ private _batcher;
17
+ constructor(_state: AbstractState<T>, _options?: Options);
18
+ on(site: () => void): () => void;
19
+ factory(): Factories;
20
+ buffer(): Buffer<T>;
21
+ bind(buffer: Buffer<T>): void;
22
+ compile<V extends Mapping>(source: V): View<V, T>;
23
+ instantiate<V extends Meta>(source: V, factory: Factories): V;
24
+ commit(): void;
25
+ variable<K extends keyof T>(path: K): Variable<T, K>;
26
+ }
27
+ export {};