forked from aurelia/framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugins.js
More file actions
79 lines (67 loc) · 1.84 KB
/
plugins.js
File metadata and controls
79 lines (67 loc) · 1.84 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import core from 'core-js';
import * as LogManager from 'aurelia-logging';
import {Metadata} from 'aurelia-metadata';
var logger = LogManager.getLogger('aurelia');
function loadPlugin(aurelia, loader, info){
logger.debug(`Loading plugin ${info.moduleId}.`);
aurelia.currentPluginId = info.moduleId;
return loader.loadModule(info.moduleId).then(m => {
if('configure' in m){
return Promise.resolve(m.configure(aurelia, info.config || {})).then(() => {
aurelia.currentPluginId = null;
logger.debug(`Configured plugin ${info.moduleId}.`);
});
}else{
aurelia.currentPluginId = null;
logger.debug(`Loaded plugin ${info.moduleId}.`);
}
});
}
/**
* Manages loading and configuring plugins.
*
* @class Plugins
* @constructor
* @param {Aurelia} aurelia An instance of Aurelia.
*/
export class Plugins {
constructor(aurelia){
this.aurelia = aurelia;
this.info = [];
this.processed = false;
}
/**
* Configures a plugin before Aurelia starts.
*
* @method plugin
* @param {moduleId} moduleId The ID of the module to configure.
* @param {config} config The configuration for the specified module.
* @return {Plugins} Returns the current Plugins instance.
*/
plugin(moduleId, config){
var plugin = {moduleId:moduleId, config:config || {}};
if(this.processed){
loadPlugin(this.aurelia, this.aurelia.loader, plugin);
}else{
this.info.push(plugin);
}
return this;
}
_process(){
var aurelia = this.aurelia,
loader = aurelia.loader,
info = this.info,
current;
if(this.processed){
return;
}
var next = () => {
if(current = info.shift()){
return loadPlugin(aurelia, loader, current).then(next);
}
this.processed = true;
return Promise.resolve();
};
return next();
}
}