xstate 5.0.0-beta.51 → 5.0.0-beta.53
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/actions/dist/xstate-actions.cjs.js +9 -11
- package/actions/dist/xstate-actions.cjs.mjs +0 -2
- package/actions/dist/xstate-actions.development.cjs.js +9 -11
- package/actions/dist/xstate-actions.development.cjs.mjs +0 -2
- package/actions/dist/xstate-actions.development.esm.js +2 -2
- package/actions/dist/xstate-actions.esm.js +2 -2
- package/actions/dist/xstate-actions.umd.min.js +1 -1
- package/actions/dist/xstate-actions.umd.min.js.map +1 -1
- package/actors/dist/xstate-actors.cjs.js +17 -17
- package/actors/dist/xstate-actors.development.cjs.js +17 -17
- package/actors/dist/xstate-actors.development.esm.js +17 -17
- package/actors/dist/xstate-actors.esm.js +17 -17
- package/actors/dist/xstate-actors.umd.min.js +1 -1
- package/actors/dist/xstate-actors.umd.min.js.map +1 -1
- package/dist/declarations/src/State.d.ts +2 -2
- package/dist/declarations/src/StateMachine.d.ts +6 -6
- package/dist/declarations/src/StateNode.d.ts +4 -4
- package/dist/declarations/src/actions.d.ts +0 -2
- package/dist/declarations/src/actors/index.d.ts +1 -1
- package/dist/declarations/src/actors/transition.d.ts +1 -1
- package/dist/declarations/src/guards.d.ts +1 -1
- package/dist/declarations/src/interpreter.d.ts +7 -7
- package/dist/declarations/src/stateUtils.d.ts +9 -9
- package/dist/declarations/src/types.d.ts +23 -19
- package/dist/{pure-296f8ebd.development.esm.js → log-1fd7d00a.development.esm.js} +24 -61
- package/dist/{pure-aefddc19.esm.js → log-60ab9eaf.esm.js} +24 -58
- package/dist/{pure-c5f1b46c.cjs.js → log-717bb5a1.cjs.js} +23 -59
- package/dist/{pure-a0f16134.development.cjs.js → log-c8797128.development.cjs.js} +23 -62
- package/dist/{raise-acaa3884.development.esm.js → raise-953b1eb5.development.esm.js} +136 -136
- package/dist/{raise-d5633a02.cjs.js → raise-a8367773.cjs.js} +136 -136
- package/dist/{raise-4742bf04.esm.js → raise-be2f20bc.esm.js} +136 -136
- package/dist/{raise-528386de.development.cjs.js → raise-d9fd8932.development.cjs.js} +136 -136
- package/dist/xstate.cjs.js +28 -30
- package/dist/xstate.cjs.mjs +0 -2
- package/dist/xstate.development.cjs.js +28 -30
- package/dist/xstate.development.cjs.mjs +0 -2
- package/dist/xstate.development.esm.js +21 -21
- package/dist/xstate.esm.js +21 -21
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/guards/dist/xstate-guards.cjs.js +1 -1
- package/guards/dist/xstate-guards.development.cjs.js +1 -1
- package/guards/dist/xstate-guards.development.esm.js +1 -1
- package/guards/dist/xstate-guards.esm.js +1 -1
- package/guards/dist/xstate-guards.umd.min.js.map +1 -1
- package/package.json +1 -1
- package/dist/declarations/src/actions/choose.d.ts +0 -9
- package/dist/declarations/src/actions/pure.d.ts +0 -10
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var guards_dist_xstateGuards = require('../../dist/raise-
|
|
5
|
+
var guards_dist_xstateGuards = require('../../dist/raise-a8367773.cjs.js');
|
|
6
6
|
require('../../dev/dist/xstate-dev.cjs.js');
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -66,10 +66,10 @@ require('../../dev/dist/xstate-dev.cjs.js');
|
|
|
66
66
|
function fromTransition(transition, initialContext) {
|
|
67
67
|
return {
|
|
68
68
|
config: transition,
|
|
69
|
-
transition: (
|
|
69
|
+
transition: (snapshot, event, actorScope) => {
|
|
70
70
|
return {
|
|
71
|
-
...
|
|
72
|
-
context: transition(
|
|
71
|
+
...snapshot,
|
|
72
|
+
context: transition(snapshot.context, event, actorScope)
|
|
73
73
|
};
|
|
74
74
|
},
|
|
75
75
|
getInitialState: (_, input) => {
|
|
@@ -82,8 +82,8 @@ function fromTransition(transition, initialContext) {
|
|
|
82
82
|
}) : initialContext
|
|
83
83
|
};
|
|
84
84
|
},
|
|
85
|
-
|
|
86
|
-
|
|
85
|
+
getPersistedSnapshot: snapshot => snapshot,
|
|
86
|
+
restoreSnapshot: snapshot => snapshot
|
|
87
87
|
};
|
|
88
88
|
}
|
|
89
89
|
|
|
@@ -198,8 +198,8 @@ function fromCallback(invokeCallback) {
|
|
|
198
198
|
input
|
|
199
199
|
};
|
|
200
200
|
},
|
|
201
|
-
|
|
202
|
-
|
|
201
|
+
getPersistedSnapshot: snapshot => snapshot,
|
|
202
|
+
restoreSnapshot: snapshot => snapshot
|
|
203
203
|
};
|
|
204
204
|
return logic;
|
|
205
205
|
}
|
|
@@ -338,11 +338,11 @@ function fromObservable(observableCreator) {
|
|
|
338
338
|
}
|
|
339
339
|
});
|
|
340
340
|
},
|
|
341
|
-
|
|
341
|
+
getPersistedSnapshot: ({
|
|
342
342
|
_subscription,
|
|
343
343
|
...state
|
|
344
344
|
}) => state,
|
|
345
|
-
|
|
345
|
+
restoreSnapshot: state => ({
|
|
346
346
|
...state,
|
|
347
347
|
_subscription: undefined
|
|
348
348
|
})
|
|
@@ -471,12 +471,12 @@ function fromEventObservable(lazyObservable) {
|
|
|
471
471
|
}
|
|
472
472
|
});
|
|
473
473
|
},
|
|
474
|
-
|
|
474
|
+
getPersistedSnapshot: ({
|
|
475
475
|
_subscription,
|
|
476
|
-
...
|
|
477
|
-
}) =>
|
|
478
|
-
|
|
479
|
-
...
|
|
476
|
+
...snapshot
|
|
477
|
+
}) => snapshot,
|
|
478
|
+
restoreSnapshot: snapshot => ({
|
|
479
|
+
...snapshot,
|
|
480
480
|
_subscription: undefined
|
|
481
481
|
})
|
|
482
482
|
};
|
|
@@ -605,8 +605,8 @@ function fromPromise(promiseCreator) {
|
|
|
605
605
|
input
|
|
606
606
|
};
|
|
607
607
|
},
|
|
608
|
-
|
|
609
|
-
|
|
608
|
+
getPersistedSnapshot: snapshot => snapshot,
|
|
609
|
+
restoreSnapshot: snapshot => snapshot
|
|
610
610
|
};
|
|
611
611
|
return logic;
|
|
612
612
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var guards_dist_xstateGuards = require('../../dist/raise-
|
|
5
|
+
var guards_dist_xstateGuards = require('../../dist/raise-d9fd8932.development.cjs.js');
|
|
6
6
|
require('../../dev/dist/xstate-dev.development.cjs.js');
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -66,10 +66,10 @@ require('../../dev/dist/xstate-dev.development.cjs.js');
|
|
|
66
66
|
function fromTransition(transition, initialContext) {
|
|
67
67
|
return {
|
|
68
68
|
config: transition,
|
|
69
|
-
transition: (
|
|
69
|
+
transition: (snapshot, event, actorScope) => {
|
|
70
70
|
return {
|
|
71
|
-
...
|
|
72
|
-
context: transition(
|
|
71
|
+
...snapshot,
|
|
72
|
+
context: transition(snapshot.context, event, actorScope)
|
|
73
73
|
};
|
|
74
74
|
},
|
|
75
75
|
getInitialState: (_, input) => {
|
|
@@ -82,8 +82,8 @@ function fromTransition(transition, initialContext) {
|
|
|
82
82
|
}) : initialContext
|
|
83
83
|
};
|
|
84
84
|
},
|
|
85
|
-
|
|
86
|
-
|
|
85
|
+
getPersistedSnapshot: snapshot => snapshot,
|
|
86
|
+
restoreSnapshot: snapshot => snapshot
|
|
87
87
|
};
|
|
88
88
|
}
|
|
89
89
|
|
|
@@ -198,8 +198,8 @@ function fromCallback(invokeCallback) {
|
|
|
198
198
|
input
|
|
199
199
|
};
|
|
200
200
|
},
|
|
201
|
-
|
|
202
|
-
|
|
201
|
+
getPersistedSnapshot: snapshot => snapshot,
|
|
202
|
+
restoreSnapshot: snapshot => snapshot
|
|
203
203
|
};
|
|
204
204
|
return logic;
|
|
205
205
|
}
|
|
@@ -338,11 +338,11 @@ function fromObservable(observableCreator) {
|
|
|
338
338
|
}
|
|
339
339
|
});
|
|
340
340
|
},
|
|
341
|
-
|
|
341
|
+
getPersistedSnapshot: ({
|
|
342
342
|
_subscription,
|
|
343
343
|
...state
|
|
344
344
|
}) => state,
|
|
345
|
-
|
|
345
|
+
restoreSnapshot: state => ({
|
|
346
346
|
...state,
|
|
347
347
|
_subscription: undefined
|
|
348
348
|
})
|
|
@@ -471,12 +471,12 @@ function fromEventObservable(lazyObservable) {
|
|
|
471
471
|
}
|
|
472
472
|
});
|
|
473
473
|
},
|
|
474
|
-
|
|
474
|
+
getPersistedSnapshot: ({
|
|
475
475
|
_subscription,
|
|
476
|
-
...
|
|
477
|
-
}) =>
|
|
478
|
-
|
|
479
|
-
...
|
|
476
|
+
...snapshot
|
|
477
|
+
}) => snapshot,
|
|
478
|
+
restoreSnapshot: snapshot => ({
|
|
479
|
+
...snapshot,
|
|
480
480
|
_subscription: undefined
|
|
481
481
|
})
|
|
482
482
|
};
|
|
@@ -605,8 +605,8 @@ function fromPromise(promiseCreator) {
|
|
|
605
605
|
input
|
|
606
606
|
};
|
|
607
607
|
},
|
|
608
|
-
|
|
609
|
-
|
|
608
|
+
getPersistedSnapshot: snapshot => snapshot,
|
|
609
|
+
restoreSnapshot: snapshot => snapshot
|
|
610
610
|
};
|
|
611
611
|
return logic;
|
|
612
612
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { X as XSTATE_STOP, z as createActor } from '../../dist/raise-
|
|
1
|
+
import { X as XSTATE_STOP, z as createActor } from '../../dist/raise-953b1eb5.development.esm.js';
|
|
2
2
|
import '../../dev/dist/xstate-dev.development.esm.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -62,10 +62,10 @@ import '../../dev/dist/xstate-dev.development.esm.js';
|
|
|
62
62
|
function fromTransition(transition, initialContext) {
|
|
63
63
|
return {
|
|
64
64
|
config: transition,
|
|
65
|
-
transition: (
|
|
65
|
+
transition: (snapshot, event, actorScope) => {
|
|
66
66
|
return {
|
|
67
|
-
...
|
|
68
|
-
context: transition(
|
|
67
|
+
...snapshot,
|
|
68
|
+
context: transition(snapshot.context, event, actorScope)
|
|
69
69
|
};
|
|
70
70
|
},
|
|
71
71
|
getInitialState: (_, input) => {
|
|
@@ -78,8 +78,8 @@ function fromTransition(transition, initialContext) {
|
|
|
78
78
|
}) : initialContext
|
|
79
79
|
};
|
|
80
80
|
},
|
|
81
|
-
|
|
82
|
-
|
|
81
|
+
getPersistedSnapshot: snapshot => snapshot,
|
|
82
|
+
restoreSnapshot: snapshot => snapshot
|
|
83
83
|
};
|
|
84
84
|
}
|
|
85
85
|
|
|
@@ -194,8 +194,8 @@ function fromCallback(invokeCallback) {
|
|
|
194
194
|
input
|
|
195
195
|
};
|
|
196
196
|
},
|
|
197
|
-
|
|
198
|
-
|
|
197
|
+
getPersistedSnapshot: snapshot => snapshot,
|
|
198
|
+
restoreSnapshot: snapshot => snapshot
|
|
199
199
|
};
|
|
200
200
|
return logic;
|
|
201
201
|
}
|
|
@@ -334,11 +334,11 @@ function fromObservable(observableCreator) {
|
|
|
334
334
|
}
|
|
335
335
|
});
|
|
336
336
|
},
|
|
337
|
-
|
|
337
|
+
getPersistedSnapshot: ({
|
|
338
338
|
_subscription,
|
|
339
339
|
...state
|
|
340
340
|
}) => state,
|
|
341
|
-
|
|
341
|
+
restoreSnapshot: state => ({
|
|
342
342
|
...state,
|
|
343
343
|
_subscription: undefined
|
|
344
344
|
})
|
|
@@ -467,12 +467,12 @@ function fromEventObservable(lazyObservable) {
|
|
|
467
467
|
}
|
|
468
468
|
});
|
|
469
469
|
},
|
|
470
|
-
|
|
470
|
+
getPersistedSnapshot: ({
|
|
471
471
|
_subscription,
|
|
472
|
-
...
|
|
473
|
-
}) =>
|
|
474
|
-
|
|
475
|
-
...
|
|
472
|
+
...snapshot
|
|
473
|
+
}) => snapshot,
|
|
474
|
+
restoreSnapshot: snapshot => ({
|
|
475
|
+
...snapshot,
|
|
476
476
|
_subscription: undefined
|
|
477
477
|
})
|
|
478
478
|
};
|
|
@@ -601,8 +601,8 @@ function fromPromise(promiseCreator) {
|
|
|
601
601
|
input
|
|
602
602
|
};
|
|
603
603
|
},
|
|
604
|
-
|
|
605
|
-
|
|
604
|
+
getPersistedSnapshot: snapshot => snapshot,
|
|
605
|
+
restoreSnapshot: snapshot => snapshot
|
|
606
606
|
};
|
|
607
607
|
return logic;
|
|
608
608
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { X as XSTATE_STOP, z as createActor } from '../../dist/raise-
|
|
1
|
+
import { X as XSTATE_STOP, z as createActor } from '../../dist/raise-be2f20bc.esm.js';
|
|
2
2
|
import '../../dev/dist/xstate-dev.esm.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -62,10 +62,10 @@ import '../../dev/dist/xstate-dev.esm.js';
|
|
|
62
62
|
function fromTransition(transition, initialContext) {
|
|
63
63
|
return {
|
|
64
64
|
config: transition,
|
|
65
|
-
transition: (
|
|
65
|
+
transition: (snapshot, event, actorScope) => {
|
|
66
66
|
return {
|
|
67
|
-
...
|
|
68
|
-
context: transition(
|
|
67
|
+
...snapshot,
|
|
68
|
+
context: transition(snapshot.context, event, actorScope)
|
|
69
69
|
};
|
|
70
70
|
},
|
|
71
71
|
getInitialState: (_, input) => {
|
|
@@ -78,8 +78,8 @@ function fromTransition(transition, initialContext) {
|
|
|
78
78
|
}) : initialContext
|
|
79
79
|
};
|
|
80
80
|
},
|
|
81
|
-
|
|
82
|
-
|
|
81
|
+
getPersistedSnapshot: snapshot => snapshot,
|
|
82
|
+
restoreSnapshot: snapshot => snapshot
|
|
83
83
|
};
|
|
84
84
|
}
|
|
85
85
|
|
|
@@ -194,8 +194,8 @@ function fromCallback(invokeCallback) {
|
|
|
194
194
|
input
|
|
195
195
|
};
|
|
196
196
|
},
|
|
197
|
-
|
|
198
|
-
|
|
197
|
+
getPersistedSnapshot: snapshot => snapshot,
|
|
198
|
+
restoreSnapshot: snapshot => snapshot
|
|
199
199
|
};
|
|
200
200
|
return logic;
|
|
201
201
|
}
|
|
@@ -334,11 +334,11 @@ function fromObservable(observableCreator) {
|
|
|
334
334
|
}
|
|
335
335
|
});
|
|
336
336
|
},
|
|
337
|
-
|
|
337
|
+
getPersistedSnapshot: ({
|
|
338
338
|
_subscription,
|
|
339
339
|
...state
|
|
340
340
|
}) => state,
|
|
341
|
-
|
|
341
|
+
restoreSnapshot: state => ({
|
|
342
342
|
...state,
|
|
343
343
|
_subscription: undefined
|
|
344
344
|
})
|
|
@@ -467,12 +467,12 @@ function fromEventObservable(lazyObservable) {
|
|
|
467
467
|
}
|
|
468
468
|
});
|
|
469
469
|
},
|
|
470
|
-
|
|
470
|
+
getPersistedSnapshot: ({
|
|
471
471
|
_subscription,
|
|
472
|
-
...
|
|
473
|
-
}) =>
|
|
474
|
-
|
|
475
|
-
...
|
|
472
|
+
...snapshot
|
|
473
|
+
}) => snapshot,
|
|
474
|
+
restoreSnapshot: snapshot => ({
|
|
475
|
+
...snapshot,
|
|
476
476
|
_subscription: undefined
|
|
477
477
|
})
|
|
478
478
|
};
|
|
@@ -601,8 +601,8 @@ function fromPromise(promiseCreator) {
|
|
|
601
601
|
input
|
|
602
602
|
};
|
|
603
603
|
},
|
|
604
|
-
|
|
605
|
-
|
|
604
|
+
getPersistedSnapshot: snapshot => snapshot,
|
|
605
|
+
restoreSnapshot: snapshot => snapshot
|
|
606
606
|
};
|
|
607
607
|
return logic;
|
|
608
608
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(t,s){"object"==typeof exports&&"undefined"!=typeof module?s(exports):"function"==typeof define&&define.amd?define(["exports"],s):s((t="undefined"!=typeof globalThis?globalThis:t||self).XStateActors={})}(this,(function(t){"use strict";class s{constructor(t){this._process=t,this._active=!1,this._current=null,this._last=null}start(){this._active=!0,this.flush()}clear(){this._current&&(this._current.next=null,this._last=this._current)}enqueue(t){const s={value:t,next:null};if(this._current)return this._last.next=s,void(this._last=s);this._current=s,this._last=s,this._active&&this.flush()}flush(){for(;this._current;){const t=this._current;this._process(t.value),this._current=t.next}this._last=null}}const e="xstate.stop";function i(){const t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:window;if(t.__xstate__)return t.__xstate__}const r=t=>{const s=i();s&&s.register(t)};function o(t){setTimeout((()=>{throw t}))}const n="function"==typeof Symbol&&Symbol.observable||"@@observable";let a=0;function c(t,s,e){const i="object"==typeof t,r=i?t:void 0;return{next:(i?t.next:t)?.bind(r),error:(i?t.error:s)?.bind(r),complete:(i?t.complete:e)?.bind(r)}}let h=function(t){return t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped",t}({});const u={clock:{setTimeout:(t,s)=>setTimeout(t,s),clearTimeout:t=>clearTimeout(t)},logger:console.log.bind(console),devTools:!1};class d{constructor(t,e){this.logic=t,this._state=void 0,this.clock=void 0,this.options=void 0,this.id=void 0,this.mailbox=new s(this._process.bind(this)),this.delayedEventsMap={},this.observers=new Set,this.logger=void 0,this._processingStatus=h.NotStarted,this._parent=void 0,this._syncSnapshot=void 0,this.ref=void 0,this._actorScope=void 0,this._systemId=void 0,this.sessionId=void 0,this.system=void 0,this._doneEvent=void 0,this.src=void 0,this._deferred=[];const i={...u,...e},{clock:r,logger:o,parent:n,syncSnapshot:d,id:p,systemId:l,inspect:_}=i;this.system=n?.system??function(t){const s=new Map,e=new Map,i=new WeakMap,r=new Set,o={_bookId:()=>"x:"+a++,_register:(t,e)=>(s.set(t,e),t),_unregister:t=>{s.delete(t.sessionId);const r=i.get(t);void 0!==r&&(e.delete(r),i.delete(t))},get:t=>e.get(t),_set:(t,s)=>{const r=e.get(t);if(r&&r!==s)throw new Error(`Actor with system ID '${t}' already exists.`);e.set(t,s),i.set(s,t)},inspect:t=>{r.add(t)},_sendInspectionEvent:s=>{const e={...s,rootId:t.sessionId};r.forEach((t=>t.next?.(e)))},_relay:(t,s,e)=>{o._sendInspectionEvent({type:"@xstate.event",sourceRef:t,actorRef:s,event:e}),s._send(e)}};return o}(this),_&&!n&&this.system.inspect(c(_)),this.sessionId=this.system._bookId(),this.id=p??this.sessionId,this.logger=o,this.clock=r,this._parent=n,this._syncSnapshot=d,this.options=i,this.src=i.src??t,this.ref=this,this._actorScope={self:this,id:this.id,sessionId:this.sessionId,logger:this.logger,defer:t=>{this._deferred.push(t)},system:this.system,stopChild:t=>{if(t._parent!==this)throw new Error(`Cannot stop child actor ${t.id} of ${this.id} because it is not a child`);t._stop()}},this.send=this.send.bind(this),this.system._sendInspectionEvent({type:"@xstate.actor",actorRef:this}),l&&(this._systemId=l,this.system._set(l,this)),this._initState(e?.state),l&&"active"!==this._state.status&&this.system._unregister(this)}_initState(t){try{this._state=t?this.logic.restoreState?this.logic.restoreState(t,this._actorScope):t:this.logic.getInitialState(this._actorScope,this.options?.input)}catch(t){this._state={status:"error",output:void 0,error:t}}}update(t,s){let e;for(this._state=t;e=this._deferred.shift();)try{e()}catch(s){this._deferred.length=0,this._state={...t,status:"error",error:s}}switch(this._state.status){case"active":for(const s of this.observers)try{s.next?.(t)}catch(t){o(t)}break;case"done":for(const s of this.observers)try{s.next?.(t)}catch(t){o(t)}this._stopProcedure(),this._complete(),this._doneEvent=(i=this.id,r=this._state.output,{type:`xstate.done.actor.${i}`,output:r}),this._parent&&this.system._relay(this,this._parent,this._doneEvent);break;case"error":this._error(this._state.error)}var i,r;this.system._sendInspectionEvent({type:"@xstate.snapshot",actorRef:this,event:s,snapshot:t})}subscribe(t,s,e){const i=c(t,s,e);if(this._processingStatus!==h.Stopped)this.observers.add(i);else try{i.complete?.()}catch(t){o(t)}return{unsubscribe:()=>{this.observers.delete(i)}}}start(){if(this._processingStatus===h.Running)return this;this._syncSnapshot&&this.subscribe({next:t=>{"active"===t.status&&this.system._relay(this,this._parent,{type:`xstate.snapshot.${this.id}`,snapshot:t})},error:()=>{}}),this.system._register(this.sessionId,this),this._systemId&&this.system._set(this._systemId,this),this._processingStatus=h.Running;const t={type:"xstate.init",input:this.options.input};this.system._sendInspectionEvent({type:"@xstate.event",sourceRef:this._parent,actorRef:this,event:t});switch(this._state.status){case"done":return this.update(this._state,t),this;case"error":return this._error(this._state.error),this}if(this.logic.start)try{this.logic.start(this._state,this._actorScope)}catch(t){return this._state={...this._state,status:"error",error:t},this._error(t),this}return this.update(this._state,t),this.options.devTools&&this.attachDevTools(),this.mailbox.start(),this}_process(t){let s,i;try{s=this.logic.transition(this._state,t,this._actorScope)}catch(t){i={err:t}}if(i){const{err:t}=i;return this._state={...this._state,status:"error",error:t},void this._error(t)}this.update(s,t),t.type===e&&(this._stopProcedure(),this._complete())}_stop(){return this._processingStatus===h.Stopped?this:(this.mailbox.clear(),this._processingStatus===h.NotStarted?(this._processingStatus=h.Stopped,this):(this.mailbox.enqueue({type:e}),this))}stop(){if(this._parent)throw new Error("A non-root actor cannot be stopped directly.");return this._stop()}_complete(){for(const t of this.observers)try{t.complete?.()}catch(t){o(t)}this.observers.clear()}_reportError(t){if(!this.observers.size)return void(this._parent||o(t));let s=!1;for(const e of this.observers){const i=e.error;s||=!i;try{i?.(t)}catch(t){o(t)}}this.observers.clear(),s&&o(t)}_error(t){this._stopProcedure(),this._reportError(t),this._parent&&this.system._relay(this,this._parent,{type:`xstate.error.actor.${this.id}`,data:t})}_stopProcedure(){if(this._processingStatus!==h.Running)return this;for(const t of Object.keys(this.delayedEventsMap))this.clock.clearTimeout(this.delayedEventsMap[t]);return this.mailbox.clear(),this.mailbox=new s(this._process.bind(this)),this._processingStatus=h.Stopped,this.system._unregister(this),this}_send(t){this._processingStatus!==h.Stopped&&this.mailbox.enqueue(t)}send(t){this.system._relay(void 0,this,t)}delaySend(t){const{event:s,id:e,delay:i}=t,r=this.clock.setTimeout((()=>{this.system._relay(this,t.to??this,s)}),i);e&&(this.delayedEventsMap[e]=r)}cancel(t){this.clock.clearTimeout(this.delayedEventsMap[t]),delete this.delayedEventsMap[t]}attachDevTools(){const{devTools:t}=this.options;if(t){("function"==typeof t?t:r)(this)}}toJSON(){return{xstate$$type:1,id:this.id}}getPersistedState(t){return this.logic.getPersistedState(this._state,t)}[n](){return this}getSnapshot(){return this._state}}function p(t,s){return{config:t,transition:(s,e,i)=>({...s,context:t(s.context,e,i)}),getInitialState:(t,e)=>({status:"active",output:void 0,error:void 0,context:"function"==typeof s?s({input:e}):s}),getPersistedState:t=>t,restoreState:t=>t}}const l=new WeakMap;const _="xstate.observable.next",v="xstate.observable.error",f="xstate.observable.complete";const y="xstate.promise.resolve",b="xstate.promise.reject";const g=p((t=>{}),void 0);t.createEmptyActor=function(){return new d(g,t);var t},t.fromCallback=function(t){return{config:t,start:(s,e)=>{const{self:i,system:r}=e,o={receivers:void 0,dispose:void 0};l.set(i,o),o.dispose=t({input:s.input,system:r,self:i,sendBack:t=>{"stopped"!==i.getSnapshot().status&&i._parent&&r._relay(i,i._parent,t)},receive:t=>{o.receivers??=new Set,o.receivers.add(t)}})},transition:(t,s,i)=>{const r=l.get(i.self);return s.type===e?(t={...t,status:"stopped",error:void 0},r.dispose?.(),t):(r.receivers?.forEach((t=>t(s))),t)},getInitialState:(t,s)=>({status:"active",output:void 0,error:void 0,input:s}),getPersistedState:t=>t,restoreState:t=>t}},t.fromEventObservable=function(t){return{config:t,transition:(t,s)=>{if("active"!==t.status)return t;switch(s.type){case v:return{...t,status:"error",error:s.data,input:void 0,_subscription:void 0};case f:return{...t,status:"done",input:void 0,_subscription:void 0};case e:return t._subscription.unsubscribe(),{...t,status:"stopped",input:void 0,_subscription:void 0};default:return t}},getInitialState:(t,s)=>({status:"active",output:void 0,error:void 0,context:void 0,input:s,_subscription:void 0}),start:(s,{self:e,system:i})=>{"done"!==s.status&&(s._subscription=t({input:s.input,system:i,self:e}).subscribe({next:t=>{e._parent&&i._relay(e,e._parent,t)},error:t=>{i._relay(e,e,{type:v,data:t})},complete:()=>{i._relay(e,e,{type:f})}}))},getPersistedState:({_subscription:t,...s})=>s,restoreState:t=>({...t,_subscription:void 0})}},t.fromObservable=function(t){return{config:t,transition:(t,s,{self:i,id:r,defer:o,system:n})=>{if("active"!==t.status)return t;switch(s.type){case _:return{...t,context:s.data};case v:return{...t,status:"error",error:s.data,input:void 0,_subscription:void 0};case f:return{...t,status:"done",input:void 0,_subscription:void 0};case e:return t._subscription.unsubscribe(),{...t,status:"stopped",input:void 0,_subscription:void 0};default:return t}},getInitialState:(t,s)=>({status:"active",output:void 0,error:void 0,context:void 0,input:s,_subscription:void 0}),start:(s,{self:e,system:i})=>{"done"!==s.status&&(s._subscription=t({input:s.input,system:i,self:e}).subscribe({next:t=>{i._relay(e,e,{type:_,data:t})},error:t=>{i._relay(e,e,{type:v,data:t})},complete:()=>{i._relay(e,e,{type:f})}}))},getPersistedState:({_subscription:t,...s})=>s,restoreState:t=>({...t,_subscription:void 0})}},t.fromPromise=function(t){return{config:t,transition:(t,s)=>{if("active"!==t.status)return t;switch(s.type){case y:{const e=s.data;return{...t,status:"done",output:e,input:void 0}}case b:return{...t,status:"error",error:s.data,input:void 0};case e:return{...t,status:"stopped",input:void 0};default:return t}},start:(s,{self:e,system:i})=>{if("active"!==s.status)return;Promise.resolve(t({input:s.input,system:i,self:e})).then((t=>{"active"===e.getSnapshot().status&&i._relay(e,e,{type:y,data:t})}),(t=>{"active"===e.getSnapshot().status&&i._relay(e,e,{type:b,data:t})}))},getInitialState:(t,s)=>({status:"active",output:void 0,error:void 0,input:s}),getPersistedState:t=>t,restoreState:t=>t}},t.fromTransition=p,Object.defineProperty(t,"__esModule",{value:!0})}));
|
|
1
|
+
!function(t,s){"object"==typeof exports&&"undefined"!=typeof module?s(exports):"function"==typeof define&&define.amd?define(["exports"],s):s((t="undefined"!=typeof globalThis?globalThis:t||self).XStateActors={})}(this,(function(t){"use strict";class s{constructor(t){this._process=t,this._active=!1,this._current=null,this._last=null}start(){this._active=!0,this.flush()}clear(){this._current&&(this._current.next=null,this._last=this._current)}enqueue(t){const s={value:t,next:null};if(this._current)return this._last.next=s,void(this._last=s);this._current=s,this._last=s,this._active&&this.flush()}flush(){for(;this._current;){const t=this._current;this._process(t.value),this._current=t.next}this._last=null}}const e="xstate.stop";function i(){const t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:window;if(t.__xstate__)return t.__xstate__}const r=t=>{const s=i();s&&s.register(t)};function o(t){setTimeout((()=>{throw t}))}const n="function"==typeof Symbol&&Symbol.observable||"@@observable";let a=0;function h(t,s,e){const i="object"==typeof t,r=i?t:void 0;return{next:(i?t.next:t)?.bind(r),error:(i?t.error:s)?.bind(r),complete:(i?t.complete:e)?.bind(r)}}let c=function(t){return t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped",t}({});const p={clock:{setTimeout:(t,s)=>setTimeout(t,s),clearTimeout:t=>clearTimeout(t)},logger:console.log.bind(console),devTools:!1};class u{constructor(t,e){this.logic=t,this._snapshot=void 0,this.clock=void 0,this.options=void 0,this.id=void 0,this.mailbox=new s(this._process.bind(this)),this.delayedEventsMap={},this.observers=new Set,this.logger=void 0,this._processingStatus=c.NotStarted,this._parent=void 0,this._syncSnapshot=void 0,this.ref=void 0,this._actorScope=void 0,this._systemId=void 0,this.sessionId=void 0,this.system=void 0,this._doneEvent=void 0,this.src=void 0,this._deferred=[];const i={...p,...e},{clock:r,logger:o,parent:n,syncSnapshot:u,id:d,systemId:l,inspect:_}=i;this.system=n?.system??function(t){const s=new Map,e=new Map,i=new WeakMap,r=new Set,o={_bookId:()=>"x:"+a++,_register:(t,e)=>(s.set(t,e),t),_unregister:t=>{s.delete(t.sessionId);const r=i.get(t);void 0!==r&&(e.delete(r),i.delete(t))},get:t=>e.get(t),_set:(t,s)=>{const r=e.get(t);if(r&&r!==s)throw new Error(`Actor with system ID '${t}' already exists.`);e.set(t,s),i.set(s,t)},inspect:t=>{r.add(t)},_sendInspectionEvent:s=>{const e={...s,rootId:t.sessionId};r.forEach((t=>t.next?.(e)))},_relay:(t,s,e)=>{o._sendInspectionEvent({type:"@xstate.event",sourceRef:t,actorRef:s,event:e}),s._send(e)}};return o}(this),_&&!n&&this.system.inspect(h(_)),this.sessionId=this.system._bookId(),this.id=d??this.sessionId,this.logger=o,this.clock=r,this._parent=n,this._syncSnapshot=u,this.options=i,this.src=i.src??t,this.ref=this,this._actorScope={self:this,id:this.id,sessionId:this.sessionId,logger:this.logger,defer:t=>{this._deferred.push(t)},system:this.system,stopChild:t=>{if(t._parent!==this)throw new Error(`Cannot stop child actor ${t.id} of ${this.id} because it is not a child`);t._stop()}},this.send=this.send.bind(this),this.system._sendInspectionEvent({type:"@xstate.actor",actorRef:this}),l&&(this._systemId=l,this.system._set(l,this)),this._initState(e?.snapshot??e?.state),l&&"active"!==this._snapshot.status&&this.system._unregister(this)}_initState(t){try{this._snapshot=t?this.logic.restoreSnapshot?this.logic.restoreSnapshot(t,this._actorScope):t:this.logic.getInitialState(this._actorScope,this.options?.input)}catch(t){this._snapshot={status:"error",output:void 0,error:t}}}update(t,s){let e;for(this._snapshot=t;e=this._deferred.shift();)try{e()}catch(s){this._deferred.length=0,this._snapshot={...t,status:"error",error:s}}switch(this._snapshot.status){case"active":for(const s of this.observers)try{s.next?.(t)}catch(t){o(t)}break;case"done":for(const s of this.observers)try{s.next?.(t)}catch(t){o(t)}this._stopProcedure(),this._complete(),this._doneEvent=(i=this.id,r=this._snapshot.output,{type:`xstate.done.actor.${i}`,output:r}),this._parent&&this.system._relay(this,this._parent,this._doneEvent);break;case"error":this._error(this._snapshot.error)}var i,r;this.system._sendInspectionEvent({type:"@xstate.snapshot",actorRef:this,event:s,snapshot:t})}subscribe(t,s,e){const i=h(t,s,e);if(this._processingStatus!==c.Stopped)this.observers.add(i);else try{i.complete?.()}catch(t){o(t)}return{unsubscribe:()=>{this.observers.delete(i)}}}start(){if(this._processingStatus===c.Running)return this;this._syncSnapshot&&this.subscribe({next:t=>{"active"===t.status&&this.system._relay(this,this._parent,{type:`xstate.snapshot.${this.id}`,snapshot:t})},error:()=>{}}),this.system._register(this.sessionId,this),this._systemId&&this.system._set(this._systemId,this),this._processingStatus=c.Running;const t={type:"xstate.init",input:this.options.input};this.system._sendInspectionEvent({type:"@xstate.event",sourceRef:this._parent,actorRef:this,event:t});switch(this._snapshot.status){case"done":return this.update(this._snapshot,t),this;case"error":return this._error(this._snapshot.error),this}if(this.logic.start)try{this.logic.start(this._snapshot,this._actorScope)}catch(t){return this._snapshot={...this._snapshot,status:"error",error:t},this._error(t),this}return this.update(this._snapshot,t),this.options.devTools&&this.attachDevTools(),this.mailbox.start(),this}_process(t){let s,i;try{s=this.logic.transition(this._snapshot,t,this._actorScope)}catch(t){i={err:t}}if(i){const{err:t}=i;return this._snapshot={...this._snapshot,status:"error",error:t},void this._error(t)}this.update(s,t),t.type===e&&(this._stopProcedure(),this._complete())}_stop(){return this._processingStatus===c.Stopped?this:(this.mailbox.clear(),this._processingStatus===c.NotStarted?(this._processingStatus=c.Stopped,this):(this.mailbox.enqueue({type:e}),this))}stop(){if(this._parent)throw new Error("A non-root actor cannot be stopped directly.");return this._stop()}_complete(){for(const t of this.observers)try{t.complete?.()}catch(t){o(t)}this.observers.clear()}_reportError(t){if(!this.observers.size)return void(this._parent||o(t));let s=!1;for(const e of this.observers){const i=e.error;s||=!i;try{i?.(t)}catch(t){o(t)}}this.observers.clear(),s&&o(t)}_error(t){this._stopProcedure(),this._reportError(t),this._parent&&this.system._relay(this,this._parent,{type:`xstate.error.actor.${this.id}`,data:t})}_stopProcedure(){if(this._processingStatus!==c.Running)return this;for(const t of Object.keys(this.delayedEventsMap))this.clock.clearTimeout(this.delayedEventsMap[t]);return this.mailbox.clear(),this.mailbox=new s(this._process.bind(this)),this._processingStatus=c.Stopped,this.system._unregister(this),this}_send(t){this._processingStatus!==c.Stopped&&this.mailbox.enqueue(t)}send(t){this.system._relay(void 0,this,t)}delaySend(t){const{event:s,id:e,delay:i}=t,r=this.clock.setTimeout((()=>{this.system._relay(this,t.to??this,s)}),i);e&&(this.delayedEventsMap[e]=r)}cancel(t){this.clock.clearTimeout(this.delayedEventsMap[t]),delete this.delayedEventsMap[t]}attachDevTools(){const{devTools:t}=this.options;if(t){("function"==typeof t?t:r)(this)}}toJSON(){return{xstate$$type:1,id:this.id}}getPersistedSnapshot(t){return this.logic.getPersistedSnapshot(this._snapshot,t)}[n](){return this}getSnapshot(){return this._snapshot}}function d(t,s){return{config:t,transition:(s,e,i)=>({...s,context:t(s.context,e,i)}),getInitialState:(t,e)=>({status:"active",output:void 0,error:void 0,context:"function"==typeof s?s({input:e}):s}),getPersistedSnapshot:t=>t,restoreSnapshot:t=>t}}const l=new WeakMap;const _="xstate.observable.next",v="xstate.observable.error",f="xstate.observable.complete";const y="xstate.promise.resolve",b="xstate.promise.reject";const g=d((t=>{}),void 0);t.createEmptyActor=function(){return new u(g,t);var t},t.fromCallback=function(t){return{config:t,start:(s,e)=>{const{self:i,system:r}=e,o={receivers:void 0,dispose:void 0};l.set(i,o),o.dispose=t({input:s.input,system:r,self:i,sendBack:t=>{"stopped"!==i.getSnapshot().status&&i._parent&&r._relay(i,i._parent,t)},receive:t=>{o.receivers??=new Set,o.receivers.add(t)}})},transition:(t,s,i)=>{const r=l.get(i.self);return s.type===e?(t={...t,status:"stopped",error:void 0},r.dispose?.(),t):(r.receivers?.forEach((t=>t(s))),t)},getInitialState:(t,s)=>({status:"active",output:void 0,error:void 0,input:s}),getPersistedSnapshot:t=>t,restoreSnapshot:t=>t}},t.fromEventObservable=function(t){return{config:t,transition:(t,s)=>{if("active"!==t.status)return t;switch(s.type){case v:return{...t,status:"error",error:s.data,input:void 0,_subscription:void 0};case f:return{...t,status:"done",input:void 0,_subscription:void 0};case e:return t._subscription.unsubscribe(),{...t,status:"stopped",input:void 0,_subscription:void 0};default:return t}},getInitialState:(t,s)=>({status:"active",output:void 0,error:void 0,context:void 0,input:s,_subscription:void 0}),start:(s,{self:e,system:i})=>{"done"!==s.status&&(s._subscription=t({input:s.input,system:i,self:e}).subscribe({next:t=>{e._parent&&i._relay(e,e._parent,t)},error:t=>{i._relay(e,e,{type:v,data:t})},complete:()=>{i._relay(e,e,{type:f})}}))},getPersistedSnapshot:({_subscription:t,...s})=>s,restoreSnapshot:t=>({...t,_subscription:void 0})}},t.fromObservable=function(t){return{config:t,transition:(t,s,{self:i,id:r,defer:o,system:n})=>{if("active"!==t.status)return t;switch(s.type){case _:return{...t,context:s.data};case v:return{...t,status:"error",error:s.data,input:void 0,_subscription:void 0};case f:return{...t,status:"done",input:void 0,_subscription:void 0};case e:return t._subscription.unsubscribe(),{...t,status:"stopped",input:void 0,_subscription:void 0};default:return t}},getInitialState:(t,s)=>({status:"active",output:void 0,error:void 0,context:void 0,input:s,_subscription:void 0}),start:(s,{self:e,system:i})=>{"done"!==s.status&&(s._subscription=t({input:s.input,system:i,self:e}).subscribe({next:t=>{i._relay(e,e,{type:_,data:t})},error:t=>{i._relay(e,e,{type:v,data:t})},complete:()=>{i._relay(e,e,{type:f})}}))},getPersistedSnapshot:({_subscription:t,...s})=>s,restoreSnapshot:t=>({...t,_subscription:void 0})}},t.fromPromise=function(t){return{config:t,transition:(t,s)=>{if("active"!==t.status)return t;switch(s.type){case y:{const e=s.data;return{...t,status:"done",output:e,input:void 0}}case b:return{...t,status:"error",error:s.data,input:void 0};case e:return{...t,status:"stopped",input:void 0};default:return t}},start:(s,{self:e,system:i})=>{if("active"!==s.status)return;Promise.resolve(t({input:s.input,system:i,self:e})).then((t=>{"active"===e.getSnapshot().status&&i._relay(e,e,{type:y,data:t})}),(t=>{"active"===e.getSnapshot().status&&i._relay(e,e,{type:b,data:t})}))},getInitialState:(t,s)=>({status:"active",output:void 0,error:void 0,input:s}),getPersistedSnapshot:t=>t,restoreSnapshot:t=>t}},t.fromTransition=d,Object.defineProperty(t,"__esModule",{value:!0})}));
|
|
2
2
|
//# sourceMappingURL=xstate-actors.umd.min.js.map
|