@@ -2,9 +2,8 @@ import { CSSProperties } from "react";
2
2
import {
3
3
combine , withState , withHandlers , withProps ,
4
4
onDidMount , onWillUnmount , onWillReceiveProps ,
5
- isolate , integrate , StateUpdater ,
5
+ isolate , integrate , StateUpdater , onDidUpdate ,
6
6
} from "reassemble" ;
7
- import * as shallowEqual from "fbjs/lib/shallowEqual" ;
8
7
9
8
import { CSSTransitionProps , CSSTransitionInnerProps } from "../csstransition" ;
10
9
import runInFrame from "../utils/runInFrame" ;
@@ -27,6 +26,7 @@ type PropsOut =
27
26
actionProps ?: { [ P in ActionPropKeys ] ?: CSSTransitionProps [ P ] } ,
28
27
cancelPendingIfExistent ?: ( ) => void ,
29
28
dispatch ?: ( actionID : ActionID ) => void ,
29
+ runPending ?: ( ) => void ,
30
30
setTransitionState ?: StateUpdater < TransitionState > ,
31
31
onTransitionBegin ?: CSSTransitionInnerProps [ "onTransitionBegin" ] ,
32
32
onTransitionComplete ?: CSSTransitionInnerProps [ "onTransitionComplete" ] ,
@@ -51,6 +51,7 @@ export const withTransitionState = (reduce: Reducer) => combine(
51
51
( initialProps ) => {
52
52
let stateID = reduce ( StateID . EntryPoint , { kind : ActionID . New , props : initialProps } ) . state . id ;
53
53
let cancelPending : ( ) => void = null ;
54
+ let pendingCallback : ( ) => void ;
54
55
const cancelPendingIfExistent = ( ) => {
55
56
if ( cancelPending ) {
56
57
cancelPending ( ) ;
@@ -59,7 +60,14 @@ export const withTransitionState = (reduce: Reducer) => combine(
59
60
} ;
60
61
return {
61
62
cancelPendingIfExistent : ( ) => cancelPendingIfExistent ,
62
- dispatch : ( { actionProps, onTransitionComplete, setTransitionState, transitionState} ) => {
63
+ runPending : ( ) => ( ) => {
64
+ const callback = pendingCallback ;
65
+ pendingCallback = null ;
66
+ if ( callback ) {
67
+ callback ( ) ;
68
+ }
69
+ } ,
70
+ dispatch : ( { actionProps, onTransitionComplete, setTransitionState} ) => {
63
71
const run = ( actionID : ActionID ) => {
64
72
const result = reduce ( stateID , { kind : actionID , props : actionProps } ) ;
65
73
if ( ! result ) { return ; }
@@ -69,19 +77,12 @@ export const withTransitionState = (reduce: Reducer) => combine(
69
77
const { state, pending} = result ;
70
78
stateID = state . id ;
71
79
cancelPendingIfExistent ( ) ;
72
- let callback : any ;
73
80
if ( pending ) {
74
- callback = ( ) => {
81
+ pendingCallback = ( ) => {
75
82
cancelPending = runInFrame ( 1 , ( ) => run ( pending ) ) ;
76
83
} ;
77
84
}
78
- if ( ! shallowEqual ( transitionState . style , result . state . style ) ||
79
- transitionState . className !== result . state . className ||
80
- transitionState . inTransition !== result . state . inTransition ) {
81
- setTransitionState ( pick ( state , "style" , "className" , "inTransition" ) , callback ) ;
82
- } else if ( callback ) {
83
- callback ( ) ;
84
- }
85
+ setTransitionState ( pick ( state , "style" , "className" , "inTransition" ) , null ) ;
85
86
} ;
86
87
return run ;
87
88
} ,
@@ -96,15 +97,19 @@ export const withTransitionState = (reduce: Reducer) => combine(
96
97
( { dispatch} ) => {
97
98
dispatch ( ActionID . Mount ) ;
98
99
} ) ,
99
- onWillUnmount < PropsUnion > (
100
- ( { cancelPendingIfExistent} ) => {
101
- cancelPendingIfExistent ( ) ;
102
- } ) ,
103
100
onWillReceiveProps < PropsUnion > (
104
101
( { active : prevActive } , { active : nextActive , dispatch} ) => {
105
102
if ( prevActive === nextActive ) { return ; }
106
103
dispatch ( ActionID . TransitionTrigger ) ;
107
104
} ) ,
105
+ onDidUpdate < PropsUnion > (
106
+ ( { runPending} ) => {
107
+ runPending ( ) ;
108
+ } ) ,
109
+ onWillUnmount < PropsUnion > (
110
+ ( { cancelPendingIfExistent} ) => {
111
+ cancelPendingIfExistent ( ) ;
112
+ } ) ,
108
113
integrate < keyof PropsUnion > (
109
114
"timeout" , "transitionState" , "onTransitionBegin" , "onTransitionComplete" ,
110
115
) ,
0 commit comments