@@ -39,7 +39,11 @@ window.addEventListener('touchmove', function() {}, passiveSupported ? { passive
3939export default class Implosion {
4040 constructor ( {
4141 source : sourceEl = document ,
42- update : updateCallback ,
42+ update : updateCallbackDeprecated ,
43+ onUpdate : updateCallback ,
44+ onStart : startCallback ,
45+ onStartDecelerating : startDeceleratingCallback ,
46+ onEndDecelerating : endDeceleratingCallback ,
4347 multiplier = 1 ,
4448 friction = 0.92 ,
4549 initialValues,
@@ -78,6 +82,14 @@ export default class Implosion {
7882 throw new Error ( 'IMPETUS: source not found.' ) ;
7983 }
8084
85+ /**
86+ * Using the `update` configuration is deprecated, us the `onUpdate` key instead
87+ * @deprecated
88+ */
89+ if ( ! updateCallback && updateCallbackDeprecated ) {
90+ updateCallback = updateCallbackDeprecated ;
91+ }
92+
8193 if ( ! updateCallback ) {
8294 throw new Error ( 'IMPETUS: update function not defined.' ) ;
8395 }
@@ -219,6 +231,36 @@ export default class Implosion {
219231 prevTargetY = targetY ;
220232 }
221233
234+ /**
235+ * Executes the start function
236+ */
237+ function callStartCallback ( ) {
238+ if ( ! startCallback ) {
239+ return ;
240+ }
241+ startCallback . call ( sourceEl , targetX , targetY , prevTargetX , prevTargetY ) ;
242+ }
243+
244+ /**
245+ * Executes the start decelerating function
246+ */
247+ function callStartDeceleratingCallback ( ) {
248+ if ( ! startDeceleratingCallback ) {
249+ return ;
250+ }
251+ startDeceleratingCallback . call ( sourceEl , targetX , targetY , prevTargetX , prevTargetY ) ;
252+ }
253+
254+ /**
255+ * Executes the end decelerating function
256+ */
257+ function callEndDeceleratingCallback ( ) {
258+ if ( ! endDeceleratingCallback ) {
259+ return ;
260+ }
261+ endDeceleratingCallback . call ( sourceEl , targetX , targetY , prevTargetX , prevTargetY ) ;
262+ }
263+
222264 /**
223265 * Creates a custom normalized event object from touch and mouse events
224266 * @param {Event } ev
@@ -249,6 +291,7 @@ export default class Implosion {
249291 function onDown ( ev ) {
250292 let event = normalizeEvent ( ev ) ;
251293 if ( ! pointerActive && ! paused ) {
294+ callStartCallback ( ) ;
252295 pointerActive = true ;
253296 decelerating = false ;
254297 pointerId = event . id ;
@@ -419,9 +462,12 @@ export default class Implosion {
419462
420463 let diff = checkBounds ( ) ;
421464
465+ callStartDeceleratingCallback ( ) ;
422466 if ( Math . abs ( decVelX ) > 1 || Math . abs ( decVelY ) > 1 || ! diff . inBounds ) {
423467 decelerating = true ;
424468 requestAnimFrame ( stepDecelAnim ) ;
469+ } else {
470+ callEndDeceleratingCallback ( ) ;
425471 }
426472 }
427473
@@ -485,6 +531,7 @@ export default class Implosion {
485531 requestAnimFrame ( stepDecelAnim ) ;
486532 } else {
487533 decelerating = false ;
534+ callEndDeceleratingCallback ( ) ;
488535 }
489536 }
490537 }
0 commit comments