Skip to content

Instantly share code, notes, and snippets.

@mydea
Last active June 2, 2016 15:28
Show Gist options
  • Save mydea/f93d7e772cba9159f73e567a4b52a186 to your computer and use it in GitHub Desktop.
Save mydea/f93d7e772cba9159f73e567a4b52a186 to your computer and use it in GitHub Desktop.
Ember Bug Showcase
import DS from 'ember-data';
export default DS.RESTAdapter.extend();
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
import Ember from 'ember';
export default Ember.Controller.extend({
reloadChecker: null,
actions: {
reloadModel() {
let model = this.get('model');
model.reload().then(() => {
console.log(model.get('count'));
this.set('reloadChecker', model.get('countProp'));
});
}
}
});
let count = 0;
function setupMockjax() {
$.mockjax({
url: "/posts",
// responseTime: 200,
responseText: { posts: [{ id: 1, author: 1 }, { id: 2, author: 2}] },
});
$.mockjax({
url: "/users/1",
responseTime: 200,
response() {
count++;
this.responseText = { user: { id: 1, email: 'foo', count } };
}
});
$.mockjax({
url: "/users/2",
responseTime: 200,
responseText: { user: { id: 2, email: 'bar' } }
});
}
export default {
name: 'mockjax',
initialize: function(application) {
application.deferReadiness();
$.getScript('https://cdnjs.cloudflare.com/ajax/libs/jquery-mockjax/1.6.2/jquery.mockjax.js').then(() => {
setupMockjax();
application.advanceReadiness();
});
}
};
import DS from 'ember-data';
export default DS.Model.extend({
author: DS.belongsTo('user', { async: true }),
});
import DS from 'ember-data';
import Ember from 'ember';
export default DS.Model.extend({
email: DS.attr('string'),
count: DS.attr('number'),
countProp: Ember.computed('count', function() {
return `${this.get('count')} - PROP`;
})
});
import Ember from 'ember';
import config from './config/environment';
const Router = Ember.Router.extend({
location: 'none'
});
Router.map(function() {
this.route('user', { path: '/users/:email' });
});
export default Router;
import Ember from 'ember';
export default Ember.Route.extend({
model() {
return this.store.findAll('post');
}
});
import Ember from 'ember';
export default Ember.Route.extend({
model(params) {
return this.store.find('user', { email: params.email} ).get('firstObject');
},
serialize(model) {
return model.get('email');
}
});
import DS from 'ember-data';
export default DS.RESTSerializer.extend();
<h1>Link-to and Route#serialize issue</h1>
<br>
<br>
{{outlet}}
<br>
<br>
{{#each model as |m|}}
{{#link-to 'user' m.author}}
author ({{m.author.email}})
{{/link-to}}
<br>
{{/each}}
{{model.email}}
{{link-to "back" 'index'}}
<br><br>
<div>
<button {{action 'reloadModel'}}>Reload Model</button>
<br>Reloaded Value: {{reloadChecker}}
</div>
{
"version": "0.7.1",
"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.5.1",
"ember-data": "2.5.1",
"ember-template-compiler": "2.5.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment