saviski / ski-spy

Watch changes to object properties, using Proxy and __proto__ modifications

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

About

Watch changes to object properties, using Proxy and __proto__ modifications


Languages

Language:TypeScript 96.5%Language:JavaScript 3.5%