Quark
#
Modules #
quark/actionquark/appquark/bubblesquark/bufferquark/checkboxquark/cssquark/ctrquark/defsquark/dialogquark/eventquark/fontquark/fsquark/hashquark/httpquark/indexquark/jsonbquark/keyboardquark/lmdbquark/mediaquark/navquark/netquark/osquark/pathquark/pkgquark/screenquark/statequark/stepperquark/storagequark/testquark/typesquark/uriquark/utilquark/viewquark/windowquark/wsquark/_bufferquark/_commonquark/_decoratorsquark/_eventquark/_extquark/_md5quark/_sha1quark/_sha256quark/_utilquark/_watching
Quark v1.4.0 Documentation
Contents
quark/state #
onState #
Event triggered when any state is changed.
@eventonState:EventNoticer<Event<void,Dict>>
getState(name) #
Get a global state value by name. If not found in memory, try to read from storage if it's global.
getState(name: string)
Type parameters: T
setState(state,self?) #
Update state values (both local and global). Rules for keys:
- Normal keys (no
$prefix): updated only onself(local state). - Keys starting with
$(e.g.$count):- Treated as global shared state.
- The value is stored in
GlobalStates. - All GlobalState controllers that subscribed to this key will receive an update.
- Keys starting with
$(e.g.$theme):- Treated as global + persistent state.
- Same as
$key, but in addition the value is also written tostorageunder the key"_global_state_" + name. - On next load, if
GlobalStatesdoes not contain the key, it will be recovered fromstorage. Update order:
- Collect all changed
$/$keys and updateGlobalStates(andstorageif$). - Notify all other subscribed GlobalState controllers with the relevant subset of changes.
- Finally, update
self(if provided) usingViewController.prototype.setStateand trigger the callback (if provided).setState(state: S, self: any, self?: GlobalState): Promise<void>
Parameters:
state— Key-value pairs to update.self— The GlobalState instance that initiated the update (optional).Used to avoid notifying itself twice and to update its local state at the end.
Returns: resolves after all updates and callbacks are done.
Type parameters: S
Class: GlobalState #
GlobalState #
A special ViewController that can participate in global state sharing.
Any state key starting with $ will be synchronized across all GlobalState instances.
Keys starting with $ are persisted in storage.
Type parameters: P, S
Extends: ViewController<P,S>
globalstate.triggerLoad() #
Triggered when the controller is loaded. Synchronizes its global state keys with the GlobalStates.
triggerLoad()
globalstate.triggerUnload() #
Triggered when the controller is unloaded. Remove it from global subscribers if it was global.
triggerUnload()
Class: PersistentState #
PersistentState #
Extends GlobalState with persistence across component lifecycles. Each PersistentState instance gets a unique persistent ID.
Type parameters: P, S
Extends: GlobalState<P,S>
persistentstate.persistentID #
Unique ID for each PersistentState class
readonly persistentID:
persistentstate.saveState() #
Subclass can override this to define what to save persistently
saveState(): Partial<S> | null
persistentstate.recoveryState() #
Restore state from PersistentStates map
recoveryState(): Partial<S> | null
persistentstate.triggerLoad() #
When loading, recover state first, then proceed with global sync
triggerLoad()
persistentstate.triggerUnload() #
Called when the PersistentState controller is unloaded.
- First calls the parent's triggerUnload (to clean up global subscriptions).
- Then tries to save the component's state via
saveState().- If a partial state is returned, store it in PersistentStates (in-memory cache).
- Otherwise, remove any previously stored state for this component.
triggerUnload()