This repository was archived by the owner on Aug 23, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
174 lines (149 loc) · 4.12 KB
/
Copy pathindex.js
File metadata and controls
174 lines (149 loc) · 4.12 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
!function(e){"object"==typeof exports?module.exports=e():"function"==typeof define&&define.amd?define(e):"undefined"!=typeof window?window.sire=e():"undefined"!=typeof global?global.sire=e():"undefined"!=typeof self&&(self.sire=e())}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
'use strict';
/**
* JavaScript module husbandry. Base class for modules, such as applications and
* controllers, that will be responsible for managing the lifecycle of other
* modules, such as models, views, or child controllers. How modules are started
* and stopped is determined by the implementing class via `_start` and `_stop`
* methods.
*
* @class Sire
* @constructor
*/
function Sire() {
/**
* Used modules.
*
* @property _modules
* @type Object
* @private
*/
this._modules = {};
/**
* Started modules.
*
* @property _started
* @type Object
* @private
*/
this._started = [];
}
/**
* Starts some or all registered modules.
*
* @method start
* @param {Object} [arg]*
* @param {String} arg.name
* @param {Object} [arg.options]
* @chainable
*/
Sire.prototype.start = function() {
var i;
var arg;
var module;
var modules = this._modules;
var started = this._started;
var length = arguments.length;
// Start all known modules
if (length === 0) {
for (i in modules) {
if (modules.hasOwnProperty(i)) {
module = modules[i];
started.push(this._start(module));
}
}
return this;
}
// Start specific modules with options
for (i = 0; i < length; i++) {
arg = arguments[i];
module = arg && modules[arg.name];
// Only start known modules
if (module) {
started.push(this._start(module, arg.options));
}
}
return this;
};
/**
* Starts a registered module. Sub classes must implement this method.
*
* @method _start
* @param {Function} module
* @param {Object} [options]
*/
Sire.prototype._start = function(/* module, options */) {
throw new Error('not implemented');
};
/**
* Stops some or all started modules.
*
* @method stop
* @param {Object} [arg]*
* @chainable
*/
Sire.prototype.stop = function() {
var i;
var index;
var instance;
var started = this._started;
var length = arguments.length;
// Stop all started modules
if (length === 0) {
i = started.length;
// Stop in reverse order of creation
while (i--) {
instance = started[i];
this._stop(instance);
}
// Empty array
started.length = 0;
return this;
}
// Stop specific started modules
for (i = 0; i < length; i++) {
instance = arguments[i];
index = started.indexOf(instance);
// Only stop owned modules
if (index >= 0) {
this._stop(instance);
started.splice(index, 1);
}
}
return this;
};
/**
* Stops a started module. Sub classes must implement this method.
*
* @method _stop
* @param {Object} instance
*/
Sire.prototype._stop = function(/* instance */) {
throw new Error('not implemented');
};
/**
* Registers a module to be sired.
*
* @method use
* @param {String|Object} name
* @param {Object} [module]
* @chainable
*/
Sire.prototype.use = function(name, module) {
if (arguments.length === 1) {
module = name;
name = module.name;
}
if (name == null || name === '') {
throw new Error('invalid name');
}
if (module == null) {
throw new Error('invalid module');
}
this._modules[name] = module;
return this;
};
module.exports = Sire;
},{}]},{},[1])
(1)
});