Skip to content

Releases: yezyilomo/state-pool

v0.10.1

02 Feb 08:50
d4f392e
Compare
Choose a tag to compare

v0.10.0

02 May 17:27
63c6546
Compare
Choose a tag to compare

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 including State.js, Store.js, useReducer.js and useState.js #164

Fixes 🐛

  • Immer updating to 10.x version throwing errors #178

v0.9.0

25 Dec 11:10
e891018
Compare
Choose a tag to compare

New Features

Fixes

  • Remove store subscription after removing a global state from a store [Commit Ref]

0.8.1

05 Nov 21:32
a089318
Compare
Choose a tag to compare

Fixes

v0.8.0

29 Oct 18:31
b8d0ef2
Compare
Choose a tag to compare

v0.7.1

06 Feb 00:30
7c164bd
Compare
Choose a tag to compare

Fixes

v0.7.0

04 Feb 23:14
9f7745e
Compare
Choose a tag to compare

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 and useReducer into a store, this allows us to consume our state with store.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 from state-pool, we need to import createStore instead.
  • We can no longer pass a key parameter, persist and default configurations in useGlobalState and useGlobalStateReducer hooks, The key parameter, persist and default configurations are now accepted by store.useState and store.useReducer
  • store.LOCAL_STORAGE_UPDATE_DEBOUNCE_TIME is no longer used, since we have empowered users to implement state persistence by themselves
  • useLocalState is removed, since our focus is on managing global state

v0.6.0

25 Jul 10:45
2c1a889
Compare
Choose a tag to compare

New Feature

  • Typescript support

v0.5.0

07 Jul 14:48
326e743
Compare
Choose a tag to compare

Changes

  • Removed useGlobal and useGlobalReducer
  • Allow passing both key and global state object on useGlobalState and useGlobalStateReducer
  • Run useEffect in useGlobalStateReducer only on mounting and unmounting components(Simply subscribe when mounting and unsubscribe when unmounting)

v0.4.1

20 Jun 10:44
c79a579
Compare
Choose a tag to compare

Fixes

  • Move react to peerDependencies