2

I want to detect a change in a new record. However, the record is new and dirty from the moment I create it.

   var record = transaction.createRecord(App.ContentOfSomeSort, data);
   record.get('isNew'); // true
   record.get('isDirty'); // true

Is there an event or property that I can observe/listen for that tells me when the record has changed? I would think that isDirty would be good for this, but it's dirty as soon as I create it.

Evil Buck
  • 1,068
  • 7
  • 20

3 Answers3

0

It looks like didSetProperty might be what you are looking for

https://github.com/emberjs/data/blob/master/packages/ember-data/lib/system/model/attributes.js#L65

Cyril Fluck
  • 1,561
  • 7
  • 9
  • 2
    just a tip about linking to specific line in github repos. please add a blob to your URL, instead of using master. this way, your link gets invalid when master updates. thanks! :) – shime Oct 18 '13 at 14:43
0

Object.keys(model.changedAttributes()).length === 0 will work if you're just checking for plain attributes. changedAttributes() has an open issue right now where it will not report if relationships on the model have been changed.

adam
  • 1
-1

I don't know ember.js (maybe there's some native function/event in it?), but can't it be done by setting interval which compares previous record value with actual one?

ghost
  • 769
  • 5
  • 11
  • yes. I could, but I won't do that. I'd set an observer for all the fields of the ember-data record that would set a changed state before using an interval. I'm hoping that ember has an underlying mechanism that I can use to check that before re-inventing the wheel. – Evil Buck Apr 23 '13 at 00:09
  • which change do you want to detect? – Cyril Fluck Apr 23 '13 at 00:29
  • A change to any of the attributes. Ideally it would fire an event and I could listen to it. Something like record.on('update', function(){}), but a property change would work just as well too. – Evil Buck Apr 23 '13 at 03:51