shelterjs
A simple data state container for js projects.
Why?
I like data container and state management in my js projects but redux and other libraries are so much complex than they have to.
Instead create actions, reducers, containers, merge containers, handle async actions with middlewares and import a lot of libs to use with our favorite frontend framework, I just like to use some like this:
Component { superprops myContainermyProp } { //,,,, }
When I want to change data on my container, I like to use in this way:
myContainermyProp
And thats it!
All observers now will receive the new prop value.
Install
In terminal, just run: npm install shelterjs
Usage
Configuring the container:
// import the library // instance new container (yes, you can have more than one =])const myContainer = // define your properties with their initial values. props: myProp1: 'initial value'
Observing container changes for a single prop:
myContainermyProp1 // you can also take a previous valuemyContainermyProp1
Get value without observing:
const myValue = myContainermyProp1
Dispose observers:
const myObserverInstance = myContainermyProp1 // when you want to remove the observer, just call:myObserverInstance
Remove all observers from prop:
myContainermyProp1
Change value in container
myContainermyProp1
Creating properties at runtime
If you want to add new properties to a existing container, use the createProperty
function:
myContainer console // initial value