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 length of the keys of the properties in the dictionary value is 0 or not.
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.
The length of keys of the properties in the dictionary value.
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.
Go back in the cache and re-emit the previous value from the cache,
without creating a new entry in the cache.
It can be used as Undo.
It doesn't work if the Unit is frozen isFrozen.
It only works if there's a previously dispatched value in the cache.
ie: the cacheIndex is not 0
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 go to the next value, without creating a new entry in the cache.
It can be used as Redo.
It doesn't work if the Unit is frozen isFrozen.
It only works if the current value is not the last value in the cache.
ie: the cacheIndex is not equal to cachedValuesCount - 1
true
if the cache-navigation was successful, otherwise false
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.
Extends UnitBase.wouldDispatch and adds additional check for Object dictionary {@link isDict}, which cannot be bypassed even by using {@link force}.
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.
Copy the values of all the enumerable own properties from one or more source objects to the dictionary.
Also, dispatches it as new dictionary, without mutating the current value.
It only works if the Unit is not frozen, and at least 1 source is provided, and it is a non-null object.
eg: array
, object
The source objects from which to copy properties.
Deletes properties with given keys from the dictionary value. See value.
Deletion is performed on a copy of the value, which is then dispatched, without mutating the current value.
It only works if the Unit is not frozen, and the value is not empty,
and at least one of the passed keys exist in the value.
ie: at least 1 key value pair exists in the dictionary.
The names of the properties to be removed.
The removed properties or an empty object-literal
.
Deletes properties from the dictionary value where the predicate returns true
.
Also, dispatches it as new dictionary, without mutating the current value.
It only works if the Unit is not frozen, and the predicate is a function, and the dictionary is not empty.
A callback function that gets called for every property in the dictionary with the property-value and key as arguments.
The removed properties, or an empty object-literal
.
Finds direct properties of the dictionary that have a direct child property
that matches with key
and value
passed as params.
The key of the property whose value needs to be matched against param value
.
A primitive value that will be matched against every item's prop-value using equality operator.
A flag governing whether the value be matched using ===
or ==
operator.
Default is true
, ie: strict equality ===
. Pass false
to use ==
instead.
An array
of key/values of the matched properties, an empty array
otherwise.
Performs the specified action for each property in the object value. See value.
It's a drop-in replacement for the forEach
method.
A function that accepts up to two arguments. forEvery calls the callbackFn function one time for each property in the object value.
An object to which this keyword can refer in the callbackFn function. If thisArg is omitted, undefined is used as this value.
Returns the value of the property with the name equal to the given key in the dictionary value.
It only returns own-properties, e.g.: key 'toString' would return undefined
.
The name of the property.
Returns whether a property with the given key exists in the dictionary value.
The name of the property.
Adds a property by setting given property-value on the given key in the dictionary value.
Also, dispatches it as new dictionary, without mutating the current value.
It only works if the Unit is not frozen and the key
is either string
or number
.
The name of the property.
The property-value.
Iterator
DictUnit is a reactive storage Unit that is loosely based on
Map
.It only accepts plain dictionary
object
as its value. It ensures that at any point of time the value would always be a dictionaryobject
.Learn more about Units here.
Learn more about DictUnit here.
Just like every other Non-Primitive ActiveJS Unit:
Observable