Skip to content

Commit

Permalink
refactor(actions): make HEADER_DATA_FETCHED an FSA
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmason committed Sep 25, 2017
1 parent 1ea2e4e commit 459fa46
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ export const CHANGE_UI_LOCALE = 'CHANGE_UI_LOCALE'
export const DOCUMENT_SELECTED = 'DOCUMENT_SELECTED'
export const LOCALE_SELECTED = 'LOCALE_SELECTED'
export const STATS_FETCHED = 'STATS_FETCHED'
export const HEADER_DATA_FETCHED = Symbol('HEADER_DATA_FETCHED')
export const HEADER_DATA_FETCHED = 'HEADER_DATA_FETCHED'
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,8 @@ const containsLocale = (localeList, localeId) => {

export const selectDoc = createAction(DOCUMENT_SELECTED)
export const selectLocale = createAction(LOCALE_SELECTED)

export const statsFetched = createAction(STATS_FETCHED)

export function headerDataFetched (data) {
return {type: HEADER_DATA_FETCHED, data: data}
}
export const headerDataFetched = createAction(HEADER_DATA_FETCHED)

// this is a get all action that will wait until all promises are resovled
export function fetchHeaderInfo (projectSlug, versionSlug, docId, localeId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ const gravatarUrl = (hash, size) => {
export default (state = defaultState, action) => {
switch (action.type) {
case HEADER_DATA_FETCHED:
const docs = prepareDocs(action.data.documents)
const locales = prepareLocales(action.data.locales)
const versionSlug = action.data.versionSlug
const projectSlug = action.data.projectInfo.id
const projectName = action.data.projectInfo.name
const name = action.data.myInfo.name
const docs = prepareDocs(action.payload.documents)
const locales = prepareLocales(action.payload.locales)
const versionSlug = action.payload.versionSlug
const projectSlug = action.payload.projectInfo.id
const projectName = action.payload.projectInfo.name
const name = action.payload.myInfo.name
// FIXME server is providing myInfo.imageUrl not gravatarHash
const gravatarHash = action.data.myInfo.gravatarHash
const gravatarHash = action.payload.myInfo.gravatarHash

return updateObject(state, {
user: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ describe('header-data-reducer test', () => {
it('can select document', () => {
const withData = headerDataReducer(undefined, {
type: HEADER_DATA_FETCHED,
data: EXAMPLE_HEADER_DATA
payload: EXAMPLE_HEADER_DATA
})
const selected = headerDataReducer(withData, {
type: DOCUMENT_SELECTED,
Expand All @@ -95,7 +95,7 @@ describe('header-data-reducer test', () => {
it('can incorporate fetched header data', () => {
const withData = headerDataReducer(undefined, {
type: HEADER_DATA_FETCHED,
data: EXAMPLE_HEADER_DATA
payload: EXAMPLE_HEADER_DATA
})
expect(withData).toEqual({
user: {
Expand Down Expand Up @@ -148,7 +148,7 @@ describe('header-data-reducer test', () => {
it('can select locale', () => {
const withData = headerDataReducer(undefined, {
type: HEADER_DATA_FETCHED,
data: EXAMPLE_HEADER_DATA
payload: EXAMPLE_HEADER_DATA
})
const selected = headerDataReducer(withData, {
type: LOCALE_SELECTED,
Expand Down

0 comments on commit 459fa46

Please sign in to comment.