Last active
April 11, 2020 01:10
-
-
Save cellog/1e4a9878859fbd32fa11c66db7402705 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Available variables: | |
// - Machine | |
// - interpret | |
// - assign | |
// - send | |
// - sendParent | |
// - spawn | |
// - raise | |
// - actions | |
// - XState (all XState exports) | |
const commonActions = { | |
SEARCH: [{ | |
target: "error", | |
cond: "isInvalid", | |
actions: assign({ | |
errorMessage: "error", | |
}) | |
}, { | |
target: "filtering", | |
actions: "sendFilterToMachine" | |
}], | |
SELECT_TAB: { | |
target: "", | |
actions: assign({ | |
selectedTab: (_, { tab }) => tab, | |
}) | |
} | |
} | |
const editFilterMachine = Machine({ | |
id: 'edit filter', | |
initial: 'editing', | |
context: { | |
selectedTab: "uid", | |
errorMessage: "", | |
}, | |
states: { | |
editing: { | |
on: { | |
...commonActions, | |
} | |
}, | |
error: { | |
on: { | |
...commonActions, | |
} | |
}, | |
filtering: { | |
on: { | |
EDIT: "editing", | |
CLEAR: { | |
target: "", | |
actions: | |
send({ | |
type: "SEARCH", | |
// reset search | |
url: "/", | |
body: undefined, | |
}, { | |
to: "data objects paging" | |
}) | |
} | |
} | |
}, | |
} | |
}, { | |
guards: { | |
isInvalid: () => Math.random() > 0.5, | |
}, | |
actions: { | |
sendFilterToMachine: send((_, { url, body }) => ({ | |
type: "SEARCH", | |
url, body, | |
}), { | |
to: "data objects paging" | |
}) | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment