stillflow.engine 0.1.0 → 0.1.2
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 +30 -30
- package/dist/stillflow-adapters/dom/base.dom.d.ts +14 -0
- package/dist/stillflow-adapters/dom/base.dom.js +20 -0
- package/dist/stillflow-adapters/dom/compiler/compile.d.ts +1 -1
- package/dist/stillflow-adapters/dom/compiler/transform.d.ts +1 -1
- package/dist/stillflow-adapters/dom/description/describe.d.ts +1 -1
- package/dist/stillflow-adapters/dom/jsx.dom.d.ts +1 -1
- package/dist/stillflow-adapters/dom/properties/modifiers.d.ts +1 -1
- package/dist/stillflow-adapters/dom/types.d.ts +4 -0
- package/dist/stillflow-adapters/dom/types.js +1 -0
- package/dist/stillflow-adapters/index.d.ts +1 -1
- package/dist/stillflow-adapters/index.js +1 -1
- package/dist/stillflow-examples/app.js +2 -2
- package/dist/stillflow-examples/test.js +2 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@ I built **Stillflow** to solve my own architectural problems. I wanted explicit
|
|
|
8
8
|
|
|
9
9
|
> UI = State + Projections + Bindings + Feedback loop.
|
|
10
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**
|
|
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** an inverse function of `f`, because we cannot restore *state* from `UI` fully in the most cases, because **UI is a subset of state**.
|
|
12
12
|
|
|
13
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
14
|
|
|
@@ -24,29 +24,29 @@ Also I think that **explicit reactivity is better than implicit reactivity**. So
|
|
|
24
24
|
|
|
25
25
|
## Benchmarks
|
|
26
26
|
|
|
27
|
-
**Stillflow** performs within *1% of VanillaJS* in the Krause benchmark on my notepad
|
|
27
|
+
**Stillflow** performs within *1% of VanillaJS* in the Krause benchmark on my notepad, while providing a full transactional state model.
|
|
28
28
|

