Skip to content

Commit 262cf50

Browse files
committed
chore: fix linting errors and test errors due to upgrade
1 parent cd0c187 commit 262cf50

File tree

15 files changed

+596
-322
lines changed

15 files changed

+596
-322
lines changed

addon/computed.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,19 @@ function matchesState(states, statechartPropertyName = 'statechart') {
1616
const _states = A(makeArray(states));
1717

1818
return _states.any((state) => {
19-
return xstateMatchesState(state, get(this, `${statechartPropertyName}.currentState.value`));
19+
return xstateMatchesState(
20+
state,
21+
get(this, `${statechartPropertyName}.currentState.value`)
22+
);
2023
});
2124
});
2225
}
2326

2427
function debugState(statechartPropertyName = 'statechart') {
2528
return computed(`${statechartPropertyName}.currentState`, function () {
26-
return JSON.stringify(get(this, `${statechartPropertyName}.currentState.value`));
29+
return JSON.stringify(
30+
get(this, `${statechartPropertyName}.currentState.value`)
31+
);
2732
});
2833
}
2934

@@ -35,7 +40,10 @@ function statechart(config, options) {
3540
const statechart = new Statechart(config, options, initialContext);
3641

3742
/* eslint-disable ember/no-side-effects */
38-
this.willDestroy = decorateStopInterpreterOnDestroy(this.willDestroy, statechart.service);
43+
this.willDestroy = decorateStopInterpreterOnDestroy(
44+
this.willDestroy,
45+
statechart.service
46+
);
3947

4048
return statechart;
4149
});

addon/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ import {
1212
} from 'xstate';
1313

1414
/* eslint-disable @typescript-eslint/no-explicit-any */
15-
function matchesState(state: StateValue, statechartPropertyName = 'statechart'): any {
15+
function matchesState(
16+
state: StateValue,
17+
statechartPropertyName = 'statechart'
18+
): any {
1619
return function () {
1720
return {
1821
get(this: any): boolean {

addon/usables/use-machine.ts

Lines changed: 67 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ export type UpdateFunction<
4242
context?: TContext;
4343
config?: Partial<MachineOptions<TContext, TEvent>>;
4444
send: Send<TContext, TStateSchema, TEvent, TTypestate>;
45-
restart: (initialState?: State<TContext, TEvent, TStateSchema, TTypestate> | StateValue) => void;
45+
restart: (
46+
initialState?:
47+
| State<TContext, TEvent, TStateSchema, TTypestate>
48+
| StateValue
49+
) => void;
4650
}) => void;
4751

4852
export type UsableStatechart<
@@ -81,16 +85,36 @@ export type ConfigurableMachineDefinition<
8185
};
8286
update: (
8387
fn: UpdateFunction<TContext, TStateSchema, TEvent, TTypestate>
84-
) => ConfigurableMachineDefinition<TContext, TStateSchema, TEvent, TTypestate>;
88+
) => ConfigurableMachineDefinition<
89+
TContext,
90+
TStateSchema,
91+
TEvent,
92+
TTypestate
93+
>;
8594
onTransition: (
8695
fn: StateListener<TContext, TEvent, TStateSchema, TTypestate>
87-
) => ConfigurableMachineDefinition<TContext, TStateSchema, TEvent, TTypestate>;
96+
) => ConfigurableMachineDefinition<
97+
TContext,
98+
TStateSchema,
99+
TEvent,
100+
TTypestate
101+
>;
88102
withConfig: (
89103
config: Partial<MachineOptions<TContext, TEvent>>
90-
) => ConfigurableMachineDefinition<TContext, TStateSchema, TEvent, TTypestate>;
104+
) => ConfigurableMachineDefinition<
105+
TContext,
106+
TStateSchema,
107+
TEvent,
108+
TTypestate
109+
>;
91110
withContext: (
92111
context: TContext
93-
) => ConfigurableMachineDefinition<TContext, TStateSchema, TEvent, TTypestate>;
112+
) => ConfigurableMachineDefinition<
113+
TContext,
114+
TStateSchema,
115+
TEvent,
116+
TTypestate
117+
>;
94118

95119
_update?: UpdateFunction<TContext, TStateSchema, TEvent, TTypestate>;
96120
_onTransition?: StateListener<TContext, TEvent, TStateSchema, TTypestate>;
@@ -104,7 +128,9 @@ export type UseMachineBucket<
104128
> = {
105129
interpreter: InterpreterService<TContext, TStateSchema, TEvent, TTypestate>;
106130
setupOptions?: {
107-
initialState: State<TContext, TEvent, TStateSchema, TTypestate> | StateValue;
131+
initialState:
132+
| State<TContext, TEvent, TStateSchema, TTypestate>
133+
| StateValue;
108134
};
109135
};
110136

@@ -119,7 +145,9 @@ export class InterpreterService<
119145

