-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[v5] Rename machine.withConfig(...) to machine.provide(...) #1808
Conversation
🦋 Changeset detectedLatest commit: a6acd40 The changes in this PR will be included in the next version bump. This PR includes changesets to release 11 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@@ -18,7 +18,7 @@ const machine = createMachine( | |||
}, | |||
{ | |||
- activities: { | |||
+ behaviors: { | |||
+ actors: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a good change 👍 you still mention behaviors in a lot of places, I wonder if we want to stick with that terminology? I see it as potentially very confusing for people, at the very least maybe we should bury it deep down and only mention it in like "the very advanced" section of the docs? 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not suuuuper-stoked about this change but on the other hand, both versions are so generic that it's hard to assess which one is better. Since we provide lookups for actions/actors/guards/etc in this, maybe it would be worth renaming this to withImplementations
? It's somewhat mouthful though.
Don't take me wrong - I don't really mind the change, so do whatever you think is best for this one. The @johnyanarella's input could be valuable here as well.
It's important for consistency in terminology, and was mentioned externally which is why I made a note of it: const machine = createMachine(config, options);
// ______________________⬆ ⬆
// | |
machine.withConfig(/* ... */) // |
// ________________________________|
// |
machine.withOptions(/* ... */) |
Right - the consistency is definitely an improvement but it could be approached from the other end (I'm not saying that it should be). You could rename the createMachine(schema, implementations) I didn't even realize that those 2 were currently named like this and it seems to me that it can still be quite confusing because, as mentioned, both config & options are quite generic so if I say "Change your config" one still can be confused on which thing they should adjust. Not a big issue though - naming is hard 🤷♂️ I don't really have any strong contenders for the chosen names. |
Implementation is the "correct" answer but you're right, it's not the most dev-friendly word to type out 🤔 |
Apologies, but I couldn't resist some drive-by bikeshedding... but if open to dropping
anyway, sorry again, feel free to ignore 😄 |
@Silverwolf90 Thanks for the suggestion - still bikeshedding this! What do you think about: -machine.withConfig(/* ... */)
+machine.provide(/* ... */) As in, "provide these implementations"? |
I think it will be worth all the bikeshedding in the end - I'm excited about the potential that tweaking the names here has for reducing the learning curve for newcomers. Moving away from "configuration" is great news, given SCXML already uses it in this problem space—adhering to the classical definition of an arrangement or combination of things—to describe the set of currently active states. The interpreter "options" conform to the common expectation of a fixed set of knobs and toggles with defaults. Using that same term to describe passing a machine an arbitrary and unbounded set of methods doesn't feel like a good fit. At one point I think I halfheartedly suggested the idea of calling the thing passed in here a "wiring harness". Not keen on that one, but I do still wonder if we could mine the terminology associated with machines in the physical world to find something familiar (and less abstract) that intuitively and unambiguously conveys the idea here. Determining the right terminology to describe this pattern—referencing actions/actors/guards by name and plugging in language native implementations—will make a huge difference in highlighting this capability, its purpose and value, as the XState community expands beyond JavaScript. I gotta concede that |
This might be the best description for Do you have any good definition for |
Fair point! You're absolutely right about an In practice, we see Configuration is arguably distinct among those as precisely describing a specific arrangement or combination among possibilities. When you configure your MacBook Pro M1 for purchase, you pick a configuration of cpu speed, ram and ssd size options (another example where the options aren't really optional!). Given their mathematical underpinnings, it's not surprising that the SCXML specification and even David Harel's original statecharts paper use Anyway:
|
Regarding this suggestion above: createMachine(schema, implementations) Over in // an instance of MachineSchematic created either via the Swift DSL or parsed from SCXML
let machineSchematic = MachineSchematic.fromSCXML(data: scxmlData)
// an instance of MachineOptions mapping named references to native implementations
let machineOptions = MachineOptions(
actions: ...,
actors: ...,
guards: ...
)
let machine = Machine(schematic: machineSchematic, options: machineOptions) The term I gravitated toward As we've discussed above, I'm no longer convinced |
@johnyanarella Super helpful thoughts, thanks. So just to digest this, the
For 1., the full definition can be provided as well, and providing a partial definition is just for improved DX, since manually typing out a full definition is tedious, and a lot of things can be inferred (I'm saying this to justify So, for tentative naming, I propose this: createMachine(definition, implementations); And for the original PR, this: someMachine.provide(implementations); Of course, the developers would not need to type out |
I very much like where this bike-shedding has brought us to 👍 one important realization is that with this change we effectively seal what the second parameter is used for. We should be cautious in the future not to introduce there anything that is not an „implementation” |
Nice! I'll mirror this terminology choice over into With Swift, I've got to contend with labelled parameters. So, I'll probably sidestep let machine = Machine(
definition: MachineDefinition.fromSCXML(data: scxmlData),
provided: ImplementationDetails(
actions: [
"foo": { context, event, meta in
// ...
}
],
// ...
)
) (barring anyone coming up with a better type name for |
...or did I misinterpret your comment above, and |
(Worth noting, that the same possibility exists in |
Stumbled upon this, any chance txstate influenced this naming or just a coincidence? :P |
Reference: https://github.com/davidkpiano/xstate/projects/1#card-40598347
This PR also renames
options.behaviors
tooptions.actors
, as previously discussed.