Skip to content
Browse files

commission/decommission now happen during resolve/release rather than…

… construct/deconstruct
  • Loading branch information...
1 parent b35871b commit 729743f5e66d5ddf00ced2a2c52cee66896b6860 @neonstalwart neonstalwart committed Aug 17, 2011
Showing with 29 additions and 12 deletions.
  1. +29 −12 model/Model.js
View
41 model/Model.js
@@ -85,8 +85,10 @@ define([
// resolving might be asynchronous
return promise.whenPromise(this.lifecycle.resolve(args), function (component) {
- model.emit('componentResolved', component);
- return component;
+ return promise.when(model.commission(component), function (component) {
+ model.emit('componentResolved', component);
+ return component;
+ });
});
},
@@ -97,8 +99,10 @@ define([
}
// releasing must be synchronous
+ this.decommission(instance);
this.lifecycle.release(instance);
this.emit('componentReleased', instance);
+ return instance;
},
addMixin: function (obj) {
@@ -127,10 +131,8 @@ define([
var Ctor = compose(module, deps, model.mixin, args),
inst = new Ctor();
//inst = compose.create(compose, module, deps, model.mixin, args);
- return promise.seq(model._commissions, inst).then(function (instance) {
- model.emit('componentConstructed', instance);
- return instance;
- });
+ model.emit('componentConstructed', inst);
+ return inst;
});
}
@@ -161,12 +163,8 @@ define([
},
deconstruct: function (instance) {
- var model = this;
-
- return promise.seq(model._decommissions, instance).then(function (instance) {
- model.emit('componentDeconstructed', instance);
- return instance;
- });
+ this.emit('componentDeconstructed', instance);
+ return instance;
},
addCommissioner: function (it) {
@@ -208,6 +206,25 @@ define([
};
},
+ commission: function (inst) {
+ // commission may be asynchronous
+ var model = this;
+ return promise.seq(model._commissions, inst).then(function (instance) {
+ model.emit('componentCommissioned', instance);
+ return instance;
+ });
+ },
+
+ decommission: function (inst) {
+ // decommission is synchronous
+ var model = this;
+ arr.forEach(model._decommissions, function (decommission) {
+ decommission(inst, model);
@neonstalwart
neonstalwart added a note Dec 12, 2011

i don't think i need to pass the model here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ });
+ model.emit('componentDecommissioned', inst);
+ return inst;
+ },
+
destroy: function () {
this.emit('destroyed', this);
}

0 comments on commit 729743f

Please sign in to comment.
Something went wrong with that request. Please try again.