-
-
Save Gaurav0/ca7e7083391a401d4e50 to your computer and use it in GitHub Desktop.
Rollback Relationships
This file contains hidden or 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 Ember from 'ember'; | |
| export default Ember.Controller.extend({ | |
| appName: 'Ember Twiddle' | |
| }); |
This file contains hidden or 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 Ember from 'ember'; | |
| export default Ember.Controller.extend({ | |
| club: Ember.computed.alias('model.club'), | |
| actions: { | |
| change: function(player){ | |
| this.set('club.captain', player); | |
| }, | |
| rollback: function(club){ | |
| console.log('rollback'); | |
| } | |
| } | |
| }); |
This file contains hidden or 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 Ember from 'ember'; | |
| export default Ember.Route.extend({ | |
| init() { | |
| this._super(arguments); | |
| var club = { | |
| "data": | |
| { | |
| "attributes": { | |
| "name": "Benfica", | |
| "location": "Portugal" | |
| }, | |
| "id": "1", | |
| "relationships": { | |
| "captain": { | |
| "data": { | |
| "id": "3", "type": "players" | |
| } | |
| } | |
| }, | |
| "type": "clubs" | |
| } | |
| }; | |
| var players = { | |
| data: [ | |
| { | |
| "attributes": { | |
| "name": "Eusebio Silva Ferreira", | |
| "skill": "Rocket shot", | |
| "games-played": 431 | |
| }, | |
| "id": "3", | |
| "relationships": { | |
| "club": { | |
| "data": { | |
| "id": "1", | |
| "type": "clubs" | |
| } | |
| } | |
| }, | |
| "type": "players" | |
| }, | |
| { | |
| "id": 1, | |
| "attributes": { | |
| "name": "João Vieira Pinto", | |
| "skill": "Thunder kick", | |
| "games-played": 220 | |
| }, | |
| "relationships": { | |
| "club": { | |
| "data": { | |
| "id": "1", | |
| "type": "clubs" | |
| } | |
| } | |
| }, | |
| "type": "players" | |
| } | |
| ] | |
| }; | |
| $.mockjax({ | |
| url: '/clubs/1', | |
| dataType: 'json', | |
| responseText: club | |
| }); | |
| $.mockjax({ | |
| url: '/players', | |
| dataType: 'json', | |
| responseText: players | |
| }); | |
| }, | |
| model: function() { | |
| var store = this.store; | |
| return Ember.RSVP.hash({ | |
| club: store.find('club', 1), | |
| players: store.findAll('player') | |
| }); | |
| } | |
| }); |
This file contains hidden or 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 Ember from 'ember'; | |
| export default $.extend(true, {}, Ember.Mixin.create({ | |
| })); |
This file contains hidden or 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 DS from 'ember-data'; | |
| export default DS.Model.extend({ | |
| name: DS.attr(), | |
| location: DS.attr(), | |
| captain: DS.belongsTo('player') | |
| }); |
This file contains hidden or 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 DS from 'ember-data'; | |
| import Rollback from "../mixins/rollback"; | |
| export default DS.Model.extend({ | |
| name: DS.attr(), | |
| skill: DS.attr(), | |
| gamesPlayed: DS.attr(), | |
| club: DS.belongsTo('club') | |
| }); |
This file contains hidden or 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 Ember from 'ember'; | |
| import config from './config/environment'; | |
| const Router = Ember.Router.extend({ | |
| location: 'none' | |
| }); | |
| Router.map(function() { | |
| }); | |
| export default Router; |
This file contains hidden or 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
| { | |
| "version": "0.6.4", | |
| "EmberENV": { | |
| "FEATURES": {} | |
| }, | |
| "options": { | |
| "enable-testing": false | |
| }, | |
| "dependencies": { | |
| "jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
| "ember": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.4.1/ember.debug.js", | |
| "ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/2.4.0/ember-data.js", | |
| "ember-template-cmompiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.4.1/ember-template-compiler.js", | |
| "jquery-mockjax": "https://cdnjs.cloudflare.com/ajax/libs/jquery-mockjax/1.6.2/jquery.mockjax.js" | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment