Size of the cache, dictating how many values can be cached at a given time.
Configured options. Combination of global-options GlobalUnitConfig and the options passed on instantiation.
On-demand observable events.
An Observable to observe future values, unlike the default Observable it doesn't replay when subscribed to, rather it waits for the next value.
Index of the current value in the UnitBase.cachedValues
Count of all the cached values.
A counter to keep track of how many times has a Unit, System, Action or Cluster emitted.
Number of times a Unit, System, Action or Cluster has emitted.
Indicates whether the value is undefined or not.
It should be preferred if the Unit is configured to be immutable, as it doesn't create a copy.
Indicates whether the Unit is frozen or not. See freeze for more details.
Note: It's not the same as Object.isFrozen.
Indicates whether the Unit is muted or not. See mute for more details.
All the cached values. Creates a copy if the Unit is configured to be immutable.
The initialValue provided on instantiation. Creates a copy if the Unit is configured to be immutable.
If the Unit has a non-primitive value, use it to get access to the current value, without creating a deep-copy.
This can come in handy if the Unit is configured to be immutable, and you want to perform a non-mutating action without creating a deep-copy of the value.
Current value of the Unit. Creates a copy if the Unit is configured to be immutable.
It extends UnitBase.goBack, and allows skipping over nil (null or undefined) values.
To skip over nil values pass true
as skipNilValues
.
Should the null
and undefined
values be skipped over.
It extends UnitBase.goForward, and allows skipping over nil (null or undefined) values.
To skip over nil values pass true
as skipNilValues
.
Should the null
and undefined
values be skipped over.
Use this method to re-emit a value from the cache, by jumping specific steps backwards or forwards,
without creating a new entry in the cache.
It doesn't work if the Unit is frozen isFrozen or steps
is not a number
.
It only works if the new calculated index is in the bounds of cachedValues,
ie: the new-index is >= 0, and less than cachedValuesCount, but
not equal to current cacheIndex.
Number of steps to jump in the cache, negative to jump backwards, positive to jump forwards
true
if the cache-navigation was successful, otherwise false
.
After going back in the cache (ie: re-emitting an old value from the cache),
use this method to re-dispatch the last (latest) value in the cache,
without creating a new entry in the cache.
It doesn't work if the Unit is frozen isFrozen. It only works if the cacheIndex is not already at the last value in the cache.
true
if the cache-navigation was successful, otherwise false
Use this method to re-emit the first value in the cache,
without creating a new entry in the cache.
It doesn't work if the Unit is frozen isFrozen.
It only works if the cacheIndex is not already at the last value in the cache.
ie: the cacheIndex is not 0.
true
if the cache-navigation was successful, otherwise false
Creates a new Observable using the default Observable as source. Use this to conceal other aspects of a Unit, System, Action or Cluster except the Observable part.
An Observable with the value of a Unit, System, Action or Cluster.
A helper method that creates a stream by subscribing to the Observable returned by the param observableProducer
callback.
Ideally the callback function creates an Observable by applying Observable.pipe
.
Just know that you should catch the error in a sub-pipe (ie: do not let it propagate to the main-pipe), otherwise as usual the stream will stop working, and will not react on any further emissions.
A callback function that should return an Observable.
To manually re-emit the last emitted value again.
It doesn't work if the Unit is frozen isFrozen or muted isMuted.
Note: Even if the Unit is immutable, it does not create a copy of the Unit's value, it merely re-emits the last emitted value.
true
if replayed successfully, otherwise false
.
Converts the value to JSON string, using JSON.stringify
.
Method to dispatch new value by passing the value directly, or
by passing a value-producer-function that produces the value using the current value.
Given a value, it either gets dispatched if it's allowed by wouldDispatch,
or it gets ignored if not allowed.
If the Unit is not configured to be immutable, then
the value-producer-function (param valueOrProducer
) should not mutate the current value,
which is provided as an argument to the function.
If you mutate the value, then the cached-value might also get mutated,
as the cached-value is saved by reference, which can result in unpredictable state.
Dispatch options.
true
if value got dispatched, otherwise false
.
If UnitConfig.dispatchDebounce is enabled, then it'll return undefined
.
Method to dispatch new value by passing the value directly, or
by passing a value-producer-function that produces the value using the current value.
Given a value, it either gets dispatched if it's allowed by wouldDispatch,
or it gets ignored if not allowed.
If the Unit is not configured to be immutable, then
the value-producer-function (param valueOrProducer
) should not mutate the current value,
which is provided as an argument to the function.
If you mutate the value, then the cached-value might also get mutated,
as the cached-value is saved by reference, which can result in unpredictable state.
true
if value got dispatched, otherwise false
.
If UnitConfig.dispatchDebounce is enabled, then it'll return undefined
.
Select a nested property at a certain path in the Unit's value. It doesn't fail even if a value in middle of the path is undefined.
It can be used to create an Observable to listen to changes in a nested property using Selection.asObservable method.
It provides static value access through the Selection.value method. It can be helpful when the Unit is configured to be immutable, as you only clone the nested property instead of the whole value.
A Selection object of the selected property or path.
Select a nested property at a certain path in the Unit's value. It doesn't fail even if a value in middle of the path is undefined.
It can be used to create an Observable to listen to changes in a nested property using Selection.asObservable method.
It provides static value access through the Selection.value method. It can be helpful when the Unit is configured to be immutable, as you only clone the nested property instead of the whole value.
A Selection object of the selected property or path.
Select a nested property at a certain path in the Unit's value. It doesn't fail even if a value in middle of the path is undefined.
It can be used to create an Observable to listen to changes in a nested property using Selection.asObservable method.
It provides static value access through the Selection.value method. It can be helpful when the Unit is configured to be immutable, as you only clone the nested property instead of the whole value.
A Selection object of the selected property or path.
Select a nested property at a certain path in the Unit's value. It doesn't fail even if a value in middle of the path is undefined.
It can be used to create an Observable to listen to changes in a nested property using Selection.asObservable method.
It provides static value access through the Selection.value method. It can be helpful when the Unit is configured to be immutable, as you only clone the nested property instead of the whole value.
A Selection object of the selected property or path.
Select a nested property at a certain path in the Unit's value. It doesn't fail even if a value in middle of the path is undefined.
It can be used to create an Observable to listen to changes in a nested property using Selection.asObservable method.
It provides static value access through the Selection.value method. It can be helpful when the Unit is configured to be immutable, as you only clone the nested property instead of the whole value.
A Selection object of the selected property or path.
Select a nested property at a certain path in the Unit's value. It doesn't fail even if a value in middle of the path is undefined.
It can be used to create an Observable to listen to changes in a nested property using Selection.asObservable method.
It provides static value access through the Selection.value method. It can be helpful when the Unit is configured to be immutable, as you only clone the nested property instead of the whole value.
A Selection object of the selected property or path.
Holistically clears the Unit,
unfreezes using unfreeze,
clears the value using clearValue,
completely clears cache using clearCache,
in that specific order.
Clear cache options for clearCache.
Clears the cached values, current value stays intact, but it gets removed from the cache.
Meaning, if you dispatch a new value you can't goBack.
To keep the last value in the cache, pass {leaveLast: true}
in the param options
.
It only works if the Unit is not frozen and there's something left to clear after evaluating the param options
.
Similar to preserving the last value, you can preserve the first value by passing {leaveFirst: true}
.
Or preserve both first and last value by passing both options together.
Clear cache options
true
if the cache was cleared, otherwise false
Clears persisted value from persistent storage.
It doesn't turn off persistence, future values will get persisted again.
It only works if the Unit is configured to be persistent. ie: options.persistent
is true.
true
if the Unit is configured to be persistent, otherwise false
.
true
if the value was cleared, otherwise false
Temporarily disables most of the functions of the Unit, except unfreeze,
mute/unmute, clear and reset.
It's not the same as Object.freeze
.
Freezing prevents any new values from getting dispatched,
it disables all the mutating functions.
Which eventually ensures that no event is emitted while the Unit is frozen,
however all the read operations and operations that do not emit a value are allowed.
Get cached value at a given index.
The index of cached value
The cached value if it exists, otherwise undefined
Mute the Unit, to stop emitting values as well as events, so that the subscribers are not triggered.
All other functionalities stay unaffected. ie: cache it still updated, value is still updated.
Note: If you subscribe to the default Observable while the Unit is muted,
it will replay the last value emitted before muting the Unit,
because new values are not being emitted.
Holistically resets the Unit,
unfreezes using unfreeze,
resets the value using resetValue,
clears cache using clearCache and by default leaves last value;
in that specific order.
Clear cache options for clearCache. default is {leaveLast: true}
Resets the value by dispatching the initial-value, UnitConfig.initialValue if provided,
otherwise dispatches the default value.
It only works if the Unit is not frozen,
and the value is not equal to the initialValue.
true
if the reset was successful, otherwise false
Unfreezes the Unit, and re-enables all the functions disabled by freeze.
It only works if the Unit is frozen.
Unmute the Unit, to resume emitting values, and events.
If a value was dispatched while the Unit was muted, the most recent value immediately gets emitted,
so that subscribers can be in sync again.
However, other events$ are lost, and they will only emit on the next event.
It only works if the Unit is muted.
Moreover, it works even if the Unit is frozen,
but no value will be emitted because no values would have been dispatched while the Unit was frozen.
Given a value, this function determines whether it should be dispatched or not.
The dispatch is denied in following circumstances:
true
, and the new-value === current-value,falsy
value.If the Unit is not frozen, you can bypass other dispatch-checks by passing param force = true
.
This function is used internally, when a value is dispatched dispatch.
Even initialValue UnitConfig.initialValue dispatch has to pass this check.
You can also use it to check if the value will be dispatched or not before dispatching it.
The value to be dispatched.
Whether dispatch-checks should be bypassed or not.
A boolean indicating whether the param value
would pass the dispatch-checks if dispatched.
GenericUnit is a reactive storage Unit that doesn't pertain to any specific data type.
GenericUnit accepts all data types as its value.
Learn more about Units here.
Learn more about GenericUnit here.
Just like every other Non-Primitive ActiveJS Unit:
Observable