1- var GetValueOp = function ( key , value )
1+ function hasGetStart ( def )
22{
3- var valueCallback ;
4- var t = typeof ( value ) ;
3+ return ( ! ! def . getStart && typeof def . getStart === 'function' ) ;
4+ }
5+
6+ function hasGetEnd ( def )
7+ {
8+ return ( ! ! def . getEnd && typeof def . getEnd === 'function' ) ;
9+ }
10+
11+ function hasGetters ( def )
12+ {
13+ return hasGetStart ( def ) || hasGetEnd ( def ) ;
14+ }
15+
16+ var GetValueOp = function ( key , propertyValue )
17+ {
18+ var callbacks ;
19+
20+ // The returned value sets what the property will be at the END of the Tween (usually called at the start of the Tween)
21+ var getEnd = function ( target , key , value ) { return value ; } ;
22+
23+ // The returned value sets what the property will be at the START of the Tween (usually called at the end of the Tween)
24+ var getStart = function ( target , key , value ) { return value ; } ;
25+
26+ var t = typeof ( propertyValue ) ;
527
628 if ( t === 'number' )
729 {
@@ -10,9 +32,9 @@ var GetValueOp = function (key, value)
1032 // y: 300
1133 // }
1234
13- valueCallback = function ( )
35+ getEnd = function ( )
1436 {
15- return value ;
37+ return propertyValue ;
1638 } ;
1739 }
1840 else if ( t === 'string' )
@@ -24,69 +46,105 @@ var GetValueOp = function (key, value)
2446 // w: '/=2'
2547 // }
2648
27- var op = value [ 0 ] ;
28- var num = parseFloat ( value . substr ( 2 ) ) ;
49+ var op = propertyValue [ 0 ] ;
50+ var num = parseFloat ( propertyValue . substr ( 2 ) ) ;
2951
3052 switch ( op )
3153 {
3254 case '+' :
33- valueCallback = function ( i )
55+ getEnd = function ( target , key , value )
3456 {
35- return i + num ;
57+ return value + num ;
3658 } ;
3759 break ;
3860
3961 case '-' :
40- valueCallback = function ( i )
62+ getEnd = function ( target , key , value )
4163 {
42- return i - num ;
64+ return value - num ;
4365 } ;
4466 break ;
4567
4668 case '*' :
47- valueCallback = function ( i )
69+ getEnd = function ( target , key , value )
4870 {
49- return i * num ;
71+ return value * num ;
5072 } ;
5173 break ;
5274
5375 case '/' :
54- valueCallback = function ( i )
76+ getEnd = function ( target , key , value )
5577 {
56- return i / num ;
78+ return value / num ;
5779 } ;
5880 break ;
5981
6082 default :
61- valueCallback = function ( )
83+ getEnd = function ( )
6284 {
63- return parseFloat ( value ) ;
85+ return parseFloat ( propertyValue ) ;
6486 } ;
6587 }
6688 }
6789 else if ( t === 'function' )
6890 {
91+ // The same as setting just the getEnd function and no getStart
92+
6993 // props: {
70- // x: function (i, target, key) { return i + 50); },
94+ // x: function (target, key, value ) { return value + 50); },
7195 // }
7296
73- valueCallback = function ( i , target , key )
97+ getEnd = propertyValue ;
98+ }
99+ else if ( t === 'object' && hasGetters ( propertyValue ) )
100+ {
101+ /*
102+ x: {
103+ // Called at the start of the Tween. The returned value sets what the property will be at the END of the Tween.
104+ getEnd: function (target, key, value)
105+ {
106+ return value;
107+ },
108+
109+ // Called at the end of the Tween. The returned value sets what the property will be at the START of the Tween.
110+ getStart: function (target, key, value)
111+ {
112+ return value;
113+ }
114+ }
115+ */
116+
117+ if ( hasGetEnd ( propertyValue ) )
74118 {
75- return value ( i , target , key ) ;
76- } ;
119+ getEnd = propertyValue . getEnd ;
120+ }
121+
122+ if ( hasGetStart ( propertyValue ) )
123+ {
124+ getStart = propertyValue . getStart ;
125+ }
77126 }
78- else if ( value . hasOwnProperty ( 'value' ) )
127+ else if ( propertyValue . hasOwnProperty ( 'value' ) )
79128 {
80129 // Value may still be a string, function or a number
81130 // props: {
82131 // x: { value: 400, ... },
83132 // y: { value: 300, ... }
84133 // }
85134
86- valueCallback = GetValueOp ( key , value . value ) ;
135+ callbacks = GetValueOp ( key , propertyValue . value ) ;
136+ }
137+
138+ // If callback not set by the else if block above then set it here and return it
139+ if ( ! callbacks )
140+ {
141+ callbacks = {
142+ getEnd : getEnd ,
143+ getStart : getStart
144+ } ;
87145 }
88146
89- return valueCallback ;
147+ return callbacks ;
90148} ;
91149
92150module . exports = GetValueOp ;
0 commit comments