-
Notifications
You must be signed in to change notification settings - Fork 4
/
extension.js
39 lines (31 loc) · 924 Bytes
/
extension.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
38
39
var Extension;
/**
* Extension class.
*
* @param {Object} props User-defined properties of the extension.
*/
module.exports = Extension = function(props) {
this.props = props;
this._initialized = false;
if (!this.props.init && !this.props.format) {
throw new Error('Extensions must define an init method or a format definition object.');
}
};
// Called by the frame controller
Extension.prototype._init = function(OF) {
if (this._initialized) {
return;
}
this.frame = OF.getFrame();
this.pubsub = OF.getPubsub();
this.rest = OF.getRest();
// if the extension props contains a format, add it
if (this.props.format) {
OF.addFormat(this.props.format);
}
// if the extension props define an init method, call it
if (typeof this.props.init === 'function') {
this.props.init.call(this, OF);
}
this._initialized = true;
};