Skip to content

Instantly share code, notes, and snippets.

@RickButler
Last active January 12, 2016 14:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RickButler/4514ba475e2e282f6077 to your computer and use it in GitHub Desktop.
Save RickButler/4514ba475e2e282f6077 to your computer and use it in GitHub Desktop.
An ampersand model that replaces the idAttribtue in isNew with fetched property that is set after the model performs a get/fetch, this property can also be used for waitFor.
var Model = require('ampersand-model');
var _ = require('lodash');
module.exports = Model.extend({
constructor: function(){
Model.apply(this, arguments);
_.bindAll(this, 'onSync');
this.on('sync', this.onSync);
},
isNew: function(){
return !this.fetched;
},
session:{
fetched: ['boolean', true, false],
},
onSync: function (model, resp, options) {
if (options.xhr.method === "GET") {
this.fetched = true;
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment