Last active
July 11, 2018 14:32
-
-
Save luxzeitlos/6bf80fd82288a9293e3d5d2329d504bf to your computer and use it in GitHub Desktop.
New Twiddle
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 DS from 'ember-data'; | |
const {get} = Ember; | |
export default DS.JSONAPIAdapter.extend({ | |
findHasMany (store, snapshot, url, relationship) { | |
if(url === 'ONE') { | |
return new Ember.RSVP.Promise(r => { | |
setTimeout(() => { | |
r({ | |
data: [{ | |
id:'1', | |
type: 'post', | |
},{ | |
id:'2', | |
type: 'post', | |
},{ | |
id:'3', | |
type: 'post', | |
}] | |
}); | |
},3000); | |
}); | |
} else { | |
return new Ember.RSVP.Promise(r => { | |
setTimeout(() => { | |
r({ | |
data: [] | |
}); | |
},4000); | |
}); | |
} | |
}, | |
findRecord (store, type, id, snapshot) { | |
console.log(id); | |
if(id == '1') { | |
return { | |
data: { | |
type: 'my-model', | |
id: '1', | |
relationships: { | |
posts: { | |
links: { | |
related: 'ONE' | |
} | |
} | |
} | |
} | |
} | |
} else { | |
return { | |
data: { | |
type: 'my-model', | |
id: '2', | |
relationships: { | |
posts: { | |
links: { | |
related: 'TWO' | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
}); |
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' | |
}); |
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({ | |
posts: hasMany('post'), | |
}); |
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({ | |
}); |
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.Route.extend({ | |
model() { | |
return Ember.RSVP.hash({ | |
one: this.store.findRecord('my-model', '1'), | |
two: this.store.findRecord('my-model', '2') | |
}); | |
} | |
}); |
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.12.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.12.0", | |
"ember-template-compiler": "2.12.0", | |
"ember-testing": "2.12.0" | |
}, | |
"addons": { | |
"ember-data": "2.12.1" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment