@aegenet/belt-obj-monitoring
TypeScript icon, indicating that this package has built-in type declarations

1.5.0 • Public • Published

npm version

@aegenet/belt-obj-monitoring

Object Monitoring

💾 Installation

yarn add @aegenet/belt-obj-monitoring@^1.4.0
# or
npm i @aegenet/belt-obj-monitoring@^1.4.0

📝 Usage

Two ways:

  • One that mutates your original object (and you can use it normally): mutate.
  • One that uses a proxy to access your original object. You must use the proxy, not the original object: asProxy.

With Mutation

  • Caution: this mutates your data.
  • Limitation: if a property is added to the original data, we cannot track it.
import { ObjectMonitoring } from '@aegenet/belt-obj-monitoring';

const objMonitor = new ObjectMonitoring({
  callback: result => console.table(result),
});

const data = {
  title: 'Boris',
  description: 'Oromov',
};

const token = objMonitor.mutate(data);

data.title = 'Maurice';
// console.table({
//   newValue: 'Maurice',
//   oldValue: 'Boris',
//   path: 'title',
//   property: 'title',
// })

// We remove all listeners
token.dispose();

// Any next changes are not monitored
data.title = 'Maurice2';

With Proxy

  • Limitation: You must use the proxied data, not the original data.
import { ObjectMonitoring } from '@aegenet/belt-obj-monitoring';

const objMonitor = new ObjectMonitoring({
  callback: result => console.table(result),
});

const data = {
  title: 'Boris',
  description: 'Oromov',
};

const proxyData = objMonitor.mutate(data);

proxyData.title = 'Maurice';
// console.table({
//   newValue: 'Maurice',
//   oldValue: 'Boris',
//   path: 'title',
//   property: 'title',
// })


// Changes to the original data are not monitored
data.title = 'Maurice2';

Readme

Keywords

Package Sidebar

Install

npm i @aegenet/belt-obj-monitoring

Weekly Downloads

1

Version

1.5.0

License

MIT

Unpacked Size

10.9 kB

Total Files

7

Last publish

Collaborators

  • agenet