// Importconst{ Store }=require('@maexsoftware/datastore');// Initialize storeconststore=newStore('testStore',0);// Add modifier functions to storestore.modifier('increment',(state,value)=>state+value);store.modifier('decrement',(state,value)=>state-value);// Call modifier functions to create modifications to the store statestore.modify.increment(10);store.modify.decrement(5);// Calculate new state valuestore.state();// => 5// The base state does not changestore.baseState;// => 0// Unless a commit has been madestore.commit();store.baseState;// => 5// Stores also have eventsstore.subscribe('update',functionupdateListener(modification){console.log('update ran with:',modification);});// This will publish an 'update' event// console will log:// 'update ran with: { type: increment, value: 100 }'store.modify.increment(100);// Events also publish 'updated' events when commits are performed// console will log:// 'updated with new state: 105'constsubscription=store.subscribe('updated',functionupdatedListener(state){console.log('updated with new state:',state);});store.commit();// And of course you can unsubscribe the listener at any pointsubscription.unsubscribe();