Permalink
Browse files

Model callbacks also available as events

  • Loading branch information...
1 parent 8764ee7 commit 6c83c7807f52f391eef0d5e8259679f963070adf @caligo-mentis committed Apr 10, 2012
Showing with 16 additions and 5 deletions.
  1. +13 −2 packages/ember-data/lib/system/model/model.js
  2. +3 −3 packages/ember-data/lib/system/model/states.js
@@ -7,7 +7,7 @@ var retrieveFromCurrentState = Ember.computed(function(key) {
return get(getPath(this, 'stateManager.currentState'), key);
}).property('stateManager.currentState').cacheable();
-DS.Model = Ember.Object.extend({
+DS.Model = Ember.Object.extend(Ember.Evented, {
isLoaded: retrieveFromCurrentState,
isDirty: retrieveFromCurrentState,
isSaving: retrieveFromCurrentState,
@@ -300,7 +300,18 @@ DS.Model = Ember.Object.extend({
}
}
}, this);
- }, 'data')
+ }, 'data'),
+
+ /**
+ @private
+
+ Override the default event firing from Ember.Evented to
+ also call methods with the given name.
+ */
+ fire: function(name) {
+ this[name].apply(this, [].slice.call(arguments, 1));
+ this._super.apply(this, arguments);
+ }
});
// Helper function to generate store aliases.
@@ -388,7 +388,7 @@ var createdState = DirtyState.create({
// EVENTS
invokeLifecycleCallbacks: function(manager, model) {
- model.didCreate();
+ model.fire('didCreate');
}
});
@@ -397,7 +397,7 @@ var updatedState = DirtyState.create({
// EVENTS
invokeLifecycleCallbacks: function(manager, model) {
- model.didUpdate();
+ model.fire('didUpdate');
}
});
@@ -453,7 +453,7 @@ var states = {
// TRANSITIONS
exit: function(manager) {
var model = get(manager, 'model');
- model.didLoad();
+ model.fire('didLoad');
},
// EVENTS

0 comments on commit 6c83c78

Please sign in to comment.