Last active
November 10, 2016 01:08
-
-
Save akatov/7b477742dd572640a8c384f64e0b8f59 to your computer and use it in GitHub Desktop.
Barrels And Casks App
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 Adapter from 'ember-data/adapter'; | |
import Game from '../models/game'; | |
import RSVP from 'rsvp'; | |
var globalId = 0; | |
export default Adapter.extend({ | |
findRecord(store, type, id) { | |
console.log('find'); | |
return RSVP.resolve({ id }); | |
}, | |
createRecord(store, type, snapshot) { | |
console.log('create', arguments); | |
if (type.modelName === 'game') { | |
console.log('creating game'); | |
snapshot = snapshot || {}; | |
snapshot.id = ++globalId; | |
return RSVP.resolve(snapshot); | |
} else { | |
return RSVP.reject('unknown type'); | |
} | |
}, | |
updateRecord(store, type, snapshot) { | |
console.log('update'); | |
// already pushed into store, no need to persist | |
return RSVP.resolve(); | |
} | |
}); |
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 Ember from 'ember'; | |
export default Ember.Controller.extend({ | |
appName: 'Ember Twiddle', | |
init() { | |
this._super(); | |
// this.set('conn', new WebSocket('ws://localhost:7535')); | |
}, | |
}); |
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 "ember-data/model"; | |
import attr from "ember-data/attr"; | |
import { belongsTo, hasMany } from "ember-data/relationships"; | |
export default Model.extend({ | |
address: 'ws://localhost:7535', | |
start() { | |
let connection = new WebSocket(this.get('address')); | |
this.set('connection', connection); | |
}, | |
finish() { | |
this.get('connection').close(); | |
} | |
}); |
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 Ember from 'ember'; | |
import config from './config/environment'; | |
const Router = Ember.Router.extend({ | |
location: 'none', | |
rootURL: config.rootURL | |
}); | |
Router.map(function() { | |
this.route('index', { path: '/' }); | |
this.route('new', { path: '/new' }); | |
this.route('show', { path: '/:id'}); | |
}); | |
export default Router; |
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 Ember from 'ember'; | |
export default Ember.Route.extend({ | |
model() { | |
return this.store.peekAll('game'); | |
} | |
}); |
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 Ember from 'ember'; | |
export default Ember.Route.extend({ | |
model() { | |
return this.store.createRecord('game'); | |
}, | |
actions: { | |
start(game) { | |
game.save().then(() => { | |
game.start(); | |
this.transitionTo('show', game); | |
}); | |
} | |
} | |
}); |
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 Ember from 'ember'; | |
export default Ember.Route.extend({ | |
model(params) { | |
console.log('show', arguments); | |
}, | |
actions: { | |
willTransition(transition) { | |
let game = this.modelFor('show'); | |
game.finish(); | |
game.save(); | |
} | |
} | |
}); |
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
{ | |
"version": "0.10.6", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"ember": "2.9.0", | |
"ember-data": "2.9.0", | |
"ember-template-compiler": "2.9.0", | |
"ember-testing": "2.9.0" | |
}, | |
"addons": {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment