Skip to content

Reactivator API: isComputed()

Appurist (Paul) edited this page Sep 27, 2020 · 1 revision

isComputed()

Parameters: (obj)

Returns: true if the specified argument (obj) was previously returned by ref()

This boolean method can be used to check if an object is a reactivator computed value.

Example usage:

import { ref, isRef, isReactive } from 'reactivator'

function addOne(context) {
  return context.value + 1;
}
let computedAdd = computed(dataRef, addOne);
let dataRef = ref(42)
let dataReactive = reactive({textField: 'Hello', numField: 100})

console.log("isComputed(computedAdd) is", isComputed(computedAdd)); // true
console.log("isComputed(addOne) is", isComputed(addOne)); // false
console.log("isComputed(dataRef) is", isComputed(dataRef)); // false
console.log("isComputed(dataReactive) is", isComputed(dataReactive)); // false
console.log("isComputed(42) is", isComputed(42)); // false
console.log("isComputed( {field: 42} ) is", isComputed( {field: 42} ); // false

Resulting output:

isComputed(computedAdd) is true
isComputed(addOne) is false
isComputed(dataRef) is false
isComputed(dataReactive) is false
isComputed(42) is false
isComputed( {field: 42} ) is false