Skip to content

Instantly share code, notes, and snippets.

@kasunvp
Last active July 18, 2018 18:16
Show Gist options
  • Save kasunvp/39522462b9fa4eb7e5fd53625b8ba9ea to your computer and use it in GitHub Desktop.
Save kasunvp/39522462b9fa4eb7e5fd53625b8ba9ea to your computer and use it in GitHub Desktop.
New Twiddle
import DS from 'ember-data';
const { RESTAdapter } = DS;
export default RESTAdapter.extend({
host: 'https://api.github.com'
});
import ApplicationAdapter from './application';
export default ApplicationAdapter.extend({
handleResponse(status, headers, payload, requestData) {
return {
repositories: payload
}
}
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
import Model from 'ember-data/model';
import attr from 'ember-data/attr';
export default Model.extend({
name: attr('string'),
fullName: attr('string'),
url: attr('string')
});
import EmberRouter from '@ember/routing/router';
import config from './config/environment';
const Router = EmberRouter.extend({
location: 'none',
rootURL: config.rootURL
});
Router.map(function() {
this.route('repositories');
});
export default Router;
import Ember from 'ember';
export default Ember.Route.extend({
model() {
return this.store.findAll('repository');
}
});
import DS from 'ember-data';
export default DS.RESTSerializer.extend({
});
import ApplicationSerializer from './application';
import { camelize } from '@ember/string';
export default ApplicationSerializer.extend({
extractAttributes(modelClass, resourceHash) {
let attributes = {};
Object.keys(resourceHash).forEach((key) => {
attributes[camelize(key)] = resourceHash[key];
});
return attributes;
}
});
{{#link-to 'application'}}Home{{/link-to}}<br>
{{#link-to 'repositories'}}Repositories{{/link-to}}
{{outlet}}
<br>
<br>
<h1>Public Repositories</h1>
{{#each model as |repo|}}
Id: {{repo.id}}<br>
Name: {{repo.name}}<br>
Full name: {{repo.fullName}}<br>
Url: {{repo.url}}<hr>
{{/each}}
{
"version": "0.15.0",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js",
"ember": "3.2.2",
"ember-template-compiler": "3.2.2",
"ember-testing": "3.2.2"
},
"addons": {
"ember-data": "3.2.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment