1 | 'use strict';
|
2 |
|
3 | var generateMask = require('./utils').generateMask;
|
4 | var mod$3 = require('./options');var BLUEPRINT = mod$3.BLUEPRINT;var PROVIDER = mod$3.PROVIDER;
|
5 | var mod$4 = require('./constants');var CONTAINER_ALIAS = mod$4.CONTAINER_ALIAS;var CONTEXT_ALIAS = mod$4.CONTEXT_ALIAS;
|
6 |
|
7 | var ALIAS_IDX = 0
|
8 | var VALUE_IDX = 1
|
9 | var TYPE_IDX = 2
|
10 | var DEPS_IDX = 3
|
11 |
|
12 | function createChildContainerFactory(conf) {
|
13 | return function (container) {
|
14 | return container.createChild(conf)
|
15 | }
|
16 | }
|
17 |
|
18 | function createExporter(containerFactory, exportAlias) {
|
19 | return function (container) {
|
20 | return containerFactory(container).get(exportAlias)
|
21 | }
|
22 | }
|
23 |
|
24 | module.exports = function createContext(contribute) {
|
25 |
|
26 | var pending = []
|
27 | var context = {
|
28 |
|
29 | map: function(alias) {
|
30 | context.flush()
|
31 | pending.push(alias)
|
32 |
|
33 | return {
|
34 | to: function(value) {
|
35 |
|
36 | pending.push(value)
|
37 |
|
38 | return {
|
39 | as: function() {var flags=Array.prototype.slice.call(arguments,0);
|
40 | var mask = generateMask(flags)
|
41 |
|
42 | if (mask === BLUEPRINT) {
|
43 |
|
44 | flags = [PROVIDER]
|
45 | pending[VALUE_IDX] = createChildContainerFactory(pending[VALUE_IDX])
|
46 | pending.push(generateMask(flags))
|
47 | pending.push([CONTAINER_ALIAS])
|
48 |
|
49 | return {
|
50 | exports: function(alias) {
|
51 | pending[VALUE_IDX] = createExporter(pending[VALUE_IDX], alias)
|
52 | return {
|
53 | map: context.map
|
54 | }
|
55 | },
|
56 | map: context.map
|
57 | }
|
58 | }
|
59 |
|
60 | pending.push(mask)
|
61 |
|
62 | return {
|
63 | map: context.map,
|
64 |
|
65 | injecting: function() {var deps=Array.prototype.slice.call(arguments,0);
|
66 | pending.push(deps)
|
67 |
|
68 | return {
|
69 | map: context.map
|
70 | }
|
71 | }
|
72 | }
|
73 | }
|
74 | }
|
75 | }
|
76 | }
|
77 | },
|
78 |
|
79 | flush: function() {
|
80 | var deps = pending[DEPS_IDX] || []
|
81 |
|
82 | if (pending.length > 2) {
|
83 | contribute(pending[ALIAS_IDX], pending[VALUE_IDX], pending[TYPE_IDX], deps)
|
84 | pending = []
|
85 | }
|
86 | }
|
87 | }
|
88 |
|
89 | return context
|
90 | } |
\ | No newline at end of file |