first commit
This commit is contained in:
5
lib/components/shopping_list/action_constants.js
Normal file
5
lib/components/shopping_list/action_constants.js
Normal file
@@ -0,0 +1,5 @@
|
||||
'use strict'
|
||||
|
||||
module.exports = {
|
||||
RECEIVE_SHOPPING_LIST: 'RECEIVE_SHOPPING_LIST',
|
||||
}
|
||||
12
lib/components/shopping_list/actions.js
Normal file
12
lib/components/shopping_list/actions.js
Normal file
@@ -0,0 +1,12 @@
|
||||
'use strict'
|
||||
|
||||
const {RECEIVE_SHOPPING_LIST} = require('./action_constants')
|
||||
|
||||
module.exports = {
|
||||
receivedShoppingList: todos => {
|
||||
return {
|
||||
type: RECEIVE_SHOPPING_LIST,
|
||||
items: todos,
|
||||
}
|
||||
}
|
||||
}
|
||||
20
lib/components/shopping_list/proxy.js
Normal file
20
lib/components/shopping_list/proxy.js
Normal file
@@ -0,0 +1,20 @@
|
||||
'use strict'
|
||||
|
||||
const {receivedShoppingList} = require('./actions')
|
||||
|
||||
module.exports = {
|
||||
// urls that should be called for the remote actions
|
||||
urls: {
|
||||
fetch: 'https://layla.amazon.de/api/todos?type=SHOPPING_ITEM&size=100',
|
||||
},
|
||||
// called after an remote http call to the shopping_list API has been successfully executed
|
||||
postHooks: {
|
||||
// called after the shopping items have been fetched
|
||||
fetch:(store, data) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
store.dispatch(receivedShoppingList(data.values))
|
||||
resolve(data)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
13
lib/components/shopping_list/reducer.js
Normal file
13
lib/components/shopping_list/reducer.js
Normal file
@@ -0,0 +1,13 @@
|
||||
'use strict'
|
||||
const {RECEIVE_SHOPPING_LIST} = require('./action_constants')
|
||||
|
||||
module.exports = (state = {}, action) => {
|
||||
switch (action.type) {
|
||||
case RECEIVE_SHOPPING_LIST:
|
||||
return Object.assign({}, state, {
|
||||
items: action.items
|
||||
})
|
||||
default:
|
||||
return state
|
||||
}
|
||||
}
|
||||
7
lib/components/shopping_list/route.js
Normal file
7
lib/components/shopping_list/route.js
Normal file
@@ -0,0 +1,7 @@
|
||||
'use strict'
|
||||
|
||||
module.exports = {
|
||||
'/shopping_list': (store, params, cb) => {
|
||||
cb(store.getState().shopping_list.items)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user