Releases: yezyilomo/state-pool
Releases · yezyilomo/state-pool
v0.10.1
v0.10.0
Intro
Hello everyone!,
We are excited🎉 to announce that our library is getting very close to a stable API and we will soon be releasing version 1.0. We have been working hard to introduce new features that we believe will improve your experience with the library. However, before we can release version 1.0, we need to thoroughly test these features(in this release) to ensure that they meet our quality standards.
We encourage all of our users to help us with testing these new features by trying them out and reporting any issues or bugs you encounter. Your feedback is valuable to us and will help us ensure that the final release is as stable and reliable as possible.
New Features ✨
- Simplify low level API #162
- Add a way to initialize state lazily #163
- Implement local state management #165
- Double down on types(Make the lib strongly typed) #166
- Return state object reference in
useState
&useReducer
hooks #177 - Add a way to check if a state is available in a store before accessing it #167
- Add a way to initialize store in instantiation #168
- Add a way to iterate over state in a store #160
- Add a method to get state value directly from a store #161
- Add default export in
index.js
and some files includingState.js
,Store.js
,useReducer.js
anduseState.js
#164
Fixes 🐛
- Immer updating to 10.x version throwing errors #178
v0.9.0
New Features
- Add
globalState.select
API [Commit Ref] - Remove
globalState.persist
unofficial internal API [Commit Ref] - Keep the private part of the API private [Commit Ref]
Fixes
- Remove store subscription after removing a global state from a store [Commit Ref]
0.8.1
v0.8.0
v0.7.1
v0.7.0
New Features
-
Added the ability to create a store
import {createStore} from 'state-pool'; const store = createStore(); // You can create as many stores as you want
-
Integrated
useState
anduseReducer
into a store, this allows us to consume our state withstore.useState
&store.useReducer
-
Introduced a generic API for implementing state persistence in any storage
store.persist({ saveState: function(key, value, isInitialSet){/*your code to save state */}, loadState: function(key){/*your code to load state */}, removeState: function(key){/*your code to remove state */}, clear: function(){/*your code to clear storage */} })
-
Introduced state typing
store.setState<T>(key, initialVal) store.useState<T>(key) store.useReducer<T>(reducer, key) createGlobalState<T>(initialVal) useGlobalState<T>(globalState) useGlobalStateReducer<T>(reducer, globalState)
-
Managing state outside react component(reading and writing state outside react component)
// Reading state outside of React component store.getState(key).getValue() // Reading value of a global state from a store globalState.getValue() // Reading value of a global state // Listening to store changes const unsubscribe = store.subscribe(function(key: String, value: Any){ // key is the key for a global state that has changed // value is the new value of a global state }) // You can unsubscribe by calling the result unsubscribe(); //If you want to listen to a single global state in a store you can use const unsubscribe = store.getState(key).subscribe(function(value){ // value is the new value of a global state }) // For a plain global state const unsubscribe = globalState.subscribe(function(value){ // value is the new value of a global state }) // You can unsubscribe by calling the result unsubscribe(); // Writing to a global state in a store store.getState(key).updateValue(value => { // Do your updates here e.g value.name = "Yezy" }) // Writing to a plain global state globalState.updateValue(value => { // Do your updates here e.g value.name = "Yezy" })
Breaking Changes
- We can no longer import a
store
fromstate-pool
, we need to importcreateStore
instead. - We can no longer pass a key parameter, persist and default configurations in
useGlobalState
anduseGlobalStateReducer
hooks, The key parameter, persist and default configurations are now accepted bystore.useState
andstore.useReducer
store.LOCAL_STORAGE_UPDATE_DEBOUNCE_TIME
is no longer used, since we have empowered users to implement state persistence by themselvesuseLocalState
is removed, since our focus is on managing global state
v0.6.0
v0.5.0
Changes
- Removed
useGlobal
anduseGlobalReducer
- Allow passing both key and global state object on
useGlobalState
anduseGlobalStateReducer
- Run
useEffect
inuseGlobalStateReducer
only on mounting and unmounting components(Simply subscribe when mounting and unsubscribe when unmounting)