@koordinates/xstate-tree 5.1.0-next.10 → 5.1.0-next.12

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/lib/builders.js CHANGED
@@ -31,9 +31,19 @@ function createXStateTreeMachine(machine, options) {
31
31
  View: options.View,
32
32
  slots: (options.slots ?? []),
33
33
  };
34
- return machineWithMeta;
34
+ return fixProvideLosingXstateTreeMeta(machineWithMeta);
35
35
  }
36
36
  exports.createXStateTreeMachine = createXStateTreeMachine;
37
+ function fixProvideLosingXstateTreeMeta(machine) {
38
+ const originalProvide = machine.provide.bind(machine);
39
+ machine.provide = (impl) => {
40
+ const result = originalProvide(impl);
41
+ result._xstateTree = machine._xstateTree;
42
+ fixProvideLosingXstateTreeMeta(result);
43
+ return result;
44
+ };
45
+ return machine;
46
+ }
37
47
  /**
38
48
  * @public
39
49
  *
@@ -329,7 +329,7 @@ declare type OmitOptional<T> = {
329
329
  */
330
330
  export declare function onBroadcast(handler: (event: GlobalEvents) => void): () => void;
331
331
 
332
- declare type Options<TStateMachine extends AnyStateMachine> = {
332
+ declare type Options<TStateMachine extends AnyXstateTreeMachine> = {
333
333
  /**
334
334
  * Displayed while the promise is resolving, defaults to returning null
335
335
  */
@@ -370,6 +370,14 @@ export declare type Query<T> = T extends {
370
370
  query: infer TQuery;
371
371
  } ? TQuery : undefined;
372
372
 
373
+ /**
374
+ * Repairs the return type of the `provide` function on XstateTreeMachines to correctly return
375
+ * an XstateTreeMachine type instead of an xstate StateMachine
376
+ */
377
+ declare type RepairProvideReturnType<T extends AnyStateMachine, TSelectorsOutput, TActionsOutput, TSlots extends readonly Slot[]> = {
378
+ [K in keyof T]: K extends "provide" ? (...args: Parameters<T[K]>) => XstateTreeMachine<T, TSelectorsOutput, TActionsOutput, TSlots> : T[K];
379
+ };
380
+
373
381
  declare type ResolveZodType<T extends Z.ZodType<any> | undefined> = undefined extends T ? undefined : Z.TypeOf<Exclude<T, undefined>>;
374
382
 
375
383
  declare type Return<TRoutes extends Route<any, any, any, any>[]> = {
@@ -716,7 +724,7 @@ export declare type XstateTreeHistory<T = unknown> = History_2<{
716
724
  /**
717
725
  * @public
718
726
  */
719
- export declare type XstateTreeMachine<TMachine extends AnyStateMachine, TSelectorsOutput = ContextFrom<TMachine>, TActionsOutput = Record<never, string>, TSlots extends readonly Slot[] = Slot[]> = TMachine & XstateTreeMachineInjection<TMachine, TSelectorsOutput, TActionsOutput, TSlots>;
727
+ export declare type XstateTreeMachine<TMachine extends AnyStateMachine, TSelectorsOutput = ContextFrom<TMachine>, TActionsOutput = Record<never, string>, TSlots extends readonly Slot[] = Slot[]> = RepairProvideReturnType<TMachine, TSelectorsOutput, TActionsOutput, TSlots> & XstateTreeMachineInjection<TMachine, TSelectorsOutput, TActionsOutput, TSlots>;
720
728
 
721
729
  /**
722
730
  * @internal
package/lib/xstateTree.js CHANGED
@@ -221,6 +221,10 @@ function buildRootComponent(options) {
221
221
  console.log(`[xstate-tree] actor spawned: ${event.actorRef.id}`);
222
222
  break;
223
223
  case "@xstate.event":
224
+ // Ignore internal events
225
+ if (event.event.type.includes("xstate.")) {
226
+ return;
227
+ }
224
228
  console.log(`[xstate-tree] event: ${event.sourceRef ? event.sourceRef.id : "UNKNOWN"} -> ${event.event.type} -> ${event.actorRef.id}`, event.event);
225
229
  break;
226
230
  case "@xstate.snapshot":
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@koordinates/xstate-tree",
3
3
  "main": "lib/index.js",
4
4
  "types": "lib/xstate-tree.d.ts",
5
- "version": "5.1.0-next.10",
5
+ "version": "5.1.0-next.12",
6
6
  "license": "MIT",
7
7
  "description": "Build UIs with Actors using xstate and React",
8
8
  "keywords": [