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.
The length of the list-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 list-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.
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 type array
{@see {@link Array.isArray}},
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.
Deletes items at given indices in the list-value.
Dispatches a new copy of the value, without mutating the current-value.
It doesn't modify the length of the list as these indices are only deleted, not removed.
It only works if the Unit is not frozen, and the list is not empty, and at least 1 valid-numeric index is provided.
The indices of the items to be deleted.
A negative index is normalized as following: \
The removed items or an empty array
.
Deletes items from the list-value where the predicate returns true
.
Dispatches a new copy of the value, without mutating the current-value.
It doesn't modify the length of the list as these indices are only deleted, not removed.
It only works if the Unit is not frozen, and the predicate is a function, and the list is not empty.
A callback function that gets called for every item in the list with the item and index as arguments.
The removed items or an empty array
.
Finds items of the list 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 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.
Returns the first item in the list-value.
The first item in the list.
Returns the item at the given index in the list-value.
Negative index returns items from the end of the list.
The index of the item.
A negative index is normalized as following: \
The item at the given index.
Inserts items to the list-value.
Dispatches a new copy of the value, without mutating the current-value.
It only works if the Unit is not frozen and there's at least 1 item to be inserted.
The zero-based index in the list from which to start adding items.
A negative index is normalized as following: \
The items to be insert.
The new length of the list.
Adds all the items of the list separated by the specified separator string, and all the items are converted into string first using JSON.stringify
A string used to separate one item of the list from the next in the resulting String. If omitted, the list items are separated with a comma.
Concatenated JSON.stringify
d list items.
Returns the last item in the list-value.
The last item in the list.
Removes items at given indices from the list-value.
Dispatches a new copy of the value, without mutating the current-value.
It modifies the length of the list as these indices are not deleted,
rather removed using Array.prototype.splice
.
It only works if the Unit is not frozen, and the list is not empty, and at least 1 valid-numeric index is provided.
Notes:
5
, negative index -5
will be normalized to 0
, -6
will be normalized to 0
, and so on.The indices of the items to be removed.
The removed items or an empty array
.
Removes items from the list-value where the predicate returns truthy
value.
Dispatches a new copy of the value, without mutating the current-value.
It modifies the length of the list as these indices are not deleted,
rather removed using Array.prototype.splice
.
It only works if the Unit is not frozen, and
the predicate is a function, and the list is not empty.
It uses remove internally, for actual removal.
A callback function that gets called for every item in the list with the item and index as arguments.
The removed items or an empty array
.
Sets the item on the given index in the list-value.
Dispatches a new copy of the value, without mutating the current-value.
It only works if the Unit is not frozen, and the index is valid-numeric.
The index of the item.
A negative index is normalized as following: \
The item.
Returns the this object after copying a section of the array identified by start and end to the same array starting at position target
It only works if the Unit is not frozen, and the list is not empty isEmpty.
If target is negative, it is treated as length+target where length is the length of the list.
If start is negative, it is treated as length+start. If end is negative, it is treated as length+end.
If end is not specified, length of the list is used as its default value.
Nothing, unlike Array.prototype.copyWithin
Returns the this object after filling the section identified by start and end with value
It only works if the Unit is not frozen, and the list is not empty isEmpty.
value to fill array section with
The index to start filling the list at. If start is negative, it is treated as length+start where length is the length of the list.
The index to stop filling the list at. If end is negative, it is treated as length+end.
Nothing, unlike Array.prototype.fill
Performs the specified action for each item in the list-value.
It's a drop-in replacement for the Array.prototype.forEach
method.
A function that accepts up to three arguments. forEvery calls the callbackFn function one time for each element in the list.
An object to which this keyword can refer in the callbackFn function. If thisArg is omitted, undefined is used as this value.
Removes the last element from an array and returns it.
It only works if the Unit is not frozen, and the list is not empty isEmpty.
The popped item.
Appends new elements to an array, and returns the new length of the array.
It only works if the Unit is not frozen, and at least 1 item is provided.
The items to be appended to the list.
The new length of the list.
Reverses the elements in an Array.
It only works if the Unit is not frozen, and the list is not empty isEmpty.
Nothing, unlike Array.prototype.reverse
Removes the first element from an array and returns it.
It only works if the Unit is not frozen, and the list is not empty isEmpty.
The shifted item.
Returns a section of an array.
The beginning of the specified portion of the list.
The end of the specified portion of the list.
A section of the list.
Sorts an array.
It only works if the Unit is not frozen, and the list is not empty isEmpty.
The name of the function used to determine the order of the items. If omitted, the items are sorted in ascending, ASCII character order.
Nothing, unlike Array.prototype.sort
Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements.
It only works if the Unit is not frozen, and
either deleteCount is not 0 (loose comparison) and the list is not empty isEmpty, or
there's at least 1 item to be added.
The zero-based location in the list from which to start removing items.
The number of items to remove.
The deleted Items or an empty array
.
Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements.
It only works if the Unit is not frozen, and
either deleteCount is not 0 (loose comparison) and the list is not empty isEmpty, or
there's at least 1 item to be added.
The zero-based location in the list from which to start removing items.
The number of items to remove.
Items to insert into the list in place of the deleted items.
The deleted Items or an empty array
.
Inserts new elements at the start of an array.
It only works if the Unit is not frozen, and at least 1 item is provided.
The items to be insert at the start of the list
The new length of the list.
Iterator
Returns an object whose properties have the value 'true' when they will be absent when used in a 'with' statement.
Combines two or more arrays.
Additional items to add to the end of array1.
Combines two or more arrays.
Additional items to add to the end of array1.
Returns an iterable of key, value pairs for every entry in the array
Determines whether all the members of an array satisfy the specified test.
A function that accepts up to three arguments. The every method calls the predicate function for each element in the array until the predicate returns a value which is coercible to the Boolean value false, or until the end of the array.
An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.
Determines whether all the members of an array satisfy the specified test.
A function that accepts up to three arguments. The every method calls the predicate function for each element in the array until the predicate returns a value which is coercible to the Boolean value false, or until the end of the array.
An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.
Returns the elements of an array that meet the condition specified in a callback function.
A function that accepts up to three arguments. The filter method calls the predicate function one time for each element in the array.
An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.
Returns the elements of an array that meet the condition specified in a callback function.
A function that accepts up to three arguments. The filter method calls the predicate function one time for each element in the array.
An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.
Returns the value of the first element in the array where predicate is true, and undefined otherwise.
find calls predicate once for each element of the array, in ascending order, until it finds one where predicate returns true. If such an element is found, find immediately returns that element value. Otherwise, find returns undefined.
If provided, it will be used as the this value for each invocation of predicate. If it is not provided, undefined is used instead.
Returns the index of the first element in the array where predicate is true, and -1 otherwise.
find calls predicate once for each element of the array, in ascending order, until it finds one where predicate returns true. If such an element is found, findIndex immediately returns that element index. Otherwise, findIndex returns -1.
If provided, it will be used as the this value for each invocation of predicate. If it is not provided, undefined is used instead.
Returns a new array with all sub-array elements concatenated into it recursively up to the specified depth.
The maximum recursion depth
Calls a defined callback function on each element of an array. Then, flattens the result into a new array. This is identical to a map followed by flat with depth 1.
A function that accepts up to three arguments. The flatMap method calls the callback function one time for each element in the array.
An object to which the this keyword can refer in the callback function. If thisArg is omitted, undefined is used as the this value.
Performs the specified action for each element in an array.
A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the array.
An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
Determines whether an array includes a certain element, returning true or false as appropriate.
The element to search for.
The position in this array at which to begin searching for searchElement.
Returns the index of the first occurrence of a value in an array.
The value to locate in the array.
The array index at which to begin the search. If fromIndex is omitted, the search starts at index 0.
Adds all the elements of an array separated by the specified separator string.
A string used to separate one element of an array from the next in the resulting String. If omitted, the array elements are separated with a comma.
Returns an iterable of keys in the array
Returns the index of the last occurrence of a specified value in an array.
The value to locate in the array.
The array index at which to begin the search. If fromIndex is omitted, the search starts at the last index in the array.
Calls a defined callback function on each element of an array, and returns an array that contains the results.
A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array.
An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array.
Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array.
If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.
Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array.
Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array.
If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.
Determines whether the specified callback function returns true for any element of an array.
A function that accepts up to three arguments. The some method calls the predicate function for each element in the array until the predicate returns a value which is coercible to the Boolean value true, or until the end of the array.
An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.
Returns a string representation of an array. The elements are converted to string using their toLocalString methods.
Returns a string representation of an array.
Returns an iterable of values in the array
ListUnit is a reactive storage Unit that emulates
array
.ListUnit only accepts
array
data type as its value. It ensures that at any point of time the value would always be anarray
.ListUnit is based on
array
, it implements all theArray.prototype
methods that are available in the environment/browser its running, including polyfills. e.g.:find
,filter
,includes
, etc.Learn more about Units here.
Learn more about ListUnit here.
Just like every other Non-Primitive ActiveJS Unit:
Observable