-
Notifications
You must be signed in to change notification settings - Fork 0
/
UnicronSubscriber.js
37 lines (30 loc) · 1.31 KB
/
UnicronSubscriber.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { UnicronWeapons } from 'decepticons/UnicronWeapons.js'
export class UnicronSubscriber extends UnicronWeapons {
constructor(topic, listener, $scope) {
super();
if (typeof topic === 'undefined')
throw new Error('Can not create a subscriber without a topic');
if (typeof listener === 'undefined')
throw new Error('Can not create a subscriber without a listener');
this.id = this.guid();
this.topic = topic;
if (this.isValidHandler(listener)) {
this.listener = listener.bind($scope || this);
} else
this.listener = () => {};
}
isValidHandler(handler) {
let error = null;
if (typeof handler === 'function') {
return true;
}
error = new Error('Attempt to register an invalid handler with the subscriber.');
error.handler = handler;
throw error;
}
}
const _root = window || global;
( (namespace) => { 'use strict'; })(_root.decepticons = _root.decepticons || {});
( (namespace) => { 'use strict'; })(_root.decepticons.helpers = _root.decepticons.helpers || {});
( (namespace) => { 'use strict'; })(_root.decepticons.helpers.messenger = _root.decepticons.helpers.messenger || {});
_root.decepticons.helpers.messenger.UnicronSubscriber = UnicronSubscriber;