Api / JavaScript /

createObserver( callback )

Creates a new Observer object that listen for mutations.

Arguments

callback Function( mutations:Array )

The function where you want to receive the mutations.

Returns

A new Observer object.

Examples

const user = dop.register({ surname: 'Doe' })
const observer = dop.createObserver(mutations => {
    const mutation = mutations[0]
    console.log(mutation.object === user) // true
    console.log(mutation.prop) // 'surname'
    console.log(mutation.value) // 'Gonzalez'
    console.log(mutation.oldValue) // 'Doe'
})
observer.observeObject(user)
user.surname = 'Gonzalez'

See also