Specifying Priority

Priority allows some listeners to be called prior to the others when the event occurs. The smaller number, the higher priority. If priority is not specified, Priority.MEDIUM will be used by default.

const { Priority } = require('robo-toolkit').event;

/** possible values:
    Priority.HIGEST: Number.MIN_SAFE_INTEGER
    Priority.HIGER: -2
    Priority.HIGH: -1
    Priority.MEDIUM: 0
    Priority.LOW: 1
    Priority.LOWER: 2
    Priority.LOWEST: Number.MAX_SAFE_INTEGER
*/

// usage
aggregator
    .get('some event')
    .priority(Priority.HIGH)
    .add(listener);

You can use any number you want as Priority rather than predefined ones. Below is an example:

aggregator
    .get('some event')
    .priority(10)
    .add(() => {
        console.log('My priority: 10');
    });

aggregator
    .get('some event')
    .priority(5)
    .add(() => {
        console.log('My priority: 5');
    });

aggregator
    .get('some event')
    .dispatch();

Output in console will look like:

My priority: 5
My priority: 10

Last updated