omniscient
The simplest usable global state management.
Usage
The goal is extremely simple state management. There are only 4 methods to learn!
Constructing a new instance
The constructor allows you to set the initial state of the store, or just leave it empty!
const omniscient = ; // Empty stateconst omniscient = todos: id: 1 value: 'Get some wicked kicks at the shoe store' ; // Initial state
getState
You can either get the entire state, or a specific property of the state.
const initialState = user: id: 1234 name: 'Boba Fett' lastAction: name: 'Being awesome' time: 'May 25, 1983' ;const omniscient = initialState; const allState = omniscient;console; // true const user = omniscient;console; // true
setState
Similar to getState you can either set the entire state, or a specific property of the state.
const initialState = user: id: 1234 name: 'Boba Fett' lastAction: name: 'Being awesome' time: 'May 25, 1983' ;const omniscient = initialState; const currentUser = omniscient;omniscient;const name = omniscient;console; // true const newState = completely: 'different';omniscient;const allState = omniscient;console; // true
registerCallback and unregister
These are the callback management methods. If you want to know when a property changes, you'll call registerCallback
. If you stop caring about that property, you'll call unregister
.
const initialState = user: id: 1234 name: 'Boba Fett' lastAction: name: 'Being awesome' time: 'May 25, 1983' ;const omniscient = initialState; const callback = console; // Call this method any time the 'user' property changesconst registrationId = omniscient; const callbackUserOne = omniscient; // This will trigger the call backomniscient; // When you no longer want to be called for a property changeomniscient; console;const callbackUserTwo = omniscient;omniscient;