Skip to content

Instantly share code, notes, and snippets.

@ksol
Created October 20, 2015 22:15
Show Gist options
  • Select an option

  • Save ksol/32fabbc6ad8aa8fbf068 to your computer and use it in GitHub Desktop.

Select an option

Save ksol/32fabbc6ad8aa8fbf068 to your computer and use it in GitHub Desktop.

Revisions

  1. ksol created this gist Oct 20, 2015.
    26 changes: 26 additions & 0 deletions post.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    import Ember from "ember";
    import DS from "ember-data";

    export default DS.Model.extend({
    // Your ED relationships and properties here...
    // ...

    // Custom API
    upvote() {
    this.set('_updateEndpoint', 'upvote');

    let promise = this.save();
    promise.finally(() => this.set('_updateEndpoint', null));

    return promise;
    },

    downvote() {
    this.set('_updateEndpoint', 'downvote');

    let promise = this.save();
    promise.finally(() => this.set('_updateEndpoint', null));

    return promise;
    },
    });