Repository navigation
fiorejs 2 gives every tag an immutable builder, renames the data object keys to attrs and on, rewrites live children to keep their place between comment markers, and replaces the plugin hook with a live-value protocol. It is a major release: check "Breaking changes" and the upgrade table before upgrading. @fiorejs/signals 2.0.0 and @fiorejs/jsx 2.0.0 follow this release and require it.
Breaking changes
- Data object keys:
attributesis nowattrs, andeventis nowon. element(name, data)is nowelement(name)(data):element(name)returns the tag function for any name.- Plugins are removed, and so is
use(). A value is live when it has a method underSymbol.for('fiorejs.live'), exported asLIVE; fiorejs callsvalue[LIVE](apply, context)for props, attributes and children. Signals from@fiorejs/signals2.0.0 carry this method. - A plain function is never a live value. In props, attributes, children and JSX alike, a function is a callback or plain content. Derived values are written with
computedfrom@fiorejs/signals. - Live children sit between two empty comments when they have siblings, so the comments show in
childNodesandinnerHTML(not inchildren,textContentor CSS selectors). A live child that is the only child of its element fills the element without comments. - Children arrays are flattened at any depth, so
[title, items.map(row)]works. Earlier versions flattened one level. - A plain object that carries
[LIVE]is live, also as the only argument of a tag.
Added
- Builders: every tag has
props(map),attrs(map),on(map),with(modifier),also(fn)andcreate(children). Builders never change, so a builder is a reusable template.propsandattrscombine across calls (later keys win);onadds listeners. HTMLModifierandSVGModifiertype a reusable modifier that works on every tag of its namespace and keeps the tag's element type.LIVE, and theLiveValue,LiveandBindContexttypes, for writing your own live values.- A live value under an inline handler prop binds, so
props: { onclick: handlerSignal }swaps the handler. Inline handler attributes such asonclickare still never set.
Improved
- Live children keep their nodes between two markers and read the DOM between them on every update, instead of tracking their nodes in a separate list. Updates keep working after
Node.normalize(), after browser page translation replaces a text node, and for a live child inside a fragment that becomes another live child's value. A list update steps over unchanged rows at both ends and moves only the rows that are out of order, withmoveBeforewhere the browser has it. Measured in Chrome 157 with the published packages (fiorejs and@fiorejs/signals, 1.2.0 and 1.0.0 against 2.0.0): creating 10,000 rows with a live text child is about 1.6 times faster, appending one row to a 10,000-row list takes about 2.0 ms instead of 3.2 ms, and updating 10,000 live texts is 10 to 20% faster. The first render of a 10,000-row list and replacing all of its rows are about 20% slower (about 1 to 2 ms). - A cyclic children array renders its other items instead of running out of memory, and very deep arrays do not overflow the stack.
- Types:
Childrenaccepts nested arrays and live values among siblings, and the deprecated MathMLais typed without a cast.
Upgrading from 1.x
| 1.x | 2.0 |
|---|---|
div({ attributes: { … } }) |
div({ attrs: { … } }) or div.attrs({ … }).create() |
div({ event: { click } }) |
div({ on: { click } }) or div.on({ click }).create() |
element('div', data) |
element('div')(data) |
use(plugin) |
a [LIVE] method on the value |
div(() => count.get() * 2) |
div(count.computed((n) => n * 2)) with @fiorejs/signals 2.0.0 |
The README's "Upgrading from 1.x" section has the details, and the documentation site describes the 2.0 API.