Skip to content

Commit f8d4fc0

Browse files
committed
Removed State#toStrings method
1 parent 340aee6 commit f8d4fc0

File tree

6 files changed

+5
-172
lines changed

6 files changed

+5
-172
lines changed

.changeset/clean-turkeys-cough.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'xstate': major
3+
---
4+
5+
Removed `State#toStrings` method.

packages/core/src/State.ts

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import isDevelopment from '#is-development';
2-
import { STATE_DELIMITER } from './constants.ts';
32
import { $$ACTOR_TYPE } from './interpreter.ts';
43
import { memo } from './memo.ts';
54
import { MachineSnapshot } from './StateMachine.ts';
@@ -172,7 +171,6 @@ export class State<
172171
this.context = config.context;
173172
this.historyValue = config.historyValue || {};
174173
this.matches = this.matches.bind(this);
175-
this.toStrings = this.toStrings.bind(this);
176174
this.configuration =
177175
config.configuration ??
178176
Array.from(getConfiguration(getStateNodes(machine.root, config.value)));
@@ -185,24 +183,6 @@ export class State<
185183
(this as any).error = config.error;
186184
}
187185

188-
/**
189-
* Returns an array of all the string leaf state node paths.
190-
* @param stateValue
191-
* @param delimiter The character(s) that separate each subpath in the string state node path.
192-
*/
193-
public toStrings(stateValue: StateValue = this.value): string[] {
194-
if (typeof stateValue === 'string') {
195-
return [stateValue];
196-
}
197-
const valueKeys = Object.keys(stateValue);
198-
199-
return valueKeys.concat(
200-
...valueKeys.map((key) =>
201-
this.toStrings(stateValue[key]).map((s) => key + STATE_DELIMITER + s)
202-
)
203-
);
204-
}
205-
206186
public toJSON() {
207187
const { configuration, tags, machine, ...jsonValues } = this;
208188

packages/core/test/state.test.ts

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -219,28 +219,6 @@ describe('State', () => {
219219
});
220220
});
221221

222-
describe('State.prototype.toStrings', () => {
223-
it('should return all state paths as strings', () => {
224-
const actorRef = createActor(exampleMachine).start();
225-
actorRef.send({
226-
type: 'TO_TWO',
227-
foo: 'test'
228-
});
229-
230-
expect(actorRef.getSnapshot().toStrings()).toEqual([
231-
'two',
232-
'two.deep',
233-
'two.deep.foo'
234-
]);
235-
});
236-
237-
it('should keep reference to state instance after destructuring', () => {
238-
expect(createActor(exampleMachine).getSnapshot().toStrings()).toEqual([
239-
'one'
240-
]);
241-
});
242-
});
243-
244222
describe('status', () => {
245223
it('should show that a machine has not reached its final state', () => {
246224
expect(createActor(exampleMachine).getSnapshot().status).not.toBe('done');

packages/xstate-solid/src/deriveServiceState.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ export const deriveServiceState = <
2929
return {
3030
...state,
3131
toJSON: state.toJSON,
32-
toStrings: state.toStrings,
3332
can: state.can,
3433
hasTag: state.hasTag,
3534
nextEvents: state.nextEvents,

packages/xstate-solid/test/useActor.test.tsx

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -334,71 +334,6 @@ describe('useActor', () => {
334334
render(() => <Test />);
335335
});
336336

337-
it('should be reactive to toStrings method calls', () => {
338-
const machine = createMachine({
339-
initial: 'green',
340-
states: {
341-
green: {
342-
on: {
343-
TRANSITION: 'yellow'
344-
}
345-
},
346-
yellow: {
347-
on: {
348-
TRANSITION: 'red'
349-
}
350-
},
351-
red: {
352-
on: {
353-
TRANSITION: 'green'
354-
}
355-
}
356-
}
357-
});
358-
359-
const App = () => {
360-
const service = createActor(machine).start();
361-
const [state, send] = useActor(service);
362-
const [toStrings, setToStrings] = createSignal(state().toStrings());
363-
createEffect(
364-
on(
365-
() => state().value,
366-
() => {
367-
setToStrings(state().toStrings());
368-
}
369-
)
370-
);
371-
return (
372-
<div>
373-
<button
374-
data-testid="transition-button"
375-
onclick={() => send({ type: 'TRANSITION' })}
376-
/>
377-
<div data-testid="to-strings">{JSON.stringify(toStrings())}</div>
378-
</div>
379-
);
380-
};
381-
382-
render(() => <App />);
383-
const toStringsEl = screen.getByTestId('to-strings');
384-
const transitionBtn = screen.getByTestId('transition-button');
385-
386-
// Green
387-
expect(toStringsEl.textContent).toEqual('["green"]');
388-
transitionBtn.click();
389-
390-
// Yellow
391-
expect(toStringsEl.textContent).toEqual('["yellow"]');
392-
transitionBtn.click();
393-
394-
// Red
395-
expect(toStringsEl.textContent).toEqual('["red"]');
396-
transitionBtn.click();
397-
398-
// Green
399-
expect(toStringsEl.textContent).toEqual('["green"]');
400-
});
401-
402337
it('should be reactive to toJSON method calls', () => {
403338
const machine = createMachine({
404339
initial: 'green',

packages/xstate-solid/test/useMachine.test.tsx

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -713,70 +713,6 @@ describe('useMachine hook', () => {
713713
expect(screen.queryByTestId('event-1')).not.toBeTruthy();
714714
});
715715

716-
it('should be reactive to toStrings method calls', () => {
717-
const machine = createMachine({
718-
initial: 'green',
719-
states: {
720-
green: {
721-
on: {
722-
TRANSITION: 'yellow'
723-
}
724-
},
725-
yellow: {
726-
on: {
727-
TRANSITION: 'red'
728-
}
729-
},
730-
red: {
731-
on: {
732-
TRANSITION: 'green'
733-
}
734-
}
735-
}
736-
});
737-
738-
const App = () => {
739-
const [state, send] = useMachine(machine);
740-
const [toStrings, setToStrings] = createSignal(state.toStrings());
741-
createEffect(
742-
on(
743-
() => state.value,
744-
() => {
745-
setToStrings(state.toStrings());
746-
}
747-
)
748-
);
749-
return (
750-
<div>
751-
<button
752-
data-testid="transition-button"
753-
onclick={() => send({ type: 'TRANSITION' })}
754-
/>
755-
<div data-testid="to-strings">{JSON.stringify(toStrings())}</div>
756-
</div>
757-
);
758-
};
759-
760-
render(() => <App />);
761-
const toStringsEl = screen.getByTestId('to-strings');
762-
const transitionBtn = screen.getByTestId('transition-button');
763-
764-
// Green
765-
expect(toStringsEl.textContent).toEqual('["green"]');
766-
transitionBtn.click();
767-
768-
// Yellow
769-
expect(toStringsEl.textContent).toEqual('["yellow"]');
770-
transitionBtn.click();
771-
772-
// Red
773-
expect(toStringsEl.textContent).toEqual('["red"]');
774-
transitionBtn.click();
775-
776-
// Green
777-
expect(toStringsEl.textContent).toEqual('["green"]');
778-
});
779-
780716
it('should be reactive to toJSON method calls', () => {
781717
const machine = createMachine({
782718
initial: 'green',

0 commit comments

Comments
 (0)