Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detecting Final State without starting #328

Closed
timoxley opened this issue Jan 24, 2019 · 2 comments
Closed

Detecting Final State without starting #328

timoxley opened this issue Jan 24, 2019 · 2 comments

Comments

@timoxley
Copy link

timoxley commented Jan 24, 2019

Feature request

Originally discussed here: https://spectrum.chat/statecharts/general/detecting-state-machine-is-done~56dda5bc-8031-4840-96d7-f0458cca12d6

I would like to be able to filter my persisted state machines to only those which have not reached a final state. i.e. no point starting a machine which has already reached its final state. Currently there doesn't appear to be a good way to do this without starting the machine.

Perhaps it could be a method on the State prototype e.g.:

const state = State.create(data)
if (state.isFinal()) {
  interpret(machine).start(state)
}

However this would prevent filtering db records without instantiating State for each of them. A serialisable flag would be preferable e.g.:

if (data.isFinal) {
  interpret(machine).start(data)
}

// queryable from the db level:
const datas = await db.query({ isFinal: false })
datas.forEach(data => interpret(machine).start(data))
@davidkpiano
Copy link
Member

Bikeshedding:

state.done; // true or false

// might be confusing with type: 'final' for individual state nodes
state.final; // true or false

@timoxley
Copy link
Author

timoxley commented Jan 25, 2019

state.done 👍

I guess this also matches up with onDone

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants