StoneCypher / fsl

Finite State Language specification
9 stars 1 forks source link

Override #1223

Open StoneCypher opened 1 year ago

StoneCypher commented 1 year ago

Sometimes working machines' state (and data) may need to be overridden.

This is meaningfully distinct from the universal transition described in #1217 , as it's not actually a transition, and doesn't need to resolve the lifecycle or collisions as a result. It won't block defaulting and can co-exist with the universal transition.

The universal transition is do-able, and should exist, but is also problematic for a host of reasons. Heavy use would produce slow machines; there is the potential for difficult to diagnose conflicts, especially around spread; self-references get gross; most importantly, though, it is used for a "let's just be here instead" gesture, which is not actually meaningfully a transition, meaning that wildcard transitions will interact poorly with global hooks.

We'll still make them; they're actually useful in several contexts. But there's a more direct modelling described in the original ask - "I just need the state to be something else now."

I had been just replacing the actual object with a new instance, but with enough external hooks, or any dynamic hooks at all, that's problematic for its own reasons.

So it's time to just offer an override mechanism. This is just the hard-acid ability to say "fuck you, Larry, your state is now 'blue' ."

There needs to be a new hook made available around this, and a new event emitted by this. There also needs to be an attribute in the machine notation to dis-permit this (or possibly instead to permit it.)

There is another semi-colliding concept of a reset. An override only checks if the new state exists; a reset also checks if the state is a valid starting state. An override doesn't have to torch the data; a reset does. They have different hooks and different events.

Initial concept is simple.

const foo = sm`a->b->c->d->e->f->g;`;
foo.go('b');
foo.go('c');
foo.go('d');
foo.override('b');