Observer

Monster/Types. Observer

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/observer.js';
console.log(new Monster.Types.Observer())
</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/observer.js';
console.log(Observer())
</script>

the update method is called with the subject object as this pointer. for this reason the callback should not be an arrow function, because it gets the this pointer of its own context.

<script>
Observer(()=>{
    // this is not subject
})

Observer(function() {
    // this is subject
})
</script>

additional arguments can be passed to the callback. to do this, simply specify them.

<script>
Observer(function(a, b, c) {
    console.log(a, b, c); // ↦ "a", 2, true 
}, "a", 2, true)
</script>

the callback function must have as many parameters as arguments are given.

Constructor

new Observer(callback, …args)

Source:
Since:
  • 1.0.0
Parameters:
Name Type Attributes Description
callback function
args * <repeatable>

Methods

addTag(tag) → {Observer}

Source:
Parameters:
Name Type Description
tag string
Returns:
Type
Observer

getTags() → {Array}

Source:
Returns:
Type
Array

hasTag(tag) → {boolean}

Source:
Parameters:
Name Type Description
tag string
Returns:
Type
boolean

removeTag(tag) → {Observer}

Source:
Parameters:
Name Type Description
tag string
Returns:
Type
Observer

update(subject) → {Promise}

Source:
Parameters:
Name Type Description
subject object
Returns:
Type
Promise