Skip to content

Instantly share code, notes, and snippets.

@blabadi
Created September 14, 2018 04:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blabadi/822a8b9b061875585ee0846f9b4705da to your computer and use it in GitHub Desktop.
Save blabadi/822a8b9b061875585ee0846f9b4705da to your computer and use it in GitHub Desktop.
reducer
import { combineReducers } from 'redux'
import searchFoodResult from './search'
const nutracker = combineReducers({
searchFoodResult
})
export default nutracker
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