-
-
Save kumkanillam/593c24e26e7ff7f765fdd56fe02d4677 to your computer and use it in GitHub Desktop.
How to change a component based on route or handlebars condition
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.RESTAdapter.extend({ | |
}); |
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 Eudora from './application'; | |
export default Eudora.extend({ | |
pathForType() { | |
return 'pages'; | |
} | |
}); |
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 Eudora from './application'; | |
export default Eudora.extend({ | |
pathForType() { | |
return 'posts'; | |
} | |
}); |
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', | |
single:Ember.computed('currentRouteName',function(){ | |
if(this.get('currentRouteName') === 'posts.single'){ | |
return true; | |
} | |
return false; | |
}), | |
}); |
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
export function returnJSON(status, body) { | |
return json(...arguments); | |
}; | |
export function json(status, body) { | |
if (arguments.length === 1) { | |
body = status; | |
status = 200; | |
} | |
return [ | |
status, | |
{ "Content-Type": "application/json" }, | |
JSON.stringify(body) | |
]; | |
}; | |
export const server = new Pretender(); | |
export function initialize() { | |
server.handledRequest = function(verb, path, request) { | |
console.log(`handled request to ${verb} ${path}`); | |
} | |
server.unhandledRequest = function(verb, path, request) { | |
console.log(`undhandled request ${verb} ${path}`); | |
} | |
}; | |
export default { | |
name: 'pretender', | |
initialize | |
}; |
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 Model from "ember-data/model"; | |
import attr from "ember-data/attr"; | |
import { belongsTo, hasMany } from "ember-data/relationships"; | |
export default Model.extend({ | |
title: attr(), | |
}); | |
*/ | |
import Model from 'ember-data/model'; | |
import DS from 'ember-data'; | |
const { | |
attr, | |
//belongsTo | |
} = DS; | |
export default Model.extend({ | |
title: attr() | |
}); |
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 Model from 'ember-data/model'; | |
import DS from 'ember-data'; | |
const { | |
attr, | |
//belongsTo | |
} = DS; | |
export default Model.extend({ | |
//user: belongsTo('user'), | |
title: attr(), | |
//excerpt: attr(), | |
//date: attr('string') | |
}); |
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', | |
rootURL: config.rootURL | |
}); | |
Router.map(function() { | |
this.route('posts', function() { | |
this.route('user', { path: '/user/:id' } ); | |
this.route('single', { path: '/:id', } ); | |
}); | |
this.route('pages'); | |
}); | |
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
import Ember from 'ember'; | |
import { server, json } from '../initializers/pretender'; | |
const { | |
Route, | |
set | |
} = Ember; | |
server.map(function() { | |
this.get('/pages', function() { | |
return json( | |
[ | |
{ | |
"id":139, | |
"title":{ | |
"rendered":"test" | |
} | |
} | |
] | |
); | |
}); | |
}); | |
export default Ember.Route.extend({ | |
model(){ | |
return this.store.findAll('page'); | |
}, | |
setupController(controller, model) { | |
set(controller, 'pages', model); | |
} | |
}); |
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'; | |
const { | |
Route, | |
set | |
} = Ember; | |
export default Route.extend({ | |
model() { | |
return this.store.findAll('page'); | |
}, | |
setupController(controller, model) { | |
set(controller, 'pages', model); | |
} | |
}); |
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 { server, json } from '../initializers/pretender'; | |
const { | |
Route, | |
set | |
} = Ember; | |
server.map(function() { | |
this.get('/posts', function() { | |
return json( | |
[ | |
{ | |
"id":139, | |
"title":{ | |
"rendered":"test" | |
} | |
} | |
] | |
); | |
}); | |
}); | |
export default Route.extend({ | |
model() { | |
return this.store.findAll('post'); | |
}, | |
setupController(controller, model) { | |
set(controller, 'posts', model); | |
} | |
}); |
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 { server, json } from '../../initializers/pretender'; | |
const { | |
Route, | |
set | |
} = Ember; | |
server.map(function() { | |
this.get('/posts/139', function() { | |
return json( | |
[ | |
{ | |
"id":139, | |
"title":{ | |
"rendered":"139 post" | |
} | |
} | |
] | |
); | |
}); | |
}); | |
export default Route.extend({ | |
//templateName: 'posts/single', | |
model(params) { | |
return this.store.findRecord('post', params.id); | |
}, | |
setupController(controller, model) { | |
set(controller, 'post', model); | |
} | |
}); |
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.RESTSerializer.extend({ | |
normalizeResponse( store, primaryModelClass, payload, id, requestType) { | |
payload = { pages: payload }; | |
return this._super( store, primaryModelClass, payload, id, requestType ); | |
} | |
}); |
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.RESTSerializer.extend({ | |
normalizeResponse( store, primaryModelClass, payload, id, requestType) { | |
payload = { pages: payload }; | |
return this._super( store, primaryModelClass, payload, id, requestType ); | |
} | |
}); |
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 JSONAPISerializer from 'ember-data/serializers/json-api'; | |
import DS from 'ember-data'; | |
export default DS.RESTSerializer.extend({ | |
normalizeResponse(store,primaryModelClass,payload,id,requestType) { | |
payload = { posts: payload }; | |
//console.log(payload); | |
return this._super(store,primaryModelClass,payload,id,requestType); | |
}, | |
normalizeSingleResponse(store,primaryModelClass,payload,id,requestType) { | |
payload.posts.user = payload.posts.author; | |
delete payload.posts.author; | |
return this._super(store,primaryModelClass,payload,id,requestType); | |
}, | |
normalizeArrayResponse(store,primaryModelClass,payload,id,requestType) { | |
payload.posts.forEach((post) => { | |
post.user = post.author; | |
delete post.author; | |
}); | |
return this._super(store,primaryModelClass,payload,id,requestType); | |
} | |
}); |
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.10.4", | |
"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.7.0", | |
"ember-data": "2.7.0", | |
"ember-template-compiler": "2.7.0", | |
"route-recognizer": "https://rawgit.com/tildeio/route-recognizer/56f5fcec6ae58d8e86b5dc77609809fb91198142/dist/route-recognizer.js", | |
"FakeXMLHttpRequest": "https://rawgit.com/pretenderjs/FakeXMLHttpRequest/23c3a96b5b24f1bfe595867437e4f128a29c2840/fake_xml_http_request.js", | |
"pretender": "https://rawgit.com/pretenderjs/pretender/c6de9afe18b1472aded2592f5a80ad9a26a0e262/pretender.js" | |
}, | |
"addons": {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment