Must be instantiated in an injection context. This should naturally be the case for subclasses that are services (which is the common case).
the key in local storage at which to persist the state
used when the state has not been persisted yet
Optionalcodec?: PersistenceCodec<State, Persisted>used to persist a different format than what is kept in the store
Optionalmigrator?: MigrationManager<Persisted>used to update state that was at a lower VersionedObject._version when it was persisted
Assigns the given values to the state of this store object. The resulting state will be like Object.assign(store.state, value).
Get the current state of this store object. This is backed by a signal, so it will trigger change detection when accessed in templates, etc.
Runs func on a shallow clone of the state, replacing the state with the clone. The first argument to func will be the cloned state, followed by the arguments in args.
WARNING: You SHOULD NOT use a function that will mutate nested objects within the state.
Runs func on the state and replaces it with the return value. The first argument to func will be the state, followed by the arguments in args.
WARNING: You SHOULD NOT use a function that will mutate the state.
A store that is automatically saved to and restored from local storage. This is suitable for small stores that can very quickly be (de)serialized to/from JSON without any noticeable delay.
At this point, if you change
_versionthe store will be reset to the default state. This is a convenience during initial development of your app. Once it is released to real users, you will want to use a MigrationManager to avoid wiping out your users' data:If you want to persist something a little different from what is in the store, for example to omit some properties, use a
PersistenceCodec: