Rack it's a simple and pluggable state manager based on reactive concepts
The key concepts that Rack implements are:
- History managements of your application's global states
- States are observable by default
- Pluggable persistent layer module
- Hande immutable state concepts
npm install @antonlabs/rack
import {State} from "@antonlabs/rack";
export interface WalletProperties {
currency: string;
units: number;
}
export class WalletState extends State<WalletProperties> {
onCreate(): WalletProperties { // this is used to provide a first implementation of you state
return {
currency: undefined,
units: undefined
};
}
async refreshState(): Promise<void> {}
}
export const appRack = new Rack({
myWallet: new WalletState('wallet') //wallet argument is the key in the persitent layer that contains the state content
});
rack.states.myWallet.obs.subscribe(
(wallet) => {
//Do a lot of things
}
);
This will auto propagate your changes to all listeners
rack.states.myWallet.set({
currency: 'EUR'
});
rack.states.myWallet.store()
Install the adapter package, for example this is the module to use MacOS's keychain
npm install @antonlabs/rack-keychain-adapter
You can changing it during instance declaration like the example
const rack = new Rack({
myWallet: new WalletState(
'wallet',
new KeyChainAdapter('anton.finance') //the argument is the domain of our secrets
)
});