Created
August 27, 2018 15:30
-
-
Save andresgcarmona/99fd8bf9c4fa734c2fb5c7d63344e466 to your computer and use it in GitHub Desktop.
Todo model
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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