Skip to content

2.0.0

Latest

Choose a tag to compare

@vrtexe vrtexe released this 16 Nov 16:08
· 1 commit to main since this release

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: attributes is now attrs, and event is now on.
  • element(name, data) is now element(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 under Symbol.for('fiorejs.live'), exported as LIVE; fiorejs calls value[LIVE](apply, context) for props, attributes and children. Signals from @fiorejs/signals 2.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 computed from @fiorejs/signals.
  • Live children sit between two empty comments when they have siblings, so the comments show in childNodes and innerHTML (not in children, textContent or 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) and create(children). Builders never change, so a builder is a reusable template. props and attrs combine across calls (later keys win); on adds listeners.
  • HTMLModifier and SVGModifier type a reusable modifier that works on every tag of its namespace and keeps the tag's element type.
  • LIVE, and the LiveValue, Live and BindContext types, 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 as onclick are 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, with moveBefore where 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: Children accepts nested arrays and live values among siblings, and the deprecated MathML a is 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.