Skip to content

Reactivator API: isDirty()

Appurist (Paul) edited this page Dec 13, 2020 · 1 revision

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).

isDirty()

Parameters: (since)

Returns: 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).

Example usage:

import { ref, isDirty } from 'reactivator'

const DATA = 42
let data = ref(COUNT)

data.value++;
let since = data.isDirty();  // current total
console.log("Number of changes after first change:", since);  // 1

data.value = 99
changes = data.isDirty();  // current total
console.log("Number of changes after second change:", changes);  // 2

changes = data.isDirty(since);  // a "since" was provided
console.log("Number of changes since first change:", changes);  // 1

Resulting output:

Number of changes after first change: 1
Number of changes after second change: 2
Number of changes since first change: 1