Skip to content

Latest commit

 

History

History
24 lines (17 loc) · 496 Bytes

README.md

File metadata and controls

24 lines (17 loc) · 496 Bytes

Simple observer that allow watching for property value changes of existing objects

import { spy } from '@ski/spy'

let originalObject = { a: 1, b: 2 }

let events = spy(originalObject)
logChanges(events)

originalObject.a = 3
originalObject.b = 5
originalObject.c = 1

async function logChanges(stream) {
  for await (const [key, value] of stream) console.log('property', key, 'changed', value)
}

will log

  • property a changed 3
  • property b changed 5
  • property c changed 1