Monster.Types. ProxyObserver

An observer manages a callback function

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.

Constructor

new ProxyObserver(object)

Parameters:
NameTypeDescription
objectobject
Since
  • 1.0.0
License
  • AGPLv3
Throws:

value is not a object

Type
TypeError
Example
import {ProxyObserver} from '@schukai/monster/source/types/proxyobserver.mjs';
import {Observer} from '@schukai/monster/source/types/observer.mjs';
import {isObject} from '@schukai/monster/source/types/is.mjs';

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

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

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

Methods

attachObserver(observer) → {ProxyObserver}

attach a new observer

.

attach a new observer

Parameters:
NameTypeDescription
observerObserver
Returns:
Type: 
ProxyObserver

containsObserver(observer) → {boolean}

Parameters:
NameTypeDescription
observerObserver
Returns:
Type: 
boolean

detachObserver(observer) → {ProxyObserver}

detach a observer

.

detach a observer

Parameters:
NameTypeDescription
observerObserver
Returns:
Type: 
ProxyObserver

getRealSubject() → {object}

get the proxied object

.

get the proxied object

Returns:
Type: 
object

getSubject() → {object}

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.

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() → {Promise}

notify all observer

.

notify all observer

Returns:
Type: 
Promise

setSubject(obj) → {Monster.Types.ProxyObserver}

Parameters:
NameTypeDescription
objObject
Since
  • 1.24.0