Last active
January 5, 2017 20:34
Revisions
-
toranb revised this gist
Aug 17, 2016 . 8 changed files with 92 additions and 20 deletions.There are no files selected for viewing
This file contains 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 charactersOriginal file line number Diff line number Diff line change @@ -1,15 +1,25 @@ import Ember from 'ember'; import route from 'ember-redux/route'; var model = (dispatch, options) => { //why mirage no work here? var response = {id: options.index, number: options.index}; return dispatch({type: 'TRANSFORM_DETAIL', response: response}); }; var DetailRoute = Ember.Route.extend({ renderTemplate: function(model, options){ var outletName = parseInt(options.response.id, 10).toString(); this.render('items/detail', { 'into': 'items', 'outlet': outletName }); }, actions: { willTransition: function() { this.disconnectOutlet(this.context.response.id); } } }); export default route({model})(DetailRoute); This file contains 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 charactersOriginal file line number Diff line number Diff line change @@ -1 +1 @@ <p>the detail template {{model.response.id}}</p> This file contains 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,8 @@ import fetch from 'fetch'; import route from 'ember-redux/route'; var model = (dispatch) => { return fetch('/api/items').then(fetched => fetched.json()).then(response => dispatch({type: 'TRANSFORM_LIST', response: response})); }; export default route({model})(); This file contains 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,21 @@ export default function() { this.namespace = 'api'; this.get('/items', () => { return { items: [ {id: 1, name: 'one'}, {id: 2, name: 'two'}, {id: 3, name: 'three'} ] }; }); this.get('/items/1', () => { return {id: 1, name: 'one', number: 1}; }); this.get('/items/2', () => { return {id: 1, name: 'two', number: 2}; }); this.get('/items/3', () => { return {id: 1, name: 'three', number: 3}; }); } This file contains 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 charactersOriginal file line number Diff line number Diff line change @@ -1,17 +1,17 @@ import Ember from 'ember'; import hbs from 'htmlbars-inline-precompile'; import connect from 'ember-redux/components/connect'; var stateToComputed = (state) => { return { items: state.items.all }; }; var MyResultsComponent = Ember.Component.extend({ layout: hbs` {{yield items}} ` }); export default connect(stateToComputed)(MyResultsComponent); This file contains 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,5 @@ import items from './items'; export default { items: items }; This file contains 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,18 @@ const initialState = { all: [], selected: null }; export default ((state, action) => { if (action.type === 'TRANSFORM_LIST') { return Object.assign({}, state, { all: action.response.items }); } if (action.type === 'TRANSFORM_DETAIL') { return Object.assign({}, state, { selected: action.response.item }); } return state || initialState; }); This file contains 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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,11 @@ { "version": "0.10.4", "ENV": { "ember-cli-mirage": { "enabled": true, "directory": "app/mirage" } }, "EmberENV": { "FEATURES": {} }, @@ -9,9 +15,13 @@ }, "dependencies": { "jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", "ember": "2.6.2", "ember-data": "2.7.0", "ember-template-compiler": "2.6.2" }, "addons": { "ember-redux": "1.5.0", "ember-fetch": "1.3.0", "ember-cli-mirage": "0.2.1" } } -
toranb revised this gist
Aug 17, 2016 . 5 changed files with 15 additions and 20 deletions.There are no files selected for viewing
This file contains 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 charactersOriginal file line number Diff line number Diff line change @@ -1,13 +1,15 @@ import Ember from 'ember'; export default Ember.Route.extend({ renderTemplate: function(model, options){; this.render('items/detail', { 'into': 'items', 'outlet': options.index }); }, actions: { willTransition: function() { this.disconnectOutlet(this.context.index); } } }); This file contains 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 charactersOriginal file line number Diff line number Diff line change @@ -1 +1 @@ <p>the detail template!</p> This file contains 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 charactersOriginal file line number Diff line number Diff line change @@ -1,7 +0,0 @@ This file contains 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 charactersOriginal file line number Diff line number Diff line change @@ -1 +1,5 @@ {{#my-results as |items|}} {{#my-list items=items as |index|}} {{outlet (plus-one index)}} {{/my-list}} {{/my-results}} This file contains 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 charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,3 @@ {{#app-layout}} {{outlet}} {{/app-layout}} -
toranb created this gist
Aug 17, 2016 .There are no files selected for viewing
This file contains 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,8 @@ import Ember from 'ember'; import hbs from 'htmlbars-inline-precompile'; export default Ember.Component.extend({ layout: hbs` {{yield}} ` }); This file contains 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,5 @@ import Ember from "ember"; export default Ember.Helper.helper(function(params) { return parseInt(params[0], 10) + 1; }); This file contains 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,13 @@ import Ember from 'ember'; export default Ember.Route.extend({ model: function() { return {}; }, renderTemplate: function(){ this.render('items/detail', { 'into':'items', 'outlet': 'main' }); } }); This file contains 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ <p>detail template showing</p> This file contains 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,7 @@ import Ember from 'ember'; export default Ember.Route.extend({ model() { return {}; } }); This file contains 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ {{outlet}} This file contains 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,12 @@ import Ember from 'ember'; import hbs from 'htmlbars-inline-precompile'; export default Ember.Component.extend({ layout: hbs` {{#each items as |item index|}} <div>{{item.name}}</div> {{#link-to "items.detail" (plus-one index)}}details{{/link-to}} {{yield index}} {{/each}} ` }); This file contains 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,17 @@ import Ember from 'ember'; import hbs from 'htmlbars-inline-precompile'; export default Ember.Component.extend({ items: Ember.computed(function() { return [{ id: 1, name: 'one' },{ id: 2, name: 'two' }]; }), layout: hbs` {{yield items}} ` }); This file contains 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,15 @@ import Ember from 'ember'; import config from './config/environment'; const Router = Ember.Router.extend({ location: 'none', rootURL: config.rootURL }); Router.map(function() { this.route('items', {path: '/'}, function() { this.route('detail', {path: '/detail/:index'}); }); }); export default Router; This file contains 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,7 @@ {{#app-layout}} {{#my-results as |items|}} {{#my-list items=items as |index|}} {{outlet "main"}} {{/my-list}} {{/my-results}} {{/app-layout}} This file contains 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,17 @@ { "version": "0.10.4", "EmberENV": { "FEATURES": {} }, "options": { "use_pods": true, "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" }, "addons": {} }