Conversation
25a01c3 to
93a0d8f
Compare
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 9b28377:
|
2f36204 to
3a6a6b0
Compare
545a5a8 to
1f3bcce
Compare
81244f9 to
752b6d5
Compare
6b42438 to
f57f739
Compare
f1f9f1a to
2d51976
Compare
edbb7c0 to
e1ba83a
Compare
ade4a23 to
4d201c1
Compare
96eda58 to
ae70d67
Compare
13a2f94 to
8ceda5a
Compare
4430c39 to
df4b2be
Compare
df4b2be to
297ca6c
Compare
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit e95f0dc:
|
24 tasks
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR was opened by the Changesets release GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to next, this PR will be updated.
nextis currently in pre mode so this branch has prereleases rather than normal releases. If you want to exit prereleases, runchangeset pre exitonnext.Releases
xstate@5.0.0-alpha.0
Major Changes
#1045
7f3b84816Thanks @davidkpiano! - - The third argument ofmachine.transition(state, event)has been removed. Thecontextshould always be given as part of thestate.There is a new method:
machine.microstep(state, event)which returns the resulting intermediateStateobject that represents a single microstep being taken when transitioning fromstatevia theevent. This is theStatethat does not take into account transient transitions nor raised events, and is useful for debugging.The
state.eventsproperty has been removed from theStateobject, and is replaced internally bystate._internalQueue, which represents raised events to be processed in a macrostep loop. Thestate._internalQueueproperty should be considered internal (not used in normal development).The
state.historyValueproperty now more closely represents the original SCXML algorithm, and is a mapping of state node IDs to their historic descendent state nodes. This is used for resolving history states, and should be considered internal.The
stateNode.isTransientproperty is removed fromStateNode.The
.initialproperty of a state node config object can now contain executable content (i.e., actions):assign()) will now be executed "in order", rather than automatically prioritized. They will be evaluated after previously defined actions are evaluated, and actions that read fromcontextwill have those intermediate values applied, rather than the final resolved value of allassign()actions taken, which was the previous behavior.This shouldn't change the behavior for most state machines. To maintain the previous behavior, ensure that
assign()actions are defined before any other actions.#1669
969a2f4fcThanks @davidkpiano! - An error will be thrown if aninitialstate key is not specified for compound state nodes. For example:You will get the error:
#2294
c0a6dcafaThanks @davidkpiano! - The machine'scontextis now restricted to anobject. This was the most common usage, but now the typings preventcontextfrom being anything but an object:If
contextisundefined, it will now default to an empty object{}:#1260
172d6a7e1Thanks @davidkpiano! - All generic types containingTContextandTEventwill now follow the same, consistent order:TContextTEventTStateSchema,TTypestate`, etc.#1808
31bc73e05Thanks @davidkpiano! - Renamedmachine.withConfig(...)tomachine.provide(...).#878
e09efc720Thanks @Andarist! - Removed third parameter (context) from Machine's transition method. If you want to transition with a particular context value you should create appropriateStateusingState.from. So instead of this -machine.transition('green', 'TIMER', { elapsed: 100 }), you should do this -machine.transition(State.from('green', { elapsed: 100 }), 'TIMER').#1203
145539c4cThanks @davidkpiano! - - Theexecuteoption for an interpreted service has been removed. If you don't want to execute actions, it's recommended that you don't hardcode implementation details into the basemachinethat will be interpreted, and extend the machine'soptions.actionsinstead. By default, the interpreter will execute all actions according to SCXML semantics (immediately upon transition).xstate/devTools/redux:By default, dev tools are attached to the global
window.__xstate__object:And creating your own custom dev tools adapter is a function that takes in the
service:These handlers have been removed, as they are redundant and can all be accomplished with
.onTransition(...)and/or.subscribe(...):service.onEvent()service.onSend()service.onChange()The
service.send(...)method no longer returns the next state. It is avoidfunction (fire-and-forget).The
service.sender(...)method has been removed as redundant. Useservice.send(...)instead.#953
3de36bb24Thanks @davidkpiano! - Support for getters as a transition target (instead of referencing state nodes by ID or relative key) has been removed.The
Machine()andcreateMachine()factory functions no longer support passing incontextas a third argument.The
contextproperty in the machine configuration no longer accepts a function for determining context (which was introduced in 4.7). This might change as the API becomes finalized.The
activitiesproperty was removed fromStateobjects, as activities are now part ofinvokedeclarations.The state nodes will not show the machine's
versionon them - theversionproperty is only available on the root machine node.The
machine.withContext({...})method now permits providing partial context, instead of the entire machine context.#1443
9e10660ecThanks @davidkpiano! - Thein: ...property for transitions is removed and replaced with guards. It is recommended to usestateIn()andnot(stateIn())guard creators instead:#1456
8fcbddd51Thanks @davidkpiano! - There is now support for higher-level guards, which are guards that can compose other guards:and([guard1, guard2, /* ... */])returnstrueif all guards evaluate to truthy, otherwisefalseor([guard1, guard2, /* ... */])returnstrueif any guard evaluates to truthy, otherwisefalsenot(guard1)returnstrueif a single guard evaluates tofalse, otherwisetrue#2824
515cdc9c1Thanks @davidkpiano! - Actions and guards that follow eventless transitions will now receive the event that triggered the transition instead of a "null" event ({ type: '' }), which no longer exists:#1240
6043a1c28Thanks @davidkpiano! - Thein: '...'transition property can now be replaced withstateIn(...)andstateNotIn(...)guards, imported fromxstate/guards:import { createMachine, + stateIn } from 'xstate/guards'; const machine = createMachine({ // ... on: { SOME_EVENT: { target: 'anotherState', - in: '#someState', + cond: stateIn('#someState') } } })The
stateIn(...)andstateNotIn(...)guards also can be used the same way asstate.matches(...):An error will now be thrown if the
assign(...)action is executed when thecontextisundefined. Previously, there was only a warning.The SCXML event
error.executionwill be raised if assignment in anassign(...)action fails.Error events raised by the machine will be thrown if there are no error listeners registered on a service via
service.onError(...).#2824
6a6b2b869Thanks @davidkpiano! - Eventless transitions must now be specified in thealways: { ... }object and not in theon: { ... }object:someState: { on: { // Will no longer work - '': { target: 'anotherState' } }, + always: { target: 'anotherState' } }#2484
0b49437b1Thanks @davidkpiano! - Parameterized actions now require aparamsproperty:// ... entry: [ { type: 'greet', - message: 'Hello' + params: { message: 'Hello' } } ] // ...#987
0e24ea6d6Thanks @davidkpiano! - Theinternalproperty will no longer have effect for transitions on atomic (leaf-node) state nodes. In SCXML,internalonly applies to complex (compound and parallel) state nodes:// ... green: { on: { NOTHING: { - target: 'green', - internal: true, actions: doSomething } } }#987
04e89f90fThanks @davidkpiano! - The history resolution algorithm has been refactored to closely match the SCXML algorithm, which changes the shape ofstate.historyValueto map history state node IDs to their most recently resolved target state nodes.#2882
0096d9f7aThanks @davidkpiano! - Thestate.historyproperty has been removed. This does not affect the machine "history" mechanism.Storing previous state should now be done explicitly:
#1456
8fcbddd51Thanks @davidkpiano! - BREAKING: Thecondproperty in transition config objects has been renamed toguard. This unifies terminology for guarded transitions and guard predicates (previously called "cond", or "conditional", predicates):someState: { on: { EVENT: { target: 'anotherState', - cond: 'isValid' + guard: 'isValid' } } }#2060
b200e0e0bThanks @davidkpiano! - TheMachine()function has been removed. Use thecreateMachine()function instead.#3148
7a68cbb61Thanks @davidkpiano! -spawnis no longer importable fromxstate. Instead you get it inassignlike this:In addition to that, you can now
spawnactors defined in your implementations object, in the same way that you were already able to do that withinvoke. To do that just reference the defined actor like this:#2869
9437c3de9Thanks @davidkpiano! - Theservice.batch(events)method is no longer available.#2191
0038c7b1eThanks @davidkpiano! - TheStateSchematype has been removed from all generic type signatures.#3148
7a68cbb61Thanks @davidkpiano! -EmittedFromtype helper has been renamed toSnapshotFrom.#1163
390eaaa52Thanks @davidkpiano! - Breaking: Thestate.childrenproperty is now a mapping of invoked actor IDs to theirActorRefinstances.Breaking: The way that you interface with invoked/spawned actors is now through
ActorRefinstances. AnActorRefis an opaque reference to anActor, which should be never referenced directly.Breaking: The
originof anSCXML.Eventis no longer a string, but anActorRefinstance.#3148
7a68cbb61Thanks @davidkpiano! - Theservicesoption passed as the second argument tocreateMachine(config, options)is renamed toactors. Each value inactorsshould be a function that takes incontextandeventand returns a [behavior](TODO: link) for an actor. The provided behavior creators are:fromMachinefromPromisefromCallbackfromObservablefromEventObservableimport { createMachine } from 'xstate'; +import { fromPromise } from 'xstate/actors'; const machine = createMachine( { // ... invoke: { src: 'fetchFromAPI' } }, { - services: { + actors: { - fetchFromAPI: (context, event) => { + fetchFromAPI: (context, event) => fromPromise(() => { // ... (return a promise) }) } } );#878
e09efc720Thanks @Andarist! - Support for compound string state values has been dropped from Machine's transition method. It's no longer allowed to call transition like this -machine.transition('a.b', 'NEXT'), instead it's required to use "state value" representation like this -machine.transition({ a: 'b' }, 'NEXT').#898
025a2d6a2Thanks @davidkpiano! - - Breaking: activities removed (can be invoked)Since activities can be considered invoked services, they can be implemented as such. Activities are services that do not send any events back to the parent machine, nor do they receive any events, other than a "stop" signal when the parent changes to a state where the activity is no longer active. This is modeled the same way as a callback service is modeled.
#878
e09efc720Thanks @Andarist! - Removed previously deprecated config properties:onEntry,onExit,parallelandforward.#2876
c99bb43afThanks @davidkpiano! - Typings forTypestatehave been removed. The reason for this is that types for typestates needed to be manually specified, which is unsound because it is possible to specify impossible typestates; i.e., typings for a state'svalueandcontextthat are impossible to achieve.#2840
fc5ca7b7fThanks @davidkpiano! - Invoked/spawned actors are no longer available onservice.children- they can only be accessed fromstate.children.#1811
5d16a7365Thanks @davidkpiano! - Prefix wildcard event descriptors are now supported. These are event descriptors ending with".*"which will match all events that start with the prefix (the partial event type before".*"):Note: wildcards are only valid as the entire event type (
"*") or at the end of an event type, preceded by a period (".*"):"*""event.*""event.something.*""event.*.something""event*""event*.some*thing""*.something"#1456
8fcbddd51Thanks @davidkpiano! - The interface for guard objects has changed. Notably, all guard parameters should be placed in theparamsproperty of the guard object:Example taken from Custom Guards:
#1054
53a594e9aThanks @Andarist! -Machine#transitionno longer handles invalid state values such as values containing non-existent state regions. If you rehydrate your machines and change machine's schema then you should migrate your data accordingly on your own.#1002
31a0d890fThanks @Andarist! - Removed support forservice.send(type, payload). We are usingsendAPI at multiple places and this was the only one supporting this shape of parameters. Additionally, it had not strict TS types and using it was unsafe (type-wise).Minor Changes
#3148
7a68cbb61Thanks @davidkpiano! -onSnapshotis now available for invoke configs. You can specify a transition there to be taken when a snapshot of an invoked actor gets updated. It works similarly toonDone/onError.#1041
b24e47b9eThanks @Andarist! - Support for specifying states deep in the hierarchy has been added for theinitialproperty. It's also now possible to specify multiple states as initial ones - so you can enter multiple descandants which have to be parallel to each other. Keep also in mind that you can only target descendant states with theinitialproperty - it's not possible to target states from another regions.Those are now possible:
#1028
0c6cfee9aThanks @Andarist! - Added support for expressions tocancelaction.#898
c9cda27cbThanks @davidkpiano! - Added interop observable symbols toActorRefso that actor refs are compatible with libraries like RxJS.@xstate/react@4.0.0-alpha.0
Major Changes
7a68cbb61Thanks @davidkpiano! - RemovedgetSnapshotparameter from hooks. It is expected that the receivedactorRefhas to have agetSnapshotmethod on it that can be used internally.Patch Changes
7f3b84816,969a2f4fc,c0a6dcafa,7a68cbb61,172d6a7e1,31bc73e05,e09efc720,145539c4c,3de36bb24,9e10660ec,8fcbddd51,515cdc9c1,6043a1c28,6a6b2b869,0b49437b1,0e24ea6d6,04e89f90f,0096d9f7a,8fcbddd51,b200e0e0b,7a68cbb61,9437c3de9,0038c7b1e,7a68cbb61,b24e47b9e,390eaaa52,7a68cbb61,0c6cfee9a,e09efc720,025a2d6a2,e09efc720,c99bb43af,fc5ca7b7f,c9cda27cb,5d16a7365,8fcbddd51,53a594e9a,31a0d890f]:@xstate/vue@3.0.0-alpha.0
Major Changes
7a68cbb61Thanks @davidkpiano! - RemovedgetSnapshotparameter from composables. It is expected that the receivedactorRefhas to have agetSnapshotmethod on it that can be used internally.Patch Changes
7f3b84816,969a2f4fc,c0a6dcafa,7a68cbb61,172d6a7e1,31bc73e05,e09efc720,145539c4c,3de36bb24,9e10660ec,8fcbddd51,515cdc9c1,6043a1c28,6a6b2b869,0b49437b1,0e24ea6d6,04e89f90f,0096d9f7a,8fcbddd51,b200e0e0b,7a68cbb61,9437c3de9,0038c7b1e,7a68cbb61,b24e47b9e,390eaaa52,7a68cbb61,0c6cfee9a,e09efc720,025a2d6a2,e09efc720,c99bb43af,fc5ca7b7f,c9cda27cb,5d16a7365,8fcbddd51,53a594e9a,31a0d890f]: