1 | Message = require './message'
|
2 | _ = require 'underscore'
|
3 |
|
4 | module.exports = class
|
5 |
|
6 | |
7 |
|
8 |
|
9 | constructor: (@router) ->
|
10 | @_pluginsByName = {}
|
11 | @_using = [];
|
12 |
|
13 | using: () -> @_using
|
14 |
|
15 | |
16 |
|
17 |
|
18 | add: (plugin) ->
|
19 |
|
20 | if plugin instanceof Array
|
21 | for plg in plugin
|
22 | @add plg
|
23 | return
|
24 |
|
25 | @_using.push plugin
|
26 |
|
27 |
|
28 | mod = plugin @router
|
29 |
|
30 |
|
31 | @_pluginsByName[mod.name] = mod
|
32 |
|
33 |
|
34 | _.extend @router._messageBuilder, mod.message
|
35 |
|
36 |
|
37 |
|
38 | _.extend @router, mod.router
|
39 |
|
40 |
|
41 | @router.directors[mod.name] = mod.director if mod.director
|
42 |
|
43 |
|
44 | |
45 |
|
46 |
|
47 | get: (name) -> @_pluginsByName[name]
|
48 |
|
49 |
|
50 | |
51 |
|
52 |
|
53 |
|
54 | newListener: (listener) -> @_emit 'newListener', listener
|
55 |
|
56 |
|
57 | |
58 |
|
59 |
|
60 | _emit: (type, data) ->
|
61 | for pluginName of @_pluginsByName
|
62 | plugin = @_pluginsByName[pluginName]
|
63 | plugin[type](data) if plugin[type]
|
64 |
|