Skip to content

Reactivator API

Appurist (Paul) edited this page Dec 13, 2020 · 7 revisions

This library package includes a small number of methods that provide reactivity for data elements. While modeled after Vue, it is framework-agnostic and should support any data, stored anywhere. However, the naming of methods will clash with those in Vue, and likely other frameworks, and since it provides a subset of other frameworks, it is assumed that this package will not be used in combination with other frameworks, at least within the same modules.

Reactivator API

Primary API Methods

ref(data) - wraps a simple scalar data element (such as a number or string) with an object that provides reactivity to that element.

reactive(obj) - replaces (returns) an object (with several members) with a Proxy object that provides reactivity to changes to that element.

computed(data, func) - returns a reactive reference (via .value) that accepts an arbitrary function to provided the evaluation.

watch(data, func) - watches data (which was returned from either ref or reactive above) for any changes and invokes the handler (func) supplied.

unwatch(data, func) - removes a previous watch on data where the handler supplied (func) matches the original watch.

Support Methods

isRef(thing) - returns true if the parameter was previously returned from a call to ref() above.

isReactive(thing) - returns true if the parameter was previously returned from a call to reactive() above.

isComputed(thing) - returns true if the parameter was previously returned from a call to computed() above.

isDirty(since) - returns the number of changes to the data item since the specified revision number, or if since is not provided, it returns the total number of changes. This total can then be used in subsequent calls to isDirty in order to determine if changes have been made since, or if at all (treating the result as a boolean).

Utility Methods

dumpValue(thing, objToJSON)- a convenience function that accepts a variable of any kind and returns a simple text string representation for reporting. If the optional objToJSON parameter is provided and is truthy, an objects encountered will be returned as a JSON string rather than "[object Object]".