Created
January 8, 2019 11:04
-
-
Save thomasJang/03b3292cef28c2522a1ce5e66f3f6420 to your computer and use it in GitHub Desktop.
mouseEventSubscribe
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| handleRowResizerMove = (e: React.MouseEvent<HTMLDivElement>) => { | |
| const { activePanel } = this.props.appStore.uiStore.queryPanelStore; | |
| const containerTop = this.containerRef.current.getBoundingClientRect().top; | |
| mouseEventSubscribe( | |
| (mpos: IMousePosition) => { | |
| const resizerTop = mpos.clientY - containerTop; | |
| activePanel.setFlexGlow((resizerTop * 2) / this.containerHeight); | |
| }, | |
| () => { | |
| // onSubscribeEnd | |
| }, | |
| ); | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const mouseEventSubscribe = ( | |
| callBack: MouseEventSubscribeCallbackFn, | |
| onEnd: () => void, | |
| ) => { | |
| const onMousemoveWindow = (e: MouseEvent) => { | |
| callBack( | |
| { | |
| pageX: e.pageX, | |
| pageY: e.pageY, | |
| clientX: e.clientX, | |
| clientY: e.clientY, | |
| }, | |
| () => { | |
| onMouseupWindow(); | |
| }, | |
| ); | |
| }; | |
| const onMouseupWindow = (e?: MouseEvent) => { | |
| window.removeEventListener('mousemove', onMousemoveWindow); | |
| window.removeEventListener('mouseup', onMouseupWindow); | |
| window.removeEventListener('mouseleave', onMouseupWindow); | |
| if (onEnd) { | |
| onEnd(); | |
| } | |
| }; | |
| window.addEventListener('mousemove', onMousemoveWindow, false); | |
| window.addEventListener('mouseup', onMouseupWindow); | |
| window.addEventListener('mouseleave', onMouseupWindow); | |
| }; | |
| export default mouseEventSubscribe; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment