Add default behavior to contextFn at createMachine
wuarmin opened this issue · comments
Armin commented
Hey,
great lib! Thanks. What do you think about a default implementation of contextFn
at createMachine
?
If somebody uses react-robot and calls useMachine(flow, { foo: "bar"})
, but has no contextFn
prepared, the result is an empty initial context.
BR
Matthew Phillips commented
This is intentional, a machine gets to decide what is in its context. It does this by accepting or rejecting context passed in when interpreted. If you feel like you want your machines to always accept a passed in object as its context you can easily do that with a little functional programming.
import { createMachine as defaultCreateMachine } from 'robot3';
export const createMachine = (states, context = {}) => defaultCreateMachine(states, () => context);