Releases: tivac/xstate-component-tree
v5.0.1
v5.0.0
Major Changes
-
#69
b6c9fc8Thanks @tivac! - Always provide a valid initial value to subscribersPreviously if you called the
.subscribe()method on aComponentTreeinstance before the statechart had been processed the return value would befalse. This meant that subscribers would have to add checks to do anything against the returned value, since they couldn't depend on the.matches/.hasTag/.broadcastAPIs existing.This change fixes that, and ensures that even if the statechart hasn't been walked yet the initial value stored has all the expected APIs, along with a reasonable value for the
treeproperty of[]. There isn't a great fallback value for.stateat this time though.
v4.2.0
Minor Changes
-
#67
a8aa4acThanks @tivac! - Added.send()APIThe
.send()API is a simple passthrough to the interpreter for the root statechart being managed byxstate-component-tree, and is intended as a convenience function to make it easier to interact with aComponentTreeinstance instead of a direct XStateInterpreterreference.
v4.1.1
v4.1.0
Minor Changes
-
#63
d9d3820Thanks @tivac! - Added observable APIAvailable on the
ComponentTreeinstance as.subscribe(callback), calls the callback function immediately with the most recent result and then will re-call it each time a build completes.Follows the svelte store contract which isn't strictly compliant with any official observable APIs but is extremely simple and usable.
The
callbackpassed to.subscribe(...)will immediately be called with the most recent result of building the component tree (orfalseif it hasn't finished yet), and then for each complete tree building run after that thecallbackwill be called with a single argument. The arg is anObjectwith anullprototype and the following properties:tree, nested component structures. This is the same as the first argument to the oldernew ComponentTree(service, callback)API.state, an XStateStateinstance representing the most recent state of the root statechart.matches(<state>),state.matches()but for every statechart instance including any invoked statecharts.hasTag(<tag>),state.hasTag()but for every statechart instance including any invoked statecharts.broadcast(<event>),service.send()but for every statechart instance including any invoked statecharts. Prefer using this instead of settinginvoke.autoForwardbecause it'll reduce the amount of junk events sent to invoked children.
All notable changes to this project will be documented in this file. See standard-version for commit guidelines.
v4.0.0
4.0.0 (2022-03-16)
⚠ BREAKING CHANGES
- previously the second arg to the callback function had a single
dataproperty on it representing the lastStateobject seen by the top-level machine. Now it hasstate(same as data was previously), and some bound APIs for interacting with the statechart:.hasTag(),.broadcast(), and.matches(). These are the same APIs available on theComponentTreeinstance but made available through the callback args for convenience.
Features
v3.5.0
3.5.0 (2022-03-15)
Features
Feature Explanations
.broadcast(), to send an event to all of the machines, allowing you to not useautoforward.hasTag()calls the built-in xstate.hasTag()API against all the cached state objects (stopping at the first successful one).matches()calls the built-in xstate.matches()API against all the cached state objects (stopping at the first successful one)
NOTE: Not a breaking change because the public API didn't meaningfully shift, but the internals of xstate-component-tree have been significantly changed in this release. Instead of invoking a new ComponentTree class for every child machine it now tracks them all without any need for recursion or new class instances. Should be a bit lighter at run-time as a result.