Skip to content
This repository was archived by the owner on Apr 8, 2020. It is now read-only.

Commit 87d770e

Browse files
committed
Use distintive state names
1 parent a051793 commit 87d770e

File tree

4 files changed

+98
-98
lines changed

4 files changed

+98
-98
lines changed

src/composables/withTransitionState.spec.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ describe("withTransitionState.tsx", () => {
3434
reducer = spy(() => ({ state }));
3535
wrapper = getWrapper({ children: <span /> }, reducer);
3636
});
37-
it("should dispatch Init", () => {
38-
assert.isTrue(reducer.calledWith(StateID.EntryPoint, { kind: ActionID.Init, props: {} }));
37+
it("should dispatch New", () => {
38+
assert.isTrue(reducer.calledWith(StateID.EntryPoint, { kind: ActionID.New, props: {} }));
3939
});
4040
it("should return transitionState", () => {
4141
assert.deepEqual(wrapper.props().transitionState, pick(state, "style", "className"));

src/composables/withTransitionState.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ export const withTransitionState = (reduce: Reducer) => combine(
4242
"transitionState", "setTransitionState",
4343
({actionProps}) =>
4444
pick(
45-
reduce(StateID.EntryPoint, { kind: ActionID.Init, props: actionProps }).state,
45+
reduce(StateID.EntryPoint, { kind: ActionID.New, props: actionProps }).state,
4646
"style", "className", "inTransition",
4747
),
4848
),
4949
withHandlers<PropsUnion, PropsOut>(
5050
(initialProps) => {
51-
let stateID = reduce(StateID.EntryPoint, { kind: ActionID.Init, props: initialProps }).state.id;
51+
let stateID = reduce(StateID.EntryPoint, { kind: ActionID.New, props: initialProps }).state.id;
5252
let cancelPending: () => void = null;
5353
const cancelPendingIfExistent = () => {
5454
if (cancelPending) {

src/reducer.spec.ts

+56-56
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import { transit } from "./transit";
44
import {
55
reducer, StateID, StateIDList, ActionID, ActionProps, TransitionState, getState,
66
getDelay, transitionNames, hasTransition,
7-
defaultInitState, activeInitState, appearInitState,
7+
defaultNewState, activeNewState, appearNewState,
88
defaultState, activeState,
9-
appearPendingState, enterPendingState, leavePendingState,
9+
appearInitState, enterInitState, leaveInitState,
1010
appearPrepareState, enterPrepareState, leavePrepareState,
1111
appearTriggeredState, enterTriggeredState, leaveTriggeredState,
1212
appearStartedState, enterStartedState, leaveStartedState,
@@ -69,7 +69,7 @@ describe("reducer.ts", () => {
6969
});
7070
it("should return transition init state", () => {
7171
transitionNames.forEach((name) => {
72-
const id = StateID.EnterPending;
72+
const id = StateID.EnterInit;
7373
const inTransition = false;
7474
const style = { top: 0 };
7575
const className = "foo";
@@ -115,7 +115,7 @@ describe("reducer.ts", () => {
115115
it("should return transition init fallback state", () => {
116116
transitionNames.forEach((name) => {
117117
const fallbackName = name === "leave" ? "active" : "default";
118-
const id = StateID.EnterPending;
118+
const id = StateID.EnterInit;
119119
const inTransition = false;
120120
const style = { top: 0 };
121121
const className = "foo";
@@ -203,7 +203,7 @@ describe("reducer.ts", () => {
203203
});
204204
});
205205
it("should fallback appear to enter", () => {
206-
const id = StateID.AppearInit;
206+
const id = StateID.AppearNew;
207207
const style = { left: "0px" };
208208
const className = "foo";
209209
const inTransition = true;
@@ -234,7 +234,7 @@ it("should fallback appear to enter", () => {
234234
});
235235
});
236236
it("should fallback appearInit to enterInit", () => {
237-
const id = StateID.AppearInit;
237+
const id = StateID.AppearNew;
238238
const style = { left: "0px" };
239239
const className = "foo";
240240
const inTransition = false;
@@ -266,16 +266,16 @@ it("should fallback appearInit to enterInit", () => {
266266
});
267267
describe("states", () => {
268268
describe(
269-
"defaultInitState",
270-
testState(StateID.DefaultInit, "defaultStyle", (props) => defaultInitState(props)),
269+
"defaultNewState",
270+
testState(StateID.DefaultNew, "defaultStyle", (props) => defaultNewState(props)),
271271
);
272272
describe(
273-
"activeInitState",
274-
testState(StateID.ActiveInit, "activeStyle", (props) => activeInitState(props)),
273+
"activeNewState",
274+
testState(StateID.ActiveNew, "activeStyle", (props) => activeNewState(props)),
275275
);
276276
describe(
277-
"appearInitState",
278-
testState(StateID.AppearInit, "appearInitStyle", (props) => appearInitState(props)),
277+
"appearNewState",
278+
testState(StateID.AppearNew, "appearInitStyle", (props) => appearNewState(props)),
279279
);
280280
describe(
281281
"defaultState",
@@ -286,16 +286,16 @@ describe("states", () => {
286286
testState(StateID.Active, "activeStyle", (props) => activeState(props)),
287287
);
288288
describe(
289-
"appearPendingState",
290-
testState(StateID.AppearPending, "appearInitStyle", (props) => appearPendingState(props)),
289+
"appearInitState",
290+
testState(StateID.AppearInit, "appearInitStyle", (props) => appearInitState(props)),
291291
);
292292
describe(
293-
"enterPendingState",
294-
testState(StateID.EnterPending, "enterInitStyle", (props) => enterPendingState(props)),
293+
"enterInitState",
294+
testState(StateID.EnterInit, "enterInitStyle", (props) => enterInitState(props)),
295295
);
296296
describe(
297-
"leavePendingState",
298-
testState(StateID.LeavePending, "leaveInitStyle", (props) => leavePendingState(props)),
297+
"leaveInitState",
298+
testState(StateID.LeaveInit, "leaveInitStyle", (props) => leaveInitState(props)),
299299
);
300300
describe(
301301
"appearPrepareState",
@@ -335,44 +335,44 @@ describe("states", () => {
335335
);
336336
});
337337
describe("actions", () => {
338-
describe("Init", () => {
339-
const actionID = ActionID.Init;
338+
describe("New", () => {
339+
const actionID = ActionID.New;
340340

341341
it("should fail when state is already initialized", () => {
342342
assert.throw(() => reducer(StateID.Active, { kind: actionID, props: {} }));
343343
});
344-
it("should become DefaultInit", () => {
344+
it("should become DefaultNew", () => {
345345
const {state, pending} = reducer(StateID.EntryPoint, { kind: actionID, props: { active: false } });
346346
assert.isUndefined(pending);
347-
assert.strictEqual(state.id, StateID.DefaultInit);
347+
assert.strictEqual(state.id, StateID.DefaultNew);
348348
});
349-
it("should become ActiveInit", () => {
349+
it("should become ActiveNew", () => {
350350
const {state, pending} = reducer(StateID.EntryPoint, { kind: actionID, props: { active: true } });
351351
assert.isUndefined(pending);
352-
assert.strictEqual(state.id, StateID.ActiveInit);
352+
assert.strictEqual(state.id, StateID.ActiveNew);
353353
});
354-
it("should become AppearInit", () => {
354+
it("should become AppearNew", () => {
355355
const {state, pending} = reducer(StateID.EntryPoint, {
356356
kind: actionID,
357357
props: {
358358
active: true, transitionAppear: true,
359359
},
360360
});
361361
assert.isUndefined(pending);
362-
assert.strictEqual(state.id, StateID.AppearInit);
362+
assert.strictEqual(state.id, StateID.AppearNew);
363363
});
364364
});
365365
describe("Mount", () => {
366366
const actionID = ActionID.Mount;
367-
it("should become AppearPending", () => {
368-
const {state, pending} = reducer(StateID.AppearInit, {
367+
it("should become AppearInit", () => {
368+
const {state, pending} = reducer(StateID.AppearNew, {
369369
kind: actionID,
370370
props: {
371371
appearStyle: {},
372372
},
373373
});
374374
assert.strictEqual(pending, ActionID.TransitionPrepare);
375-
assert.strictEqual(state.id, StateID.AppearPending);
375+
assert.strictEqual(state.id, StateID.AppearInit);
376376
});
377377

378378
it("should do nothing", () => {
@@ -382,44 +382,44 @@ describe("actions", () => {
382382
describe("TransitionInit", () => {
383383
const actionID = ActionID.TransitionInit;
384384
const validOrigin = [
385-
StateID.Active, StateID.ActiveInit, StateID.Default, StateID.DefaultInit, StateID.AppearInit,
385+
StateID.Active, StateID.ActiveNew, StateID.Default, StateID.DefaultNew, StateID.AppearNew,
386386
];
387387

388388
it("should fail on invalid state transitions", () => {
389389
StateIDList
390390
.filter((id) => validOrigin.indexOf(id) < 0)
391391
.forEach((id) => assert.throw(() => reducer(id, { kind: actionID, props: {} })));
392392
});
393-
it("should transit to enter pending state", () => {
394-
[StateID.Default, StateID.DefaultInit].forEach((id) => {
393+
it("should transit to enter init state", () => {
394+
[StateID.Default, StateID.DefaultNew].forEach((id) => {
395395
const {state, pending} = reducer(id, { kind: actionID, props: { enterStyle: {} } });
396396
assert.strictEqual(pending, ActionID.TransitionPrepare);
397-
assert.strictEqual(state.id, StateID.EnterPending);
397+
assert.strictEqual(state.id, StateID.EnterInit);
398398
});
399399
});
400-
it("should transit to leave pending state", () => {
401-
[StateID.Active, StateID.ActiveInit].forEach((id) => {
400+
it("should transit to leave init state", () => {
401+
[StateID.Active, StateID.ActiveNew].forEach((id) => {
402402
const {state, pending} = reducer(id, { kind: actionID, props: { leaveStyle: {} } });
403403
assert.strictEqual(pending, ActionID.TransitionPrepare);
404-
assert.strictEqual(state.id, StateID.LeavePending);
404+
assert.strictEqual(state.id, StateID.LeaveInit);
405405
});
406406
});
407-
it("should transit to appear pending state", () => {
408-
const id = StateID.AppearInit;
407+
it("should transit to appear init state", () => {
408+
const id = StateID.AppearNew;
409409
const {state, pending} = reducer(id, { kind: actionID, props: { appearStyle: {} } });
410410
assert.strictEqual(pending, ActionID.TransitionPrepare);
411-
assert.strictEqual(state.id, StateID.AppearPending);
411+
assert.strictEqual(state.id, StateID.AppearInit);
412412
});
413413
it("should skip to active and complete", () => {
414-
[StateID.Default, StateID.DefaultInit, StateID.AppearInit].forEach((id) => {
414+
[StateID.Default, StateID.DefaultNew, StateID.AppearNew].forEach((id) => {
415415
const {state, pending, completed} = reducer(id, { kind: actionID, props: {} });
416416
assert.isUndefined(pending);
417417
assert.strictEqual(state.id, StateID.Active);
418418
assert.isTrue(completed);
419419
});
420420
});
421421
it("should skip to default and complete", () => {
422-
[StateID.Active, StateID.ActiveInit].forEach((id) => {
422+
[StateID.Active, StateID.ActiveNew].forEach((id) => {
423423
const {state, pending, completed} = reducer(id, { kind: actionID, props: {} });
424424
assert.isUndefined(pending);
425425
assert.strictEqual(state.id, StateID.Default);
@@ -492,25 +492,25 @@ describe("actions", () => {
492492
});
493493
describe("TransitionTrigger", () => {
494494
const actionID = ActionID.TransitionTrigger;
495-
it("should transit to enter pending state", () => {
496-
[StateID.Default, StateID.DefaultInit].forEach((id) => {
495+
it("should transit to enter init state", () => {
496+
[StateID.Default, StateID.DefaultNew].forEach((id) => {
497497
const {state, pending} = reducer(id, { kind: actionID, props: { enterStyle: {} } });
498498
assert.strictEqual(pending, ActionID.TransitionPrepare);
499-
assert.strictEqual(state.id, StateID.EnterPending);
499+
assert.strictEqual(state.id, StateID.EnterInit);
500500
});
501501
});
502-
it("should transit to leave pending state", () => {
503-
[StateID.Active, StateID.ActiveInit].forEach((id) => {
502+
it("should transit to leave init state", () => {
503+
[StateID.Active, StateID.ActiveNew].forEach((id) => {
504504
const {state, pending} = reducer(id, { kind: actionID, props: { leaveStyle: {} } });
505505
assert.strictEqual(pending, ActionID.TransitionPrepare);
506-
assert.strictEqual(state.id, StateID.LeavePending);
506+
assert.strictEqual(state.id, StateID.LeaveInit);
507507
});
508508
});
509-
it("should transit to appear pending state", () => {
510-
const id = StateID.AppearInit;
509+
it("should transit to appear init state", () => {
510+
const id = StateID.AppearNew;
511511
const {state, pending} = reducer(id, { kind: actionID, props: { appearStyle: {} } });
512512
assert.strictEqual(pending, ActionID.TransitionPrepare);
513-
assert.strictEqual(state.id, StateID.AppearPending);
513+
assert.strictEqual(state.id, StateID.AppearInit);
514514
});
515515
it("should transit to enter triggered state", () => {
516516
const id = StateID.EnterPrepare;
@@ -530,26 +530,26 @@ describe("actions", () => {
530530
assert.isUndefined(pending);
531531
assert.strictEqual(state.id, StateID.AppearTriggered);
532532
});
533-
it("should interrupt enter pending and triggered", () => {
534-
[StateID.EnterPending, StateID.EnterPrepare, StateID.EnterTriggered].forEach((id) => {
533+
it("should interrupt enter init and triggered", () => {
534+
[StateID.EnterInit, StateID.EnterPrepare, StateID.EnterTriggered].forEach((id) => {
535535
const props = { active: false };
536536
const {state, pending, completed} = reducer(id, { kind: actionID, props });
537537
assert.isUndefined(pending);
538538
assert.strictEqual(state.id, StateID.Default);
539539
assert.isTrue(completed);
540540
});
541541
});
542-
it("should interrupt leave pending and triggered", () => {
543-
[StateID.LeavePending, StateID.LeavePrepare, StateID.LeaveTriggered].forEach((id) => {
542+
it("should interrupt leave init and triggered", () => {
543+
[StateID.LeaveInit, StateID.LeavePrepare, StateID.LeaveTriggered].forEach((id) => {
544544
const props = { active: true };
545545
const {state, pending, completed} = reducer(id, { kind: actionID, props });
546546
assert.isUndefined(pending);
547547
assert.strictEqual(state.id, StateID.Active);
548548
assert.isTrue(completed);
549549
});
550550
});
551-
it("should interrupt appear pending and triggered", () => {
552-
[StateID.AppearPending, StateID.AppearPrepare, StateID.AppearTriggered].forEach((id) => {
551+
it("should interrupt appear init and triggered", () => {
552+
[StateID.AppearInit, StateID.AppearPrepare, StateID.AppearTriggered].forEach((id) => {
553553
const props = { active: false };
554554
const {state, pending, completed} = reducer(id, { kind: actionID, props });
555555
assert.isUndefined(pending);

0 commit comments

Comments
 (0)