Permalink
Browse files

FEATURE: display list of restaurants from api

  • Loading branch information...
toranb committed Jun 7, 2018
1 parent 746c59d commit a379ca73c3b3391a0e477ee0f7164c2319ed216e
@@ -0,0 +1,7 @@
import { connect } from 'ember-redux';

const stateToComputed = (state) => ({
restaurants: state.restaurants.all
});

export default connect(stateToComputed)();
@@ -0,0 +1,6 @@
import { combineReducers } from 'redux';
import restaurants from './restaurants';

export default combineReducers({
restaurants
});
@@ -0,0 +1,18 @@
import _ from 'lodash';

const initialState = {
all: undefined
};

export default ((state, action) => {
switch(action.type) {
case 'RESTAURANTS:TRANSFORM_LIST': {
const restaurants = _.keyBy(action.response, restaurant => restaurant.id);
const merged = _.extend({}, state.all, restaurants);
return Object.assign({}, state, {all: merged});
}
default: {
return state || initialState;
}
}
});
@@ -7,6 +7,7 @@ const Router = EmberRouter.extend({
});

Router.map(function() {
this.route('restaurants', {path: '/'});
});

export default Router;
@@ -0,0 +1,13 @@
import fetch from 'fetch';
import { route } from 'ember-redux';

const model = (dispatch) => {
return fetch('/api/restaurants')
.then(fetched => fetched.json())
.then(response => dispatch({
type: 'RESTAURANTS:TRANSFORM_LIST',
response: response.restaurants
}));
};

export default route({model})();
@@ -1,5 +1 @@
{{!-- The following component displays Ember's default welcome message. --}}
{{welcome-page}}
{{!-- Feel free to remove this! --}}

{{outlet}}
{{outlet}}
@@ -0,0 +1 @@
{{yield restaurants}}
@@ -0,0 +1,5 @@
<ul>
{{#each-in @restaurants as |key restaurant|}}
<li>{{restaurant.name}}</li>
{{/each-in}}
</ul>
@@ -0,0 +1,3 @@
<RestaurantItems as |restaurants|>
<RestaurantList @restaurants={{restaurants}} />
</RestaurantItems>
@@ -33,14 +33,22 @@
"ember-cli-sri": "^2.1.0",
"ember-cli-uglify": "^2.0.0",
"ember-export-application-global": "^2.0.0",
"ember-fetch": "^5.0.0",
"ember-load-initializers": "^1.1.0",
"ember-lodash-shim": "^2.0.0",
"ember-maybe-import-regenerator": "^0.1.6",
"ember-redux": "^3.1.1",
"ember-redux-shim": "^2.5.0",
"ember-redux-thunk-shim": "^2.4.0",
"ember-resolver": "^4.0.0",
"ember-source": "~3.2.0",
"ember-symbol-observable": "1.0.1",
"ember-welcome-page": "^3.0.0",
"eslint-plugin-ember": "^5.0.0",
"loader.js": "^4.2.3",
"qunit-dom": "^0.6.2"
"qunit-dom": "^0.6.2",
"redux": "3.7.2",
"redux-thunk": "2.2.0"
},
"engines": {
"node": "^4.5 || 6.* || >= 7.*"
Oops, something went wrong.

0 comments on commit a379ca7

Please sign in to comment.