Created
September 14, 2018 04:14
-
-
Save blabadi/822a8b9b061875585ee0846f9b4705da to your computer and use it in GitHub Desktop.
reducer
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 characters
import { combineReducers } from 'redux' | |
import searchFoodResult from './search' | |
const nutracker = combineReducers({ | |
searchFoodResult | |
}) | |
export default nutracker |
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 characters
import {SEARCH_FOOD} from "../actions"; | |
import {instance as foodRepo} from '../repos/FoodRepo'; | |
const searchFoodResult = (state = [], action) => { | |
switch (action.type) { | |
case SEARCH_FOOD: | |
return handleSearch(action.term); | |
default: | |
return state | |
} | |
}; | |
const handleSearch = (term) => { | |
console.log(`in handleSearch ${term}`); | |
const results = foodRepo.findFood(term); | |
const searchResults = results.map(food => { | |
return { | |
key: food.id, | |
text: food.name + ", " + food.unit | |
} | |
}); | |
return searchResults | |
} | |
export default searchFoodResult; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment