Changelog
3.1.6 - 2023-12-19
Changelog
3.1.5 - 2023-03-16
Changelog
3.1.4 - 2023-01-16
logic.findMounted(123)
and logic.isMounted('string key')
.logic.find(keyOrProps?)
, which throws if the logic is not mounted.Changelog
3.1.3 - 2023-01-16
KeaLogicType
type builder (experimental only in 3.1.x).Changelog
3.1.1 - 2022-12-13
asyncActions
:const logic = kea([
actions({
fetchUser: (id: number) => ({ id }),
}),
listeners({
fetchUser: async ({ id }, breakpoint) => {
await breakpoint(100)
const user = await fetch(`https://example.com/users/${id}`)
breakpoint()
return user
},
}),
])
const user = await logic.actions.fetchUser(1)
The promise returns whatever is returned in the first listener that listens to this action. Ususally that's the output of the only listener is the same logic that creates the action.
In case you use breakpoints, and the action is called multiple times, all the promises will resolve when the last called action returns.
That means in the case of
const promise1 = logic.actions.fetchUser(1)
const promise2 = logic.actions.fetchUser(1)
Both promises will resolve at the same time. The first dispatch one that breaks will resolve when the second one finishes.
To make this work, each created action now also comes with an ever-increasing dispatchId
:
logic.actionCreators.fetchUser(123) ===
{
type: 'fetch user (logic)',
payload: { id: 123 },
dispatchId: 1,
}
To disable setting dispatchId
and hence support for async actions, call resetContext({ disableAsyncActions: true })
.
Changelog
3.1.0 - 2022-12-13
logic.props
mutable, and store props input immutably in logic.lastProps
. This fixes a bug:const propValues = []
const logic = kea([
actions({ doStuff: true }),
listeners(({ props }) => ({
doStuff: () => {
propValues.push(props.value)
},
})),
])
logic({ value: 0 }).mount()
logic({ value: 1 }).actions.doStuff()
logic({ value: 2 }).actions.doStuff()
Previously propValues
would contain [0, 0]
, but now it contains [1, 2]
.
Changelog
3.0.4 - 2022-10-01
p.id
is a shorthand for (_, props) => props.id
. For example:const logic = kea([
props({} as { id: number }),
selectors({
duckAndChicken: [(s, p) => [s.duckId, s.chickenId, p.id], (duckId, chickenId, id) => duckId + chickenId + id],
}),
])
Changelog
3.0.2 - 2022-06-19
window
from hooks.ts