Skip to content

Instantly share code, notes, and snippets.

@iuliaL iuliaL/snippet.tsx
Last active Sep 5, 2019

Embed
What would you like to do?
redux-loop Cmd.map()
// from a navigation view
function reducer(
state: State,
action: Action
): [State, reduxLoop.CmdType<Action>] {
switch (action.type) {
case "INIT OPERATOR VIEW": {
const newState: State = {
...state,
page: {
name: "operator",
state: operator.init,
timerId: Maybe.nothing<TimerId>(),
maxHeats: 5,
heats: {
status: "unloaded",
}
}
};
return [newState, reduxLoop.Cmd.none];
}
case "OPERATOR VIEW ACTION": {
if (state.page.name !== "operator") {
return [state, reduxLoop.Cmd.none];
}
const [newOperatorViewState, newOperatorViewCmd]
: [operator.State, reduxLoop.CmdType<operator.Action>]
= operator.reducer(state.page.state, action.action);
const newState: State = {
...state,
page: {
...state.page,
name: "operator",
state: newOperatorViewState
}
};
const newCmd: reduxLoop.CmdType<ViewAction> = reduxLoop.Cmd.map(
newOperatorViewCmd,
(viewAction: operator.Action): ViewAction => {
return { type: "OPERATOR VIEW ACTION", action: viewAction };
});
return [newState, newCmd];
}
case "LOGOUT": {...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.