Skip to content

Commit

Permalink
refactor(actions): make PHRASE_SUGGESTION_FINISHED_COPYING an FSA
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmason committed Sep 25, 2017
1 parent c2da368 commit dd5f005
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
Expand Up @@ -9,7 +9,7 @@ export const TEXT_SUGGESTION_FINISHED_COPYING =
export const PHRASE_SUGGESTION_STARTED_COPYING =
'PHRASE_SUGGESTION_STARTED_COPYING'
export const PHRASE_SUGGESTION_FINISHED_COPYING =
Symbol('PHRASE_SUGGESTION_FINISHED_COPYING')
'PHRASE_SUGGESTION_FINISHED_COPYING'
export const TEXT_SUGGESTIONS_UPDATED = Symbol('TEXT_SUGGESTIONS_UPDATED')
export const SUGGESTION_SEARCH_TEXT_CHANGE =
Symbol('SUGGESTION_SEARCH_TEXT_CHANGE')
Expand Down
Expand Up @@ -110,6 +110,9 @@ const textSuggestionFinishedCopying =

const phraseSuggestionStartedCopying = createAction(
PHRASE_SUGGESTION_STARTED_COPYING, (phraseId, index) => ({ phraseId, index }))
const phraseSuggestionFinishedCopying = createAction(
PHRASE_SUGGESTION_FINISHED_COPYING,
(phraseId, index) => ({ phraseId, index }))

function copyTextSuggestionN (index) {
return (dispatch, getState) => {
Expand Down Expand Up @@ -138,10 +141,6 @@ function copyPhraseSuggestionN (phraseId, index) {
}
}

function phraseSuggestionFinishedCopying (phraseId, index) {
return { type: PHRASE_SUGGESTION_FINISHED_COPYING, phraseId, index }
}

export function textSuggestionsUpdated (
{loading, searchStrings, suggestions, timestamp}) {
return {
Expand Down
Expand Up @@ -46,9 +46,9 @@ const suggestions = (state = defaultState, action) => {
case PHRASE_SUGGESTION_FINISHED_COPYING:
return update({
searchByPhrase: {
[action.phraseId]: {
[action.payload.phraseId]: {
suggestions: {
[action.index]: {copying: {$set: false}}
[action.payload.index]: {copying: {$set: false}}
}
}
}
Expand Down
Expand Up @@ -77,8 +77,10 @@ describe('suggestions-reducer test', () => {
})
const doneCopying = suggestionsReducer(copying, {
type: PHRASE_SUGGESTION_FINISHED_COPYING,
phraseId: 'p01',
index: 1
payload: {
phraseId: 'p01',
index: 1
}
})
expect(copying.searchByPhrase['p01'].suggestions[1].copying).toEqual(true)
expect(doneCopying.searchByPhrase['p01'].suggestions[1].copying)
Expand Down

0 comments on commit dd5f005

Please sign in to comment.