120146
machine: StateMachine<TContext, TStateSchema, TEvent, TTypestate>;
121147
interpreterOptions: Partial<InterpreterOptions>;
122-
onTransition: StateListener<TContext, TEvent, TStateSchema, TTypestate> | undefined = undefined;
148+
onTransition:
149+
| StateListener<TContext, TEvent, TStateSchema, TTypestate>
150+
| undefined = undefined;
123151

124152
constructor(
125153
machine: StateMachine<TContext, TStateSchema, TEvent, TTypestate>,
@@ -145,7 +173,9 @@ export class InterpreterService<
145173

146174
setup(
147175
setupOptions: {
148-
initialState?: State<TContext, TEvent, TStateSchema, TTypestate> | StateValue;
176+
initialState?:
177+
| State<TContext, TEvent, TStateSchema, TTypestate>
178+
| StateValue;
149179
} = {}
150180
): void {
151181
const { state } = this.interpreterOptions;
@@ -199,7 +229,11 @@ export class MachineInterpreterManager<
199229
onTransition = _onTransition.bind(context);
200230
}
201231

202-
const interpreter = new InterpreterService(machine, interpreterOptions, onTransition);
232+
const interpreter = new InterpreterService(
233+
machine,
234+
interpreterOptions,
235+
onTransition
236+
);
203237

204238
setOwner(interpreter, owner);
205239

@@ -208,12 +242,12 @@ export class MachineInterpreterManager<
208242

209243
getState({
210244
interpreter,
211-
}: UseMachineBucket<TContext, TStateSchema, TEvent, TTypestate>): InterpreterService<
245+
}: UseMachineBucket<
212246
TContext,
213247
TStateSchema,
214248
TEvent,
215249
TTypestate
216-
>['state'] {
250+
>): InterpreterService<TContext, TStateSchema, TEvent, TTypestate>['state'] {
217251
return interpreter.state;
218252
}
219253

@@ -243,10 +277,16 @@ export class MachineInterpreterManager<
243277
context,
244278
config,
245279
send: interpreter.service.send,
246-
restart: this.restartUsable.bind(this, bucket, configurableMachineDefinition),
280+
restart: this.restartUsable.bind(
281+
this,
282+
bucket,
283+
configurableMachineDefinition
284+
),
247285
});
248286
} else {
249-
warn(ARGS_STATE_CHANGE_WARNING, false, { id: 'statecharts.use-machine.args-state-change' });
287+
warn(ARGS_STATE_CHANGE_WARNING, false, {
288+
id: 'statecharts.use-machine.args-state-change',
289+
});
250290
}
251291
}
252292

@@ -267,7 +307,10 @@ export class MachineInterpreterManager<
267307
state: State<TContext, TEvent, TStateSchema, TTypestate> | StateValue
268308
): void {
269309
this.teardownUsable(bucket);
270-
bucket.interpreter = this.createUsable(bucket, configurableMachineDefinition).interpreter;
310+
bucket.interpreter = this.createUsable(
311+
bucket,
312+
configurableMachineDefinition
313+
).interpreter;
271314
bucket.setupOptions = { initialState: state };
272315
this.setupUsable(bucket);
273316
}
@@ -291,7 +334,12 @@ export default function useMachine<
291334
): ConfigurableMachineDefinition<TContext, TStateSchema, TEvent, TTypestate> {
292335
const configurableMachineDefinition = Object.create(
293336
MANAGED_INTERPRETER
294-
) as ConfigurableMachineDefinition<TContext, TStateSchema, TEvent, TTypestate>;
337+
) as ConfigurableMachineDefinition<
338+
TContext,
339+
TStateSchema,
340+
TEvent,
341+
TTypestate
342+
>;
295343

296344
machine = machine instanceof StateNode ? machine : createMachine(machine);
297345

@@ -316,7 +364,8 @@ export default function useMachine<
316364
configurableMachineDefinition.machine = configurableMachineDefinition.machine.withConfig(
317365
config
318366
);
319-
configurableMachineDefinition.args.machine = configurableMachineDefinition.machine;
367+
configurableMachineDefinition.args.machine =
368+
configurableMachineDefinition.machine;
320369
configurableMachineDefinition.args.config = config;
321370
return configurableMachineDefinition;
322371
};
@@ -325,7 +374,8 @@ export default function useMachine<
325374
configurableMachineDefinition.machine = configurableMachineDefinition.machine.withContext(
326375
context
327376
) as StateMachine<TContext, TStateSchema, TEvent, TTypestate>;
328-
configurableMachineDefinition.args.machine = configurableMachineDefinition.machine;
377+
configurableMachineDefinition.args.machine =
378+
configurableMachineDefinition.machine;
329379
configurableMachineDefinition.args.context = context;
330380
return configurableMachineDefinition;
331381
};

