1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00

Fixed server status message in with-redux-observable-example. (#4900)

**Changes:**
- Fixed "was character fetched on server" message by properly passing `isServer`.
- Stop fetching if there was an error (currently it keeps sending requests to the same endpoint every 3 sec)

**Related:**
- https://github.com/zeit/next.js/pull/4818
- https://github.com/zeit/next.js/issues/4724
This commit is contained in:
Kate 2018-08-05 20:56:04 +03:00 committed by Tim Neutkens
parent 919b88509c
commit 05b6891620
3 changed files with 10 additions and 11 deletions

View file

@ -15,7 +15,7 @@ const CharacterInfo = ({character, error, fetchCharacter, isFetchedOnServer = fa
}
<p>
( was character fetched on server? -
(was character fetched on server? -{' '}
<b>{isFetchedOnServer.toString()})</b>
</p>
<style jsx>{`

View file

@ -6,7 +6,7 @@ export const startFetchingCharacters = () => ({
export const stopFetchingCharacters = () => ({
type: types.STOP_FETCHING_CHARACTERS
})
export const fetchCharacter = isServer => ({
export const fetchCharacter = (isServer = false) => ({
type: types.FETCH_CHARACTER,
payload: { isServer }
})

View file

@ -11,12 +11,11 @@ export const fetchUserEpic = (action$, state$) =>
ofType(types.START_FETCHING_CHARACTERS),
mergeMap(action => {
return interval(3000).pipe(
map(x =>
actions.fetchCharacter({
isServer: state$.value.isServer
})
),
takeUntil(action$.ofType(types.STOP_FETCHING_CHARACTERS))
map(x => actions.fetchCharacter()),
takeUntil(action$.ofType(
types.STOP_FETCHING_CHARACTERS,
types.FETCH_CHARACTER_FAILURE
))
)
})
)
@ -31,14 +30,14 @@ export const fetchCharacterEpic = (action$, state$) =>
map(response =>
actions.fetchCharacterSuccess(
response.response,
state$.value.isServer
action.payload.isServer
)
),
catchError(error =>
of(
actions.fetchCharacterFailure(
error.xhr.response,
state$.value.isServer
action.payload.isServer
)
)
)