From 0493d497066e2e3f8174e9c426324bc68dec392a Mon Sep 17 00:00:00 2001 From: Kevin Lacker Date: Sat, 12 Mar 2016 21:29:40 -0800 Subject: [PATCH] set word reducer --- 2016/Shuffley/index.ios.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/2016/Shuffley/index.ios.js b/2016/Shuffley/index.ios.js index 94f7348..15030e4 100644 --- a/2016/Shuffley/index.ios.js +++ b/2016/Shuffley/index.ios.js @@ -12,13 +12,30 @@ import React, { import Dimensions from 'Dimensions'; // The main Redux reducer for this application -// TODO: implement SET_WORD, SHIFT, replace all setState with this +// TODO: implement SHIFT, replace all setState with this function reduce(state = {}, action) { if (action.type == 'ACTIVATE') { return { ...state, activeIndex: action.index + }; + } + + if (action.type == 'SET_WORD') { + let colors = randomSubset(TILE_COLORS, word.length); + let tiles = []; + for (let i = 0; i < word.length; ++i) { + tiles.push({letter: word[i], color: colors[i]}); } + let location = randomShuffle(range(word.length)); + this.setState({word, tiles, activeIndex: 0, location}); + return { + ...state, + word, + tiles, + activeIndex: 0, + location + }; } return state;