Abstract
Static
ofCalling Reactive.of with a value that is already reactive just returns it as is.
Like Reactive.of:VALUE but wraps an array as a ReactiveArray.
Optional
cache: ReactiveCacheLike Reactive.of:ARRAY but allows specifying how data passed to ReactiveArray.patch should be converted to elements.
Optional
cache: ReactiveCacheLike Reactive.of:VALUE but wraps an object as a ReactiveObject.
Optional
cache: ReactiveCacheLike Reactive.of:OBJECT but allows specifying how data passed to ReactiveObject.patch should be converted to properties.
Optional
cache: ReactiveCacheWraps the given value as a ReactiveValue. If the cache already contains a reactive counterpart, that is recycled instead.
original value
Optional
cache: ReactiveCachepass a custom ReactiveCache or Reactive.NO_CACHE to disable caching. Default: Reactive.DIRECT_CACHE
Static
nestCalling Reactive.nest with a value that is already reactive just returns it as is, without any nesting.
Like Reactive.nest:OBJECT but for arrays.
Optional
arrayCache: ReactiveCacheOptional
elementCache: ReactiveCacheLike Reactive.nest:OBJECT_CONVERT but for arrays.
Optional
arrayCache: ReactiveCacheOptional
elementCache: ReactiveCacheLike Reactive.of:OBJECT but also makes all properties reactive. Useful for improving patch performance.
Note that this is limited to direct properties only, any nested values are left as is.
Since the root object and properties are transformed differently, you can provide a separate cache for both. By default, Reactive.NESTED_CACHE is used for the root object and Reactive.DIRECT_CACHE for the properties.
Optional
objectCache: ReactiveCacheOptional
propertyCache: ReactiveCacheLike Reactive.nest:OBJECT but allows specifying how data passed to ReactiveObject.patch should be converted to properties.
Optional
objectCache: ReactiveCacheOptional
propertyCache: ReactiveCacheCalling Reactive.nest with a value that is neither an object nor an array has the same effect as Reactive.of:VALUE.
Static
unwrapDeeply unwraps the given value. This means that the value is :instance | unwrapped if it is Reactive, otherwise it is returned as is. This is then repeated as long as needed until an unreactive value is found.
Static
unnestUnwraps the given value and any deeply nested properties or array elements.
Static
deriveFactory function to create a ReactiveDerivative.
Convenience function that allows passing a value that is optionally reactive. Calls Reactive.derive:INSTANCE if the given value is reactive, otherwise applies the transformation directly.
Static
combineConvenience function that converts an array of optionally reactive values into an optionally reactive array. The result is reactive if one of the given values is reactive, otherwise the given array is returned as is.
Like Reactive.combine:BASIC, but allows passing a function that transforms the array of unwrapped values into something else.
Effectively a shorthand for Reactive.derive(Reactive.combine(values), transform)
.
NOTE if none of the given values is reactive, transform is applied to the original array.
Static
consumeConvenience function that allows passing a value that is optionally reactive. Calls Reactive.consume:INSTANCE if the value is reactive, otherwise calls the consumer directly.
Reactively unwrap the underlying value, creating a subscription to track its dependants using the given tracker. Important in a ReactiveDerivative.
Abstract
unwrapReturns the current underlying value without tracking dependencies. Use Reactive.get if you need reactivity.
Creates a ReactiveDerivative that transforms the underlying value to something else.
function that receives the underlying value and produces a new one.
Creates a ReactiveDerivative that contains the property with the given name when the underlying value is an object, or the element at the given index when the underlying value is an array. You can use a negative index to count back from the end.
property name or index
undefined
.
TypeScript prevents this at compile time, there are no additional checks at runtime.undefined
.
TypeScript does not normally prevent this at compile time as it hides the potential undefined
!
There are also no additional checks at runtime because this may be intentional.
If you expect an index to be valid you can ensure this with something like ...select(101).derive(expectPresent)
.Select 2 levels deep
Select 3 levels deep
Select 4 levels deep
Select 5 levels deep
Select more than 5 levels deep without type checking. Consider combining multiple selects with a maximum depth of 5 instead.
Let subscribers (reactive dependants) know that this value has changed. Make sure to always call this after manually mutating a reactive value. Mutations through ReactiveValue.set and other library APIs do this for you.
Note that not all reactive values are expected to be mutated directly. ReactiveValue and its subclasses are, but ReactiveDerivative is not!
Returns the primitive value of the specified object.
Returns a string representation of an object.
Base class representing a reactive entity.