|
|
29
29
|
|
|
30
30
|
## Quick Start
|
|
31
31
|
|
|
32
32
|
### Let's make some simple Todo application
|
|
33
33
|
```ts
|
|
34
|
-
import { Stillflow, State, FenwickCollection, FlushableCollection, operators, adapters } from 'stillflow'
|
|
34
|
+
import { Stillflow, State, FenwickCollection, FlushableCollection, operators, adapters } from 'stillflow.engine'
|
|
35
35
|
|
|
36
36
|
type AppState = {
|
|
37
|
-
|
|
37
|
+
input: string
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
type TodoItem = {
|
|
41
|
-
|
|
41
|
+
label: string
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
type TodoState = {
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
input: string,
|
|
46
|
+
items: FlushableCollection<TodoItem>
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
const { jsxdom,
|
|
49
|
+
const { jsxdom, dom } = adapters
|
|
50
50
|
|
|
51
51
|
const state = new State()
|
|
52
52
|
const stillflow = new Stillflow<AppState>(state)
|
|
@@ -55,45 +55,45 @@ const factory = stillflow.factory()
|
|
|
55
55
|
factory.add(FlushableCollection.name, () => new FlushableCollection(new FenwickCollection(100)))
|
|
56
56
|
|
|
57
57
|
const source = {
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
input: stillflow.variable('input').backref(),
|
|
59
|
+
items: operators.is(FlushableCollection.name)
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
const view = stillflow.compile(source)
|
|
63
63
|
const instance: TodoState = stillflow.instantiate(view, factory)
|
|
64
64
|
|
|
65
65
|
function change(event: any) {
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
instance.input = event.target.value
|
|
67
|
+
stillflow.commit()
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
function add() {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
71
|
+
instance.items.add({ label: instance.input })
|
|
72
|
+
instance.input = String()
|
|
73
|
+
stillflow.commit()
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
function TodoItem() {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
77
|
+
return (
|
|
78
|
+
<jsxdom.div>
|
|
79
|
+
{(context: TodoItem) => context.label}
|
|
80
|
+
</jsxdom.div>
|
|
81
|
+
)
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
function App() {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
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
94
|
}
|
|
95
95
|
|
|
96
|
-
const { element: app, update } =
|
|
96
|
+
const { element: app, update } = dom.$(<App />)
|
|
97
97
|
|
|
98
98
|
stillflow.on(() => update(instance))
|
|
99
99
|
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { AnyDOM } from "./types.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
|
+
$: <V>(root: AnyDOM<V>) => {
|
|
9
|
+
element: HTMLElement;
|
|
10
|
+
update: (context: V) => void;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
export declare const DOM_REGISTRY: DOMRegistry;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
DOM_REGISTRY.$ = function $(root) {
|
|
8
|
+
const element = transform(root);
|
|
9
|
+
const compiler = new Compiler();
|
|
10
|
+
const compilation = compiler.compile(root);
|
|
11
|
+
const appliers = new Appliers();
|
|
12
|
+
const applier = appliers.apply(compilation);
|
|
13
|
+
const update = (context) => applier(element, context);
|
|
14
|
+
return { element, update };
|
|
15
|
+
};
|
|
16
|
+
for (const tag of HTML_TAGS) {
|
|
17
|
+
DOM_REGISTRY[tag] = (properties, children = []) => {
|
|
18
|
+
return describe({ ...properties, name: tag }, children);
|
|
19
|
+
};
|
|
20
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { DOM } from "../
|
|
1
|
+
import { DOM } from "../types.js";
|
|
2
2
|
export declare function transform<V, K extends keyof HTMLElementTagNameMap>(description: DOM<V, K>): HTMLElementTagNameMap[K];
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { AnyDOM } from "../
|
|
1
|
+
import { AnyDOM } from "../types.js";
|
|
2
2
|
import { Properties } from "../properties/properties.js";
|
|
3
3
|
export declare function describe<V, K extends keyof HTMLElementTagNameMap>(properties: Properties<V, K>, children: AnyDOM<V>[]): AnyDOM<V>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FlushableCollection } from "../../../index.js";
|
|
2
|
-
import { AnyDOM } from "../
|
|
2
|
+
import { AnyDOM } from "../types.js";
|
|
3
3
|
export type Modifiers<Context, K extends keyof HTMLElementTagNameMap = any> = Partial<{
|
|
4
4
|
text: (context: Context) => string;
|
|
5
5
|
lens: <Another>(context: Context) => Another;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Stillflow, State, Batcher, operators, adapters, FlushableCollection, FenwickCollection } from "../index.js";
|
|
2
2
|
import { buildData } from "./data.js";
|
|
3
|
-
const { jsxdom,
|
|
3
|
+
const { jsxdom, dom } = adapters;
|
|
4
4
|
class BenchmarkApplicationController {
|
|
5
5
|
_stillflow = new Stillflow(new State(), { strategy: site => requestAnimationFrame(site) });
|
|
6
6
|
_clearing = new Batcher(site => requestIdleCallback(site));
|
|
@@ -134,7 +134,7 @@ function BenchmarkApplicationView(context) {
|
|
|
134
134
|
adapters.jsx(jsxdom.span, { ariaHidden: "true", className: "preloadicon glyphicon glyphicon-remove" })));
|
|
135
135
|
}
|
|
136
136
|
const controller = new BenchmarkApplicationController();
|
|
137
|
-
const { element, update } =
|
|
137
|
+
const { element, update } = dom.$(adapters.jsx(BenchmarkApplicationView, { controller: controller }));
|
|
138
138
|
controller.core.on(() => update({}));
|
|
139
139
|
document.body.appendChild(element);
|
|
140
140
|
update({});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Stillflow, State, FenwickCollection, FlushableCollection, operators, adapters } from '../index.js';
|
|
2
|
-
const { jsxdom,
|
|
2
|
+
const { jsxdom, dom } = adapters;
|
|
3
3
|
const state = new State();
|
|
4
4
|
const stillflow = new Stillflow(state);
|
|
5
5
|
const factory = stillflow.factory();
|
|
@@ -28,7 +28,7 @@ function App() {
|
|
|
28
28
|
adapters.jsx(jsxdom.button, { "on:click": add }, "Add"),
|
|
29
29
|
adapters.jsx(jsxdom.div, { "sf:for": (context) => context.items, "sf:each": () => adapters.jsx(TodoItem, null) })));
|
|
30
30
|
}
|
|
31
|
-
const { element: app, update } =
|
|
31
|
+
const { element: app, update } = dom.$(adapters.jsx(App, null));
|
|
32
32
|
stillflow.on(() => update(instance));
|
|
33
33
|
instance.input = String();
|
|
34
34
|
document.body.appendChild(app);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "stillflow.engine",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "A headless, transaction-based UI engine with AOT compilation.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -37,4 +37,4 @@
|
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"typescript": "^5.0.0"
|
|
39
39
|
}
|
|
40
|
-
}
|
|
40
|
+
}
|