Dirty model after fetching

After creating & fetching a model from a remote source, the model's dirty property gets set to true. For example something like this:

enyo.kind({
	name: "TestModel",
	kind: "enyo.Model",
	url: "path to data",
	observers: {
		watchName: ["name"]
	},
	watchName: function(previous, current, property) {
		console.log("dirty = " + this.dirty)
	}
});

var myModel = new TestModel();
myModel.fetch();
results in a dirty model after the fetch. I think I get why this is the case but since I think dirty is there to indicate that a commit needs to happen I'm wondering if maybe dirty should not be set to true after fetches? Or am I missing something here?

Comments

  • The dirty flag gets cleared after the notifications are fired. If you want to know if the update is due to a fetch, you could override didFetch in your model and set a different flag before calling sup.apply() so you know you're in an fetch callback.
  • Thanks for that, makes sense but to be clear this doesn't seem like appropriate default behavior does it? i.e. that after a fetch the default of the dirty flag is to indicate that the data just fetched should be re-committed to the source. Wanted to get others thoughts before filing a bug.
  • I agree it does seem odd. My guess it was done to reuse the existing setObject/set code but that could have been refactored. Not sure if there are other things that expect the dirty flag in this scenario. I couldn't see one quickly searching.
  • Ok thanks for confirming my sanity here. Bug filed here - https://enyojs.atlassian.net/browse/ENYO-3843
Sign In or Register to comment.