2.2.0 • Published 10 months ago

@aegenet/belt-obj-monitoring v2.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

npm version

@aegenet/belt-obj-monitoring

Object Monitoring

💾 Installation

yarn add @aegenet/belt-obj-monitoring@^2.0.0
# or
npm i @aegenet/belt-obj-monitoring@^2.0.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';
2.2.0

10 months ago

2.1.0

11 months ago

1.6.2

1 year ago

1.7.0

1 year ago

1.6.1

1 year ago

2.0.0

1 year ago

1.5.0

1 year ago

1.4.2

1 year ago

1.4.1

1 year ago

1.4.0

1 year ago

1.3.2

2 years ago

1.3.1

2 years ago

1.3.0

2 years ago

1.2.0

2 years ago