ProxyObserver

Monster/Types. ProxyObserver

an observer manages a callback function

you can call the method via the monster namespace new Monster.Types.Observer().

<script type="module">
import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.5.0/dist/modules/types/proxyobserver.js';
console.log(new Monster.Types.ProxyObserver())
</script>

Alternatively, you can also integrate this function individually.

<script type="module">
import {Observer} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.5.0/dist/modules/types/proxyobserver.js';
console.log(new ProxyObserver())
</script>

with the ProxyObserver you can attach observer for observation. with each change at the object to be observed an update takes place.

this also applies to nested objects.

const o = new Observer(function () {
   if (isObject(this) && this instanceof ProxyObserver) {
       // do something (this ist ProxyObserver)
       const subject = this.getSubject();
   }
)

let realSubject = {
   a: {
       b: {
           c: true
       },
       d: 5
   }


const p = new ProxyObserver(realSubject);
p.attachObserver(o);
const s = p.getSubject();
s.a.b.c = false;

Constructor

new ProxyObserver(object)

Source:
Since:
  • 1.0.0
Parameters:
Name Type Description
object object

Methods

attachObserver(observer) → {ProxyObserver}

Source:

attach a new observer

Parameters:
Name Type Description
observer Observer
Returns:
Type
ProxyObserver

containsObserver(observer) → {ProxyObserver}

Source:
Parameters:
Name Type Description
observer Observer
Returns:
Type
ProxyObserver

detachObserver(observer) → {ProxyObserver}

Source:

detach a observer

Parameters:
Name Type Description
observer Observer
Returns:
Type
ProxyObserver

getRealSubject() → {object}

Source:

get the proxied object

Returns:
Type
object

getSubject() → {object}

Source:

get the real object

changes to this object are not noticed by the observers, so you can make a large number of changes and inform the observers later.

Returns:
Type
object

notifyObservers() → {ProxyObserver}

Source:

notify all observer

Returns:
Type
ProxyObserver