forked from jakesgordon/javascript-state-machine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin.js
More file actions
40 lines (30 loc) · 1.07 KB
/
plugin.js
File metadata and controls
40 lines (30 loc) · 1.07 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
'use strict'
//-------------------------------------------------------------------------------------------------
var mixin = require('./util/mixin');
//-------------------------------------------------------------------------------------------------
module.exports = {
build: function(target, config) {
var n, max, plugin, plugins = config.plugins;
for(n = 0, max = plugins.length ; n < max ; n++) {
plugin = plugins[n];
if (plugin.methods)
mixin(target, plugin.methods);
if (plugin.properties)
Object.defineProperties(target, plugin.properties);
}
},
hook: function(fsm, name, additional) {
var n, max, method, plugin,
plugins = fsm.config.plugins,
args = [fsm.context];
if (additional)
args = args.concat(additional)
for(n = 0, max = plugins.length ; n < max ; n++) {
plugin = plugins[n]
method = plugins[n][name]
if (method)
method.apply(plugin, args);
}
}
}
//-------------------------------------------------------------------------------------------------