Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Model callbacks also available as events

  • Loading branch information...
commit 6c83c7807f52f391eef0d5e8259679f963070adf 1 parent 8764ee7
Andrey Ivashchenko authored
15 packages/ember-data/lib/system/model/model.js
View
@@ -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.
6 packages/ember-data/lib/system/model/states.js
View
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.