Last active
April 11, 2020 01:12
-
-
Save cellog/b582c277f54867d144c6795cd6000aa7 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: (_, { name }) => !name, | |
actions: assign({ | |
errorMessage: "The name cannot be empty." | |
}) | |
}, { | |
target: "search", | |
actions: assign((_, { | |
name, type, projectId, datasetId | |
}) => ({ | |
errorMessage: "", | |
name, type, projectId, datasetId, | |
})) | |
}] | |
} | |
const nameFilterMachine = Machine({ | |
id: 'name filter', | |
initial: 'idle', | |
context: { | |
errorMessage: "", | |
name: "", | |
type: "", | |
datasetId: "", | |
projectId: "", | |
}, | |
states: { | |
idle: { | |
on: { | |
...commonActions, | |
} | |
}, | |
error: { | |
on: { | |
...commonActions, | |
} | |
}, | |
search: { | |
type: "final", | |
} | |
}, | |
onDone: { | |
actions: "sendSearch", | |
} | |
}, { | |
actions: { | |
sendSearch: send(({ name, type, projectId, datasetId }) => ({ | |
type: "SEARCH", | |
url: `/projects/${projectId}/${type}/filter-by-name?dataset_id=${datasetId}&name=${name}`, | |
body: undefined, | |
}), { | |
to: "data object paging" | |
}) | |
}, | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment