@fguillen wrote:
I am trying to monitor the state changes on my DS Models.
I have found interesting flags in the documentation:
And they work properly in the templates, I can play with the
{{#if model.isLoading}}Is Loading{{/if}}
, for example.But what is very disturbing is that the observers in these flags have a very random behavior. For example I have found that the observer over the flat
isSaving
doesn't work at all. But the observer over the flagisReloading
works perfectly.Here I have a full example of what I'm have tried until now. I have included this Mixin into my Model:
// app/models/mixins/loading-monitoring import Ember from 'ember'; export default Ember.Mixin.create({ isReloadingDidChange: Ember.observer('isReloading', function() { console.log('LOG: isReloadingDidChange', this.get('id'), this.get('isReloading')); }), isSavingDidChange: Ember.observer('isSaving', function() { console.log('LOG: isSavingDidChange', this.get('id'), this.get('isSaving')); }), isLoadingDidChange: Ember.observer('isLoading', function() { console.log('LOG: isLoadingDidChange', this.get('id'), this.get('isLoading')); }), isLoadedDidChange: Ember.observer('isLoaded', function() { console.log('LOG: isLoadedDidChange', this.get('id'), this.get('isLoaded')); }), onInit: Ember.on('init', function() { console.log('LOG: init', this.get('id')); }), onDidLoad: Ember.on('didLoad', function() { console.log('LOG: onDidLoad', this.get('id')); }), });
And I try to invoke all these observers but only some ones are triggered:
> $E.toString() "<reports-dashboard-client-app@route:application::ember1553>" > var report; $E.store.findRecord('report', 14).then(function(r) { report = r }); Promise {_id: 438, _label: undefined, _state: undefined, _result: undefined, _subscribers: Array[0]} LOG: init 14 XHR finished loading: GET "http://myapi.com/reports/14". LOG: onDidLoad 14 > report.toString() "<reports-dashboard-client-app@model:report::ember1554:14>" > report.get('title') "new title" > report.set('title', 'title modified') "title modified" > report.save() Class {__ember1453996199577: null, __ember_meta__: Meta} XHR finished loading: PUT "http://myapi.com/reports/14".send @ jquery.js:8630jQuery.extend.ajax @ jquery.js:8166(anonymous function) @ rest-adapter.js:764initializePromise @ ember.debug.js:52308Promise @ ember.debug.js:54158ember$data$lib$system$adapter$$default.extend.ajax @ rest-adapter.js:729ember$data$lib$system$adapter$$default.extend.updateRecord @ rest-adapter.js:544ember$data$lib$system$store$$_commit @ store.js:1930(anonymous function) @ store.js:1225ember$data$lib$system$store$$Service.extend.flushPendingSave @ store.js:1208Queue.invoke @ ember.debug.js:320Queue.flush @ ember.debug.js:384DeferredActionQueues.flush @ ember.debug.js:185Backburner.end @ ember.debug.js:563(anonymous function) @ ember.debug.js:1154 > report.reload() LOG: isReloadingDidChange 14 true Class {__ember1453996199577: null, __ember_meta__: Meta} XHR finished loading: GET "http://myapi.com/reports/14".send @ jquery.js:8630jQuery.extend.ajax @ jquery.js:8166(anonymous function) @ rest-adapter.js:764initializePromise @ LOG: isReloadingDidChange 14 false
What am I missing?
Posts: 1
Participants: 1