1 | ;
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 |
|
7 | /*
|
8 | Contains all the services, etc. that need to be injected (i.e. Dependency Injection)
|
9 |
|
10 | Only exported to enable testing. You shouldn't be accessing this normally.
|
11 | */
|
12 | var appContext = exports.appContext = {};
|
13 |
|
14 | var app = exports.app = function app() {
|
15 | return appContext;
|
16 | };
|
17 |
|
18 | /*
|
19 | Dependency injection
|
20 |
|
21 | Wrap any function with an additional first parameter of appContext which can be easily
|
22 | destructured.
|
23 |
|
24 | For example: when a function takes a single parameter foo but that function also needs to
|
25 | use the Meteor service and Bar collection it can be constructed as so:
|
26 |
|
27 | const func = ({ Meteor, Bar }, foo) => {
|
28 | ...function here...
|
29 | })
|
30 |
|
31 | export default inject(func)
|
32 |
|
33 | The exported function can then be called (passing 1234 as foo) as follows:
|
34 |
|
35 | fooFunc(1234)
|
36 |
|
37 | This way most of the app becomes pure functions which are easier to understand and test.
|
38 | */
|
39 |
|
40 | exports.default = function (injectedIntoFunc) {
|
41 | if (injectedIntoFunc == null) {
|
42 | throw new ReferenceError(injectedIntoFunc + ' passed to inject');
|
43 | }
|
44 | if (typeof injectedIntoFunc !== 'function') {
|
45 | throw new TypeError('inject called with ' + injectedIntoFunc + ' which is not a function');
|
46 | }
|
47 | return function injectWrapper() {
|
48 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
49 | args[_key] = arguments[_key];
|
50 | }
|
51 |
|
52 | return injectedIntoFunc.call.apply(injectedIntoFunc, [this, appContext].concat(args));
|
53 | };
|
54 | }; |
\ | No newline at end of file |