- s2(object, template);
- Returns [proxy, documentFragment]
, a reactive view model and a fragment containing its elements.
+ function s2<T>(d: T, t: Element): [T, Node];
Addendum
Rationale
-s² enables developers to implement complex UI as data models, like a retained mode for the web. In more technical terms, s² is a single function that proxies mutable data to reflect in the DOM. s² has a few design goals:
+s² is a bit like Mustache, but reactive. I built it because I wanted to bind mutable data to the DOM efficiently without Turing-completeness at the template level. Complex UIs are mostly about managing state, and s² has a very data-centric approach, versus component-centric. A few design goals:
-
-
- Enable separation of application logic from the presentation layer. For example, unlike React which combines hooks, templates (JSX), and arbitrary code in a render function, s² has data, functions that operate on the data, and declarative templates. -
- The entire API is built on top of its main function, which handles rendering and event listening. Advanced features such as computed properties are implemented as addons. -
- Templates are logic-less. This differs from prior art such as JSX where embedded JavaScript is allowed. Due to this constraint, logic-less templating maps well to s², and there is an addon for Mustache templates that is aware of HTML context. +
- Separation of application logic from the presentation layer. Unlike React which combines hooks, templates (JSX), and arbitrary code in a render function, s² has data, functions that operate on the data, and declarative templates. +
- The entire API is built on top of its main function, which handles rendering and event listening. Advanced features such as computed properties are implemented as modular addons. +
- Templates are logic-less, embedded JavaScript is not allowed. Due to this constraint, logic-less templating maps well to s², and there is an addon for Mustache templates that is aware of HTML context.
Here is a sample to-do app built with s²:
@@ -268,13 +290,13 @@