Smalldux
A small implementation of react-redux
using the Context API
.
The API is almost the same.
NOTE: To use this library, make sure react
and react-dom
versions are
equal or above 16.3.0
. It will NOT work on below versions of react
.
It is important to note that I've built this lib with learning/practicing purposes in mind only, so please don't use this in production! Use the official Redux or another battle-tasted flux to react inplementation!!!
Installation
yarn add smalldux
or
npm install smalldux
Usage
Define your reducers
:
const initialState = current: 'red' { } const reducers =
Then create your store
:
const store =
Append the brand new store
to a Provider
:
Component { return <Provider store=store> <ShowColor /> <UpdateColor /> </Provider> }
You're all set! Now it's time to write some components! I'll show a basic publish-subscriber example:
ShowColor.js
as our subscriber
PureComponent { return <div> Current color: thispropscolorcurrent </div> } color: statecolorShowColor
UpdateColor.js
as our publisher
PureComponent { superprops thishandleTextChange = thishandleTextChange } { thisprops } { return <p> Type your favorite color: ' ' <input type="text" onChange=thishandleTextChange /> </p> } nullUpdateColor
Surely the publisher can also be a subscriber and vice-versa. Purely examples!
TODO
mapDispatchToProps
combineReducers
that actually combine all reducers into one- initial state
middlewares
implementation
Feel free to open issues and submit PRs if you like to! Primarily I made this little project on practicing purposes, but who knows? :)