Closed ryardley closed 4 years ago
Workshopping the syntax a bit more @dmicic what do you think about this? I am starting to think configuring via options makes more sense as it enables us to mimic the React API:
import {useBusReducer} from 'ts-bus/react';
// The output shares the exact signature of the React equivalent
// This would be a breaking change
const state = useBusReducer(reducer, initState, init);
import {useBusReducer} from 'ts-bus/react';
// Create a configured useReducer function
const useReducer = useBusReducer.configure({subscriber, useReducer});
// The output shares the exact signature of the React equivalent but with the configuration applied
const state = useReducer(reducer, initState, init);
This would also be applicable to the useBusState
PR: https://github.com/ryardley/ts-bus/pull/28 and should be considered before merging that PR.
@ryardley In general, I like the the option based configuration idea. I would have to get my hands on reinspect to provide a constructive comment. But some random thoughts... At first glance, the integration could work nicely. The event name can be used for the "id" parameter required by reinspect. The only issue I see if you have multiple subscribers per event. In that case, the react devTools would probably dump the message 1*n-subscribers time. It would be useful to display to which component/subscriber the state belongs to.
I've actually started aligning useBusState to react's useState. (However, still struggeling to extract the event name from the type in order to avoid the additional parameter #28)
Currently we cannot tool useBusReducer with https://github.com/troch/reinspect because it automatically uses the React peer dependency.
Thinking syntax might be able to be something like this: