Store
Store is an app-wide key-value store for shared data, used by every view. It is a singleton and has no reactivity: views read from it in onResume() and write to it in event handlers.
import { Store } from "jops-core";
const store = Store.singleton();Learn more: Store.
Static methods
Section titled “Static methods”Store.singleton()
Section titled “Store.singleton()”Store.singleton(): StoreReturns the single Store instance, creating it on the first call. Always get the store through this method.
Instance methods
Section titled “Instance methods”get(path: string): anyReads a value by dot-notation path.
Parameters
path: for example"user.name".
Returns the stored value, or undefined when the path doesn’t exist.
set(path: string, value: any): voidWrites a value by dot-notation path. Intermediate objects are created as needed.
Parameters
path: for example"user.name".value: any value (object, array, string, …). It is stored as is, not copied.
clear()
Section titled “clear()”clear(): voidRemoves all stored data (resets the store to {}).
Example
Section titled “Example”Store.singleton().set("user.name", "Alice");Store.singleton().get("user.name"); // "Alice"Store.singleton().set("cart.items", [1, 2, 3]);Store.singleton().clear();A typical pattern: one screen writes, another reads when it comes to the front.
import { View, Store } from "jops-core";
export default class Profile extends View { onResume() { const name = Store.singleton().get("user.name") ?? "Guest"; this.get("name").set(name); }}