Skip to content

Instantly share code, notes, and snippets.

👌
Enjoying life, including work.

Balint Erdi balinterdi

👌
Enjoying life, including work.
Block or report user

Report or block balinterdi

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@balinterdi
balinterdi / notes.md
Last active Feb 24, 2017
First-class support for JSON API features in Ember Data
View notes.md

As I'm preparing for my EmberConf presentation about "Loading data patterns with JSON API" I realized there are several areas (JSON API features) where Ember Data could go further and provide a more seamless integration between Ember's data layer and the (JSON) API server.

One example of where this integration is already done is the include parameter that can be passed to store.findAll and store.findRecord.

On the other hand, here are a few ones where I think ED could provide a tighter integration:

\1. Querying relationships

View components.my-component-1.js
import Ember from 'ember';
export default Ember.Component.extend({
myFirstAction: '',
actions: {
myComponentAction() {
this.sendAction('myFirstAction');
}
}
});
View components.my-component.js
import Ember from 'ember';
export default Ember.Component.extend({
myColor: 'red',
});
View controllers.application.js
import Ember from 'ember';
function loadAndSave(loadingProperty, operation) {
this.set(loadingProperty, true);
return operation.finally(() => {
this.set(loadingProperty, false);
});
}
export default Ember.Controller.extend({
@balinterdi
balinterdi / songs_controller.rb
Created Sep 23, 2016
Some non-working ways to use jsonapi_resources primitives to craft a response
View songs_controller.rb
class SongsController < ApplicationController
def index
# params[:bandId], params[:q]
serializer = JSONAPI::ResourceSerializer.new(SongResource)
resource = SongResource.new(song, context)
render json: serializer.serialize_to_hash(resource)
end
def index
@balinterdi
balinterdi / destructuring.js
Last active Sep 6, 2016
Fooling around with ES2015 destructurings
View destructuring.js
var pearlJam = {
members: [
{ firstName: 'Eddie', lastName: 'Vedder' },
{ firstName: 'Mike', lastName: 'McCready' },
{ firstName: 'Jeff', lastName: 'Ament' },
]
}
let { members: [ eddieVedder ] } = pearlJam;
let { firstName: eddie } = eddieVedder;
@balinterdi
balinterdi / person.js
Created Jun 20, 2016
Composing `friendships` from the constituent parts - doesn't work
View person.js
export default Model.extend({
name: DS.attr(),
frienderFriendships: DS.hasMany('friendship', { inverse: 'friender' }),
friendedFriendships: DS.hasMany('friendship', { inverse: 'friended' }),
friendships: Ember.computed('frienderFriendships', 'friendedFriendships', function() {
let friendedFriendshipsRel = this.hasMany('friendedFriendships');
let frienderFriendshipsRel = this.hasMany('frienderFriendships');
let frienderFriendships;
@balinterdi
balinterdi / route.js
Created Jun 20, 2016
Eager-fetch belongsTo relationships – does not work
View route.js
model(params) {
return this.store.findRecord('person', params.person_id)
.then((person) => {
return {
friendships: person.get('friendships', { include: 'friender,friended' }),
person
}});
},
View controllers.application.js
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
@balinterdi
balinterdi / app.css
Last active Feb 3, 2016
Binding style attributes warning in Ember
View app.css
body {
margin: 12px 16px;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 12pt;
}
.bordered {
border: 1px solid blue;
height: 100px;
}
You can’t perform that action at this time.