Last active
March 18, 2018 01:33
-
-
Save sheriffderek/a36f22277b81f70dfc2c19259b96f76d to your computer and use it in GitHub Desktop.
pocket-monsters
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 DS from 'ember-data'; | |
export default DS.RESTAdapter.extend({ | |
host:'https://pokeapi.co', | |
namespace: 'api/v2', | |
pathForType() { | |
return 'pokemon'; // because I used 'monster' | |
}, | |
}); |
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: 'pocket-monster routing example' | |
}); |
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 DS from 'ember-data'; | |
import Ember from 'ember'; | |
export default DS.Model.extend({ | |
number: Ember.computed('url', function() { | |
var fullUrl = this.get('url'); | |
// https://jsfiddle.net/sheriffderek/0rLjraob/ | |
return fullUrl.split('/')[6]; // cheap way to find the monster id in the url? | |
// maybe this should happen in a serializer? | |
}), | |
name: DS.attr(), | |
slug: Ember.computed('name', function() { | |
return this.get('name').dasherize(); | |
}), | |
url: DS.attr(), | |
}); |
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('monsters', { path: '/' }, function() { | |
this.route('monster-list', { path: '/' }); | |
this.route('monster-detail', { path: '/:monsterId' }); | |
}); | |
}); | |
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({ | |
}); |
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() { | |
var monsterData = this.get('store').findAll('monster'); | |
console.log(monsterData); | |
return monsterData; | |
}, | |
}); |
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({ | |
}); |
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) { | |
var monster = this.store.peekRecord('monster', params.monsterId); | |
// this is pointy... ? not sure - | |
// see the dynamic segment in the router | |
// and see the link-to + the 'id' / number we're deriving from the model url | |
console.log('incomming monster', monster); | |
return monster; | |
}, | |
}); |
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({ | |
}); |
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 DS from 'ember-data'; | |
export default DS.RESTSerializer.extend({ | |
primaryKey: 'url', // seems like 'number' would be good... but it's computed | |
// are these parameters correct? | |
normalizeResponse(store, primaryModelClass, payload, id, requestType) { | |
payload = { | |
monster: payload.results, | |
}, | |
console.log('payload', payload); | |
console.log('id', id); // just curious | |
return this._super(store, primaryModelClass, payload, id, requestType); | |
}, | |
}); |
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.13.0", | |
"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.16.2", | |
"ember-template-compiler": "2.16.2", | |
"ember-testing": "2.16.2" | |
}, | |
"addons": { | |
"ember-data": "2.16.3" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment