Skip to content

Instantly share code, notes, and snippets.

@cellog
Last active April 11, 2020 01:10
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 cellog/1e4a9878859fbd32fa11c66db7402705 to your computer and use it in GitHub Desktop.
Save cellog/1e4a9878859fbd32fa11c66db7402705 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// 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