Releases: thomashoneyman/purescript-halogen-hooks
v0.3.0
This release changes how users update state in Hooks.
Breaking changes (😱!!!):
Replace state tokens with a modify function (#29)
The previous versions of Hooks returned a state token from the useState
hook, which could then be passed to the put
, modify
, modify_
, and get
functions we're all used to from HalogenM. Now, the useState
hook returns a modify function directly which can be used to update the state. See #29 for more details on why this matters.
This code from v0.2.1:
state /\ stateToken <- Hooks.useState 0
let handleClick = Hooks.modify_ stateToken (_ + 1)
Hooks.pure ...
Would now be written like this:
state /\ modifyState <- Hooks.useState 0
let handleClick = modifyState (_ + 1)
Hooks.pure ...
Now that there isn't a get
function, if you need to get the most up-to-date state in an asynchronous function, you should copy the relevant part of state to a mutable reference so the function can read the reference during its execution. This is the same pattern you should use if you need to do the same with component input. #29 also introduces a useGet
example Hook which makes this easy and convenient.
v0.2.1
This release improves the performance of the Hooks library, both internally and by introducing a new memoComponent
function.
Improvements:
Add memoComponent
to control evaluation on input changes (#25)
When a Halogen component re-renders it sends input again to any of its child components. When a Hook component receives new input it will store that input and re-evaluate all Hooks. This can be a performance issue if a Hook function (especially an expensive one) is run unnecessarily each time the parent component renders.
This PR introduces memoComponent
, a version of the component function which allows Hook components to ignore new input if it is unchanged from previous input.
Only re-evaluate Hooks after effects run if the effects modified state (#28)
Hooks were previously always re-evaluated if effects were run after the last evaluation, because it was possible that the effects modified something that could have triggered a useTickEffect
's memos. However, even when the effects didn't modify state we'd still re-run Hooks. This performance optimization tracks whether the state was modified after a particular effects run and only re-evaluates Hooks if the state was actually modified.
v0.2.0
This release fixes several bugs and changes some types used in the Halogen Hooks library.
Breaking changes (😱!!!):
Introduce tokens for all component-only features, not just queries (#22)
Hooks support writing functions for stateful logic, which are then interpreted by a Halogen component. However, some component features do not make sense in the context of Hooks alone (queries, slot types, and output messages).
The first version of Hooks made queries available in a Hook only via a query 'token', which was provided by the componentWithQuery
function. This approach has been extended to slot types and output messages as well. With this change Hook types no longer carry around slot or output types, which cleans up type signatures for the vast majority of cases, but they are still able to support child components and sending messages once used with the component
function.
This includes several breaking changes, all of which are simple to adjust to the new version (no features have been removed). In summary, any Hook types that previously accepted a slot and output type will no longer have them, and any Hook functions that use these types will now use a token as their first argument. Here's the full list of changes:
Hook ps o m hooks a
is nowHook m hooks a
Hooked ps o m hooksPre hooksPost a
is nowHooked m hooksPre hooksPost a
HookM ps o m a
is nowHookM m a
- The
component
function has been updated to take as its first argument a record containing the query token, slot token, and output token that can be used to enable component features in a Hook. Any usage ofcomponent \input -> ...
can be replaced withcomponent \_ input -> ...
. - The
componentWithQuery
function has been removed, as it is now covered bycomponent
. Any usage ofcomponentWithQuery \queryToken _ -> ...
can be replaced bycomponent \{ queryToken } _ -> ...
. - The
HookM
functionraise
now takes as its first argument anOutputToken
. Any use ofHooks.raise output
can be replaced bycomponent \{ outputToken } _ -> ... Hooks.raise outputToken output
. - The
HookM
functionsquery
andqueryAll
now take as their first argument aSlotToken
. Any use ofHooks.query ...
can be replaced bycomponent \{ slotToken } _ -> ... Hooks.query slotToken ...
.
Bugfixes:
- Memo values could get out of sync with their indices in state (#11)
- Effect cleanup for useTickEffect would not run until the component finalized, running all cleanup functions together at the end (#12)
- State changes triggered by effects would not cause hooks to be re-evaluated (#20)
Other improvements:
- Tests: add automated tests for Hooks (#19)
- Tests: add continuous integration to the repository via GitHub Actions
- Docs: update the documentation to make it clear when getting state vs. using the state from
useState
is necessary (#7) - Docs: update all public documentation to use new types and remove mention of
componentWithQuery
v0.1.0
Initial release of the Halogen Hooks library.