Permalink
Browse files

Merge branch 'issue-141' into dev

  • Loading branch information...
2 parents 70aa107 + 27d4140 commit 841789cdd6f9a8367afc3c4992b3f2e504c238dd @briancavalier briancavalier committed Nov 26, 2013
Showing with 32 additions and 22 deletions.
  1. +19 −11 lib/scope.js
  2. +10 −10 test/node/context-test.js
  3. +3 −1 test/node/lib/plugin/basePlugin-test.js
View
@@ -263,10 +263,11 @@ define(function(require) {
},
_parseSpec: function(spec) {
- var instances, components, plugins, id, d;
+ var instances, components, ready, plugins, id, initialized, ready;
instances = this.instances;
components = this.components;
+ ready = {};
// Setup a promise for each item in this scope
for (id in spec) {
@@ -276,25 +277,29 @@ define(function(require) {
// An initializer may have inserted concrete components
// into the context. If so, they override components of the
// same name from the input spec
- d = defer();
- components[id] = this._createComponentDef(id, spec[id], d.resolver);
- instances[id] = d.promise;
+ initialized = defer();
+ ready = defer();
+ components[id] = this._createComponentDef(id, spec[id], initialized, ready);
+ instances[id] = initialized.promise;
+ ready[id] = ready.promise;
}
}
return {
plugins: plugins,
components: components,
- instances: instances
+ instances: instances,
+ ready: ready
};
},
- _createComponentDef: function(id, spec, resolver) {
+ _createComponentDef: function(id, spec, initialized, ready) {
return {
id: id,
spec: spec,
path: this._createPath(id, this.path),
- resolver: resolver
+ initialized: initialized,
+ ready: ready
};
},
@@ -311,9 +316,9 @@ define(function(require) {
},
_awaitInstances: function(parsed) {
- var instances = parsed.instances;
- return when.map(Object.keys(instances), function(id) {
- return instances[id];
+ var ready = parsed.ready;
+ return when.map(Object.keys(ready), function(id) {
+ return ready[id];
});
},
@@ -331,7 +336,7 @@ define(function(require) {
return WireProxy.getTarget(resolved);
});
- component.resolver.resolve(item);
+ component.ready.resolve(item);
return item;
},
@@ -345,6 +350,9 @@ define(function(require) {
if(component.proxy) {
this._instanceToProxy.set(inst, component.proxy);
}
+ if(component.initialized) {
+ component.initialized.resolve(inst);
+ }
}
return instance;
@@ -258,7 +258,7 @@ buster.testCase('context', {
);
},
- 'should process component lifecycle': function() {
+ 'should process component lifecycle': function(done) {
var spy = this.spy(function(resolver) {
resolver.resolve();
});
@@ -267,22 +267,22 @@ buster.testCase('context', {
return {
context: {
initialize: function(resolver, wire) {
- wire.addComponent({}, 'instance');
+ wire.addComponent({}, 'instance').then(
+ function() {
+ assert.called(spy);
+ done();
+ },
+ fail
+ );
+
resolver.resolve();
}
},
initialize: spy
}
}
- return createContext({
- plugins: [plugin]
- }).then(
- function() {
- assert.called(spy);
- },
- fail
- );
+ createContext({ plugins: [plugin] });
}
}
}
@@ -832,7 +832,9 @@ buster.testCase('lib/plugin/basePlugin', {
t1: {
literal: {},
properties: {
- f: { literal: spy }
+ f: function(x) {
+ spy(x);
+ }
}
},
component: {

0 comments on commit 841789c

Please sign in to comment.