11import { Vector } from '../core/vector' ;
2- import { Behavior } from './behavior' ;
2+ import { Behavior , BehaviorEndToken } from './behavior' ;
33import { readMousePosition , readTouchPosition } from '../core/event-readers' ;
44
55const notInitializedError = 'State is not initialized' ;
@@ -13,11 +13,12 @@ export class BehaviorController {
1313 return new BehaviorController ( shadowRoot ?? document , shadowRoot ) ;
1414 }
1515
16- private state ?: {
16+ private previousEndToken : BehaviorEndToken | null = null ;
17+ private state : {
1718 startPosition : Vector ;
1819 behavior : Behavior ;
1920 lastPosition ?: Vector ;
20- } ;
21+ } | null = null ;
2122
2223 private constructor (
2324 private readonly dom : Document | ShadowRoot ,
@@ -106,7 +107,7 @@ export class BehaviorController {
106107 const delta = this . state . startPosition . subtract ( position ) ;
107108 const newBehavior = this . state . behavior . onMove ( delta ) ;
108109 if ( newBehavior ) {
109- this . state . behavior . onEnd ( true , null ) ;
110+ this . state . behavior . onEnd ( true , null , null ) ;
110111
111112 this . state . behavior = newBehavior ;
112113 this . state . startPosition = position ;
@@ -124,7 +125,8 @@ export class BehaviorController {
124125 }
125126 this . unbind ( window ) ;
126127
127- this . state . behavior . onEnd ( interrupt , element ) ;
128- this . state = undefined ;
128+ const endToken = this . state . behavior . onEnd ( interrupt , element , this . previousEndToken ) ;
129+ this . state = null ;
130+ this . previousEndToken = endToken || null ;
129131 }
130132}
0 commit comments