Skip to content

Instantly share code, notes, and snippets.

@dance2die
Created October 18, 2019 23:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dance2die/dc5105212fb76aa64fb0c41cc3389eec to your computer and use it in GitHub Desktop.
Save dance2die/dc5105212fb76aa64fb0c41cc3389eec to your computer and use it in GitHub Desktop.
import { ofType } from "redux-observable";
import { mapTo, tap, delay } from "rxjs/operators";
export const PING = "PING";
export const PONG = "PONG";
export const ping = () => ({ type: PING });
export const pong = () => ({ type: PONG });
export const pingEpic = action$ =>
action$.pipe(
ofType(PING),
delay(1000),
mapTo(pong()),
tap(console.info)
);
export const pongEpic = action$ =>
action$.pipe(
ofType(PONG),
delay(1000),
mapTo(ping()),
tap(console.info)
);
export default function pingReducer(state = { isPinging: false }, action) {
switch (action.type) {
case "PING":
return { isPinging: true };
case "PONG":
return { isPinging: false };
default:
return state;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment