createAppState function

When using the createAppState function, you must pass two parameters:

  1. store key (for example - keys must be unique and are used to retrieve stores later
  2. an object that defines the properties of the store

The following properties are used when creating stores:

initialStateobjectThe initial state of the store
persiststring or objectIf persistence is required (between reloads), provide a unique namespace string for saving the store to window.sessionStorage
ttlnumberLimit the lifetime of the data in the store by setting a time to live in milliseconds. Once the amount of milliseconds has elapsed, the store resets back to the initialState values
*functionone or more action functions that are invoked to eventually mutate state
const store = createAppState('', {
initialState: {
count: 0
persist: '',
ttl: 3600000, // 1 hour
increment (payload) {
this.state.count = this.state.count + payload