Skip to content

activeobject as part of jsutilslib 1.0.0-beta

Latest

Choose a tag to compare

@dealfonso dealfonso released this 03 Dec 09:28
· 1 commit to main since this release

ActiveObject is a library that converts an object into an active object that can emit events when one of its properties changes its value.

It enables creating objects and subscribing to modifications of them. So having

let people = [ { name: "Alice" }, { name: "Bob" } ]
let a_people = ActiveObject(people)
a_people.watch('*.name', function (e) {
    console.log('the list of people has changed', e)
})

if we make a change like a_people[1].name = 'John', the function in the watch will be triggered.

ActiveObject is part of jsutilslib, so please consider using the whole library.