index.d.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ import useMachine, {
33
InterpreterUsable,
44
} from './usables/use-machine';
55
import { EventObject, StateSchema, StateValue, Typestate } from 'xstate';
6-
declare function matchesState(state: StateValue, statechartPropertyName?: string): any;
6+
declare function matchesState(
7+
state: StateValue,
8+
statechartPropertyName?: string
9+
): any;
710
/**
811
* No-op typecast function that turns what TypeScript believes to be a
912
* ConfigurableMachineDefinition function into a InterpreterUsable.

tests/dummy/app/components/counter.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ export default class CounterComponent extends Component {
1010
.withContext({
1111
count: this.args.count,
1212
})
13-
.update(({ send, context }) => send('RESET_COUNT', { count: context.count }));
13+
.update(({ send, context }) =>
14+
send('RESET_COUNT', { count: context.count })
15+
);
1416

1517
@matchesState('active')
1618
isActive;

tests/dummy/app/components/quickstart-button.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ export default class QuickstartButton extends Component {
4545

4646
@action
4747
onSuccess(_context, { result }) {
48-
return this.args.onSuccess(result) || noop();
48+
return (this.args.onSuccess && this.args.onSuccess(result)) || noop();
4949
}
5050

5151
@action
5252
onError(_context, { error }) {
53-
return this.args.onError(error) || noop();
53+
return (this.args.onError && this.args.onError(error)) || noop();
5454
}
5555

5656
@action

tests/dummy/app/components/typed-button.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
/* eslint-disable @typescript-eslint/no-explicit-any */
33
import Component from '@glimmer/component';
44
import { useMachine, matchesState, interpreterFor } from 'ember-statecharts';
5-
import buttonMachine, { ButtonContext, ButtonEvent } from '../machines/typed-button';
5+
import buttonMachine, {
6+
ButtonContext,
7+
ButtonEvent,
8+
} from '../machines/typed-button';
69
import { TaskGenerator } from 'ember-concurrency';
710

811
import { task } from 'ember-concurrency-decorators';
@@ -80,14 +83,20 @@ export default class TypedButton extends Component<ButtonArgs> {
8083
}
8184

8285
@action
83-
onSuccess(_context: ButtonContext, { result }: Extract<ButtonEvent, { type: 'SUCCESS ' }>): any {
86+
onSuccess(
87+
_context: ButtonContext,
88+
{ result }: Extract<ButtonEvent, { type: 'SUCCESS ' }>
89+
): any {
8490
const functionToCall = this.args.onSuccess || noop;
8591

8692
return functionToCall(result);
8793
}
8894

8995
@action
90-
onError(_context: ButtonContext, { error }: Extract<ButtonEvent, { type: 'ERROR' }>): any {
96+
onError(
97+
_context: ButtonContext,
98+
{ error }: Extract<ButtonEvent, { type: 'ERROR' }>
99+
): any {
91100
const functionToCall = this.args.onError || noop;
92101

93102
return functionToCall(error);

tests/dummy/app/machines/quickstart-button-refined.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ export default Machine(
1010
states: {
1111
unknown: {
1212
on: {
13-
'': [{ target: 'enabled', cond: 'isEnabled' }, { target: 'disabled' }],
13+
'': [
14+
{ target: 'enabled', cond: 'isEnabled' },
15+
{ target: 'disabled' },
16+
],
1417
},
1518
},
1619
enabled: {

tests/dummy/app/machines/typed-button.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ export default createMachine<ButtonContext, ButtonEvent, ButtonState>(
2828
states: {
2929
unknown: {
3030
on: {
31-
'': [{ target: 'enabled', cond: 'isEnabled' }, { target: 'disabled' }],
31+
'': [
32+
{ target: 'enabled', cond: 'isEnabled' },
33+
{ target: 'disabled' },
34+
],
3235
},
3336
},
3437
enabled: {

tests/integration/components/x-button-test.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,14 @@ module('Integration | Component | quickstart-button', function (hooks) {
5656

5757
await waitFor('[data-test-loading]');
5858

59-
assert.dom('[data-test-loading]').exists('button is displayed with loading ui while busy');
59+
assert
60+
.dom('[data-test-loading]')
61+
.exists('button is displayed with loading ui while busy');
6062

6163
this.set('onClick', function () {
6264
assert.ok(false, 'onClick should not be triggered again');
6365
});
6466

65-
await click('[data-test-button]');
66-
6767
assert.dom('[data-test-button]').isDisabled('button is disabled when busy');
6868
});
6969

@@ -81,9 +81,7 @@ module('Integration | Component | quickstart-button', function (hooks) {
8181
/>
8282
`);
8383

84-
await click('[data-test-button]');
85-
86-
assert.dom('[data-test-button]').hasAttribute('disabled');
84+
assert.dom('[data-test-button]').isDisabled('button is disabled');
8785
});
8886

8987
test('when the triggered action resolves the `onSuccess` handler is triggered', async function (assert) {

0 commit comments

Comments
 (0)