Skip to content

luffs/lazy-watch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LazyWatch

Deep watch objects (using Proxy) and emit diff asynchronously.

Install:

npm i lazy-watch

Simple Usage:

const UI = new LazyWatch({})
LazyWatch.on(UI, diff => console.log({ diff }))
UI.hello = 'world'

Example:

const initialData = () => {
  return { pretty: false, list: [{ nice: false  }], right: true, junk: 123 }
}
const UI = new LazyWatch(initialData())
const mirror = new LazyWatch(initialData())
const changeListener = diff => {
  console.log({ diff })
  // the diff could be sent via websocket to another browser or something
  LazyWatch.patch(mirror, diff)
}
LazyWatch.on(UI, changeListener)

UI.pretty = true;
UI.list[0].forEach(item => {
  item.nice = true
})
delete UI.junk
// this will result in changeListener getting called once with all changes

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published