Skip to content

Instantly share code, notes, and snippets.

@RickButler
Created November 3, 2017 03:47
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/cb7fd02c74d21267a1ca2481b8bf9503 to your computer and use it in GitHub Desktop.
Save RickButler/cb7fd02c74d21267a1ca2481b8bf9503 to your computer and use it in GitHub Desktop.
var AmpersandModel = require('ampersand-model');
var get = require('lodash/get');
var includes = require('lodash/includes');
AmpersandModel.extend({
session: {
fetched: 'boolean',
saved: 'boolean',
destroyed: 'boolean'
},
constructor: function () {
this.on('sync', function (opts) {
if (get(opts, 'xhr.method') == "GET") {
this.fetched = true;
}
}, this);
this.on('destroy', function (opts) {
this.destroyed = true;
}, this);
this.on('sync', function (opts) {
if (includes(["POST", "PUT", "PATCH"], get(opts, 'xhr.method'))) {
this.saved = true;
}
}, this);
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment