@koordinates/xstate-tree 5.1.0-next.12 → 5.1.0-next.14
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/utils.js +6 -3
- package/lib/xstate-tree.d.ts +4 -1
- package/lib/xstateTree.js +13 -13
- package/package.json +1 -1
package/lib/utils.js
CHANGED
|
@@ -121,9 +121,12 @@ function mergeMeta(meta) {
|
|
|
121
121
|
}, {});
|
|
122
122
|
}
|
|
123
123
|
exports.mergeMeta = mergeMeta;
|
|
124
|
-
function getCircularReplacer() {
|
|
124
|
+
function getCircularReplacer(stripKeys) {
|
|
125
125
|
const seen = new WeakSet();
|
|
126
126
|
return (key, value) => {
|
|
127
|
+
if (stripKeys.includes(key)) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
127
130
|
if (typeof value === "object" && value !== null) {
|
|
128
131
|
if (seen.has(value)) {
|
|
129
132
|
// Circular reference found, discard key
|
|
@@ -135,7 +138,7 @@ function getCircularReplacer() {
|
|
|
135
138
|
return value;
|
|
136
139
|
};
|
|
137
140
|
}
|
|
138
|
-
function toJSON(value) {
|
|
139
|
-
return JSON.parse(JSON.stringify(value, getCircularReplacer()));
|
|
141
|
+
function toJSON(value, stripKeys = []) {
|
|
142
|
+
return JSON.parse(JSON.stringify(value, getCircularReplacer(stripKeys)));
|
|
140
143
|
}
|
|
141
144
|
exports.toJSON = toJSON;
|
package/lib/xstate-tree.d.ts
CHANGED
|
@@ -136,7 +136,9 @@ export declare function buildCreateRoute(history: () => XstateTreeHistory, baseP
|
|
|
136
136
|
export declare function buildRootComponent<TMachine extends AnyXstateTreeMachine>(options: {
|
|
137
137
|
machine: TMachine;
|
|
138
138
|
} & MarkOptionalLikePropertiesOptional<RootOptions<InputFrom<TMachine>>>): {
|
|
139
|
-
(
|
|
139
|
+
({ children, }: {
|
|
140
|
+
children?: React_2.ReactNode;
|
|
141
|
+
}): JSX.Element;
|
|
140
142
|
rootMachine: TMachine;
|
|
141
143
|
};
|
|
142
144
|
|
|
@@ -699,6 +701,7 @@ export declare type View<TActionsOutput, TSelectorsOutput, TSlots extends readon
|
|
|
699
701
|
slots: Record<GetSlotNames<TSlots>, React_2.ComponentType>;
|
|
700
702
|
actions: TActionsOutput;
|
|
701
703
|
selectors: TSelectorsOutput;
|
|
704
|
+
children?: React_2.ReactNode;
|
|
702
705
|
}>;
|
|
703
706
|
|
|
704
707
|
/**
|
package/lib/xstateTree.js
CHANGED
|
@@ -69,7 +69,7 @@ interpreter) {
|
|
|
69
69
|
return interpreter.sessionId;
|
|
70
70
|
}
|
|
71
71
|
const getViewForInterpreter = (0, fast_memoize_1.default)((interpreter) => {
|
|
72
|
-
return react_2.default.memo(function InterpreterView() {
|
|
72
|
+
return react_2.default.memo(function InterpreterView({ children, }) {
|
|
73
73
|
const activeRouteEvents = (0, providers_1.useActiveRouteEvents)();
|
|
74
74
|
(0, react_2.useEffect)(() => {
|
|
75
75
|
if (activeRouteEvents) {
|
|
@@ -80,7 +80,7 @@ const getViewForInterpreter = (0, fast_memoize_1.default)((interpreter) => {
|
|
|
80
80
|
});
|
|
81
81
|
}
|
|
82
82
|
}, []);
|
|
83
|
-
return react_2.default.createElement(XstateTreeView, { actor: interpreter });
|
|
83
|
+
return react_2.default.createElement(XstateTreeView, { actor: interpreter }, children);
|
|
84
84
|
});
|
|
85
85
|
},
|
|
86
86
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -105,7 +105,7 @@ function useSlots(interpreter, slots) {
|
|
|
105
105
|
return slots.reduce((views, slot) => {
|
|
106
106
|
return {
|
|
107
107
|
...views,
|
|
108
|
-
[slot]: () => {
|
|
108
|
+
[slot]: (({ children: reactChildren }) => {
|
|
109
109
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
110
110
|
const [__, children] = (0, useService_1.useService)(interpreter);
|
|
111
111
|
if (slot.toString().endsWith("Multi")) {
|
|
@@ -116,26 +116,25 @@ function useSlots(interpreter, slots) {
|
|
|
116
116
|
const interpreterForSlot = children[`${slot.toLowerCase()}-slot`];
|
|
117
117
|
if (interpreterForSlot) {
|
|
118
118
|
const View = getViewForInterpreter(interpreterForSlot);
|
|
119
|
-
return react_2.default.createElement(View, null);
|
|
119
|
+
return react_2.default.createElement(View, null, reactChildren);
|
|
120
120
|
}
|
|
121
121
|
else {
|
|
122
122
|
// Waiting for the interpreter for this slot to be invoked
|
|
123
123
|
return null;
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
|
-
},
|
|
126
|
+
}),
|
|
127
127
|
};
|
|
128
128
|
}, {});
|
|
129
129
|
});
|
|
130
130
|
}
|
|
131
131
|
function XstateTreeMultiSlotView({ childInterpreters, }) {
|
|
132
|
-
console.log("XstateTreeMultiSlotView", childInterpreters);
|
|
133
132
|
return (react_2.default.createElement(react_2.default.Fragment, null, childInterpreters.map((i) => (react_2.default.createElement(XstateTreeView, { key: i.id, actor: i })))));
|
|
134
133
|
}
|
|
135
134
|
/**
|
|
136
135
|
* @internal
|
|
137
136
|
*/
|
|
138
|
-
function XstateTreeView({ actor }) {
|
|
137
|
+
function XstateTreeView({ actor, children }) {
|
|
139
138
|
const [current] = (0, useService_1.useService)(actor);
|
|
140
139
|
const currentRef = (0, react_2.useRef)(current);
|
|
141
140
|
currentRef.current = current;
|
|
@@ -175,7 +174,7 @@ function XstateTreeView({ actor }) {
|
|
|
175
174
|
inState: inState,
|
|
176
175
|
meta: (0, utils_1.mergeMeta)(current.getMeta()),
|
|
177
176
|
});
|
|
178
|
-
return (react_2.default.createElement(View, { selectors: selectorsRef.current, actions: actions, slots: slots }));
|
|
177
|
+
return (react_2.default.createElement(View, { selectors: selectorsRef.current, actions: actions, slots: slots }, children));
|
|
179
178
|
}
|
|
180
179
|
exports.XstateTreeView = XstateTreeView;
|
|
181
180
|
/**
|
|
@@ -211,7 +210,7 @@ function buildRootComponent(options) {
|
|
|
211
210
|
if (!machine._xstateTree.View) {
|
|
212
211
|
throw new Error("Root machine has no associated view");
|
|
213
212
|
}
|
|
214
|
-
const RootComponent = function XstateTreeRootComponent() {
|
|
213
|
+
const RootComponent = function XstateTreeRootComponent({ children, }) {
|
|
215
214
|
const lastSnapshotsRef = (0, react_2.useRef)({});
|
|
216
215
|
const [_, __, interpreter] = (0, react_1.useActor)(machine, {
|
|
217
216
|
input,
|
|
@@ -229,11 +228,12 @@ function buildRootComponent(options) {
|
|
|
229
228
|
break;
|
|
230
229
|
case "@xstate.snapshot":
|
|
231
230
|
const lastSnapshot = lastSnapshotsRef.current[event.actorRef.sessionId];
|
|
231
|
+
const strippedKeys = ["_subscription"];
|
|
232
232
|
if (!lastSnapshot) {
|
|
233
|
-
console.log(`[xstate-tree] initial snapshot: ${event.actorRef.id}`, (0, utils_1.toJSON)(event.snapshot));
|
|
233
|
+
console.log(`[xstate-tree] initial snapshot: ${event.actorRef.id}`, (0, utils_1.toJSON)(event.snapshot, strippedKeys));
|
|
234
234
|
}
|
|
235
235
|
else {
|
|
236
|
-
console.log(`[xstate-tree] snapshot: ${event.actorRef.id} transitioning to`, (0, utils_1.toJSON)(event.snapshot), "from", (0, utils_1.toJSON)(lastSnapshot));
|
|
236
|
+
console.log(`[xstate-tree] snapshot: ${event.actorRef.id} transitioning to`, (0, utils_1.toJSON)(event.snapshot, strippedKeys), "from", (0, utils_1.toJSON)(lastSnapshot, strippedKeys));
|
|
237
237
|
}
|
|
238
238
|
lastSnapshotsRef.current[event.actorRef.sessionId] = event.snapshot;
|
|
239
239
|
break;
|
|
@@ -367,10 +367,10 @@ function buildRootComponent(options) {
|
|
|
367
367
|
}, [activeRoute]);
|
|
368
368
|
if (routingProviderValue) {
|
|
369
369
|
return (react_2.default.createElement(routing_1.RoutingContext.Provider, { value: routingProviderValue },
|
|
370
|
-
react_2.default.createElement(XstateTreeView, { actor: interpreter })));
|
|
370
|
+
react_2.default.createElement(XstateTreeView, { actor: interpreter }, children)));
|
|
371
371
|
}
|
|
372
372
|
else {
|
|
373
|
-
return react_2.default.createElement(XstateTreeView, { actor: interpreter });
|
|
373
|
+
return react_2.default.createElement(XstateTreeView, { actor: interpreter }, children);
|
|
374
374
|
}
|
|
375
375
|
};
|
|
376
376
|
RootComponent.rootMachine = machine;
|
package/package.json
CHANGED