Skip to content

Instantly share code, notes, and snippets.

@andresgcarmona
Created August 27, 2018 15:30
Show Gist options
  • Save andresgcarmona/99fd8bf9c4fa734c2fb5c7d63344e466 to your computer and use it in GitHub Desktop.
Save andresgcarmona/99fd8bf9c4fa734c2fb5c7d63344e466 to your computer and use it in GitHub Desktop.
Todo model
import {Model} from 'backbone';
class TodoModel extends Model {
constructor(options) {
super(options);
this.urlRoot = '/todo';
}
get idAttribute() {
return '_id';
}
get defaults() {
return {
};
}
get url() {
let base = this.urlRoot || (this.collection && this.collection.url) || '/';
if(this.isNew()) {
return base;
}
return base + '/' + encodeURIComponent(this.id);
}
parse(response) {
if(response.data) {
return response.data;
}
return response;
}
}
export default TodoModel;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment