Last active
March 30, 2016 17:09
-
-
Save ghedamat/3446d5e4376d99a66d4ccb93a326e079 to your computer and use it in GitHub Desktop.
ember data many many
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({ | |
| namespace: 'api' | |
| }); |
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 Ember from 'ember'; | |
| export function eq(params) { | |
| return params[0] === params[1]; | |
| } | |
| export default Ember.Helper.helper(eq); |
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 { mapBy } from 'ember-computed'; | |
| import Helper from 'ember-helper'; | |
| import get from 'ember-metal/get'; | |
| import observer from 'ember-metal/observer'; | |
| import set from 'ember-metal/set'; | |
| import { isEmpty } from 'ember-utils'; | |
| const { defineProperty } = Ember; | |
| export default Helper.extend({ | |
| compute([byPath, array]) { | |
| set(this, 'array', array); | |
| set(this, 'byPath', byPath); | |
| return get(this, 'content'); | |
| }, | |
| byPathDidChange: observer('byPath', function() { | |
| let byPath = get(this, 'byPath'); | |
| if (isEmpty(byPath)) { | |
| defineProperty(this, 'content', []); | |
| return; | |
| } | |
| defineProperty(this, 'content', mapBy('array', byPath)); | |
| }), | |
| contentDidChange: observer('content', function() { | |
| this.recompute(); | |
| }) | |
| }); |
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.Model.extend({ | |
| post: DS.belongsTo('post'), | |
| tag: DS.belongsTo('tag') | |
| }); |
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.Model.extend({ | |
| title: DS.attr('string'), | |
| body: DS.attr('string'), | |
| postTags: DS.hasMany('postTag') | |
| }); |
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.Model.extend({ | |
| name: DS.attr('string'), | |
| postTags: DS.hasMany('postTag') | |
| }); |
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' | |
| }); | |
| Router.map(function() { | |
| this.route('posts', function() { | |
| }); | |
| this.route('tags', function() { | |
| this.route('show', {path: '/:tag_id'}); | |
| }); | |
| }); | |
| 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'; | |
| export default Ember.Route.extend({ | |
| init() { | |
| this._super(...arguments); | |
| $.mockjax({ | |
| url: '/api/posts', | |
| responseText: { | |
| "posts": [ | |
| { | |
| "id": 1, | |
| "title": "foo", | |
| "body": "foo", | |
| "postTags": [1,2] | |
| }, | |
| { | |
| "id": 2, | |
| "title": "bar", | |
| "body": "bar", | |
| "postTags": [] | |
| } | |
| ] | |
| } | |
| }); | |
| $.mockjax({ | |
| url: '/api/tags', | |
| responseText: { | |
| "tags": [ | |
| { | |
| "id": 1, | |
| "name": "tech", | |
| "postTags": [1] | |
| }, | |
| { | |
| "id": 2, | |
| "name": "food", | |
| "postTags": [2] | |
| } | |
| ] | |
| } | |
| }); | |
| $.mockjax({ | |
| url: '/api/tags/1', | |
| responseText: { | |
| "tag": | |
| { | |
| "id": 1, | |
| "name": "tech", | |
| "postTags": [1] | |
| } | |
| } | |
| }); | |
| $.mockjax({ | |
| url: '/api/tags/2', | |
| responseText: { | |
| "tag": | |
| { | |
| "id": 2, | |
| "name": "food", | |
| "postTags": [2] | |
| } | |
| } | |
| }); | |
| $.mockjax({ | |
| url: '/api/postTags', | |
| responseText: { | |
| "postTags": [ | |
| { | |
| "id": 1, | |
| "post": 1, | |
| "tag": 1 | |
| }, | |
| ] | |
| } | |
| }); | |
| $.mockjax({ | |
| url: '/api/postTags/1', | |
| responseText: { | |
| "postTag": | |
| { | |
| "id": 1, | |
| "post": 1, | |
| "tag": 1 | |
| } | |
| } | |
| }); | |
| $.mockjax({ | |
| url: '/api/postTags/2', | |
| responseText: { | |
| "postTag": | |
| { | |
| "id": 2, | |
| "post": 1, | |
| "tag": 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
| import Ember from 'ember'; | |
| export default Ember.Route.extend({ | |
| redirect() { | |
| this.replaceWith('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.Route.extend({ | |
| model() { | |
| return this.modelFor('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.Route.extend({ | |
| model() { | |
| return this.store.findAll('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
| { | |
| "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": "release", | |
| "ember-data": "release", | |
| "ember-template-compiler": "release", | |
| "jquery-mockjax": "https://cdnjs.cloudflare.com/ajax/libs/jquery-mockjax/1.6.2/jquery.mockjax.js" | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment