-
-
Save antronic/2a8efc81b064bfbb18e771a6d5af2446 to your computer and use it in GitHub Desktop.
pokedex-react-1.js
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
// 1. set Reducer function to accept store.dispatch() | |
var reducer = function (state, action) { | |
var newState = state; | |
if (typeof state === 'undefined') { | |
return { | |
pokemonType: null, | |
pokemonAtk: null | |
}; | |
} | |
switch (action.type) { | |
case 'CHANGE_POKEMON_TYPE': | |
newState.pokemonType = action.pokemonType; | |
return newState; | |
case 'CHANGE_POKEMON_ATK': | |
newState.pokemonAtk = (action.pokemonAtk && action.pokemonAtk.length > 0) ? action.pokemonAtk : null; | |
return newState; | |
default: | |
return null; | |
} | |
}; | |
var store = Redux.createStore(reducer); | |
// 2. set Listener to dispatch such event | |
document.getElementById('pokemonTypeFilter') | |
.addEventListener('change', function (e) { | |
store.dispatch({ type: 'CHANGE_POKEMON_TYPE', pokemonType: e.target.value }) | |
}); | |
document.getElementById('pokemonAtkFilter') | |
.addEventListener('keyup', function (e) { | |
store.dispatch({ type: 'CHANGE_POKEMON_ATK', pokemonAtk: e.target.value }) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment