Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Apr 8, 2020. It is now read-only.

Commit 5c0bbc8

Browse files
committed
Add StateID to state to improve debugging
1 parent 621c01d commit 5c0bbc8

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

‎src/composables/withTransitionState.spec.tsx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import runInFrame from "../utils/runInFrame";
1313
const createReducer = (map: { [no: number]: { state: TransitionState, pending?: ActionID, completed?: boolean } }) =>
1414
(id: StateID) => map[id];
1515

16+
const pickTransitionState = (state: any) => pick(state, "style", "className", "inTransition", "id");
17+
1618
describe("withTransitionState.tsx", () => {
1719
let getWrapper: (props?: any, reducer?: Reducer) =>
1820
ShallowWrapper<any, any>;
@@ -38,7 +40,7 @@ describe("withTransitionState.tsx", () => {
3840
assert.isTrue(reducer.calledWith(StateID.EntryPoint, { kind: ActionID.New, props: {} }));
3941
});
4042
it("should return transitionState", () => {
41-
assert.deepEqual(wrapper.props().transitionState, pick(state,"style","className"));
43+
assert.deepEqual(wrapper.props().transitionState, pickTransitionState(state));
4244
});
4345
});
4446

@@ -61,7 +63,7 @@ describe("withTransitionState.tsx", () => {
6163
});
6264

6365
it("should return transitionState", () => {
64-
assert.deepEqual(wrapper.props().transitionState, pick(state,"style","className"));
66+
assert.deepEqual(wrapper.props().transitionState, pickTransitionState(state));
6567
});
6668
});
6769

@@ -84,7 +86,7 @@ describe("withTransitionState.tsx", () => {
8486
});
8587

8688
it("should return transitionState", () => {
87-
assert.deepEqual(wrapper.props().transitionState, pick(state,"style","className"));
89+
assert.deepEqual(wrapper.props().transitionState, pickTransitionState(state));
8890
});
8991
});
9092

@@ -104,7 +106,7 @@ describe("withTransitionState.tsx", () => {
104106
});
105107

106108
it("should return transitionState", () => {
107-
assert.deepEqual(wrapper.props().transitionState, pick(state,"style","className"));
109+
assert.deepEqual(wrapper.props().transitionState, pickTransitionState(state));
108110
});
109111
});
110112

@@ -124,7 +126,7 @@ describe("withTransitionState.tsx", () => {
124126
});
125127

126128
it("should return transitionState", () => {
127-
assert.deepEqual(wrapper.props().transitionState, pick(state,"style","className"));
129+
assert.deepEqual(wrapper.props().transitionState, pickTransitionState(state));
128130
});
129131
});
130132

@@ -144,7 +146,7 @@ describe("withTransitionState.tsx", () => {
144146
});
145147

146148
it("should return transitionState", () => {
147-
assert.deepEqual(wrapper.props().transitionState, pick(state,"style","className"));
149+
assert.deepEqual(wrapper.props().transitionState, pickTransitionState(state));
148150
});
149151
});
150152

@@ -170,7 +172,7 @@ describe("withTransitionState.tsx", () => {
170172
});
171173

172174
it("should return intermediate transitionState", () => {
173-
assert.deepEqual(wrapper.props().transitionState, pick(pendingState,"style","className"));
175+
assert.deepEqual(wrapper.props().transitionState, pickTransitionState(pendingState));
174176
});
175177

176178
it("should dispatch ActionID.TransitionStart after update in 2nd frame", (done) => {
@@ -185,7 +187,7 @@ describe("withTransitionState.tsx", () => {
185187
});
186188

187189
it("should return transitionState", () => {
188-
assert.deepEqual(wrapper.props().transitionState, pick(state,"style","className"));
190+
assert.deepEqual(wrapper.props().transitionState, pickTransitionState(state));
189191
});
190192
});
191193

@@ -205,7 +207,7 @@ describe("withTransitionState.tsx", () => {
205207
});
206208

207209
it("should return final transitionState", () => {
208-
assert.deepEqual(wrapper.props().transitionState, pick(state,"style","className"));
210+
assert.deepEqual(wrapper.props().transitionState, pickTransitionState(state));
209211
});
210212

211213
it("should not dispatch any further actions", (done) => {

‎src/composables/withTransitionState.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import pick from "../utils/pick";
1111
import { ActionID, StateID, Reducer, actionPropKeys, ActionPropKeys } from "../reducer";
1212

1313
export type TransitionState = {
14+
id?: StateID,
1415
style?: CSSProperties,
1516
className?: string,
1617
inTransition?: boolean,
@@ -34,6 +35,8 @@ type PropsOut =
3435

3536
type PropsUnion = CSSTransitionProps & PropsOut;
3637

38+
const pickTransitionState = (state: any) => pick(state, "style", "className", "inTransition", "id");
39+
3740
export const withTransitionState = (reduce: Reducer) => combine(
3841
isolate(
3942
withProps<PropsUnion, PropsOut>(
@@ -42,9 +45,8 @@ export const withTransitionState = (reduce: Reducer) => combine(
4245
withState<PropsUnion, keyof PropsOut, TransitionState>(
4346
"transitionState", "setTransitionState",
4447
({actionProps}) =>
45-
pick(
48+
pickTransitionState(
4649
reduce(StateID.EntryPoint, { kind: ActionID.New, props: actionProps }).state,
47-
"style", "className", "inTransition",
4850
),
4951
),
5052
withHandlers<PropsUnion, PropsOut>(
@@ -82,7 +84,7 @@ export const withTransitionState = (reduce: Reducer) => combine(
8284
cancelPending = runInFrame(1, () => run(pending));
8385
};
8486
}
85-
setTransitionState(pick(state,"style","className","inTransition"),null);
87+
setTransitionState(pickTransitionState(state));
8688
};
8789
return run;
8890
},

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /