index.tsx 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  1. /* eslint-disable max-lines-per-function */
  2. /* eslint-disable react/no-find-dom-node */
  3. import React, { CSSProperties } from 'react';
  4. import ReactDOM from 'react-dom';
  5. import PropTypes from 'prop-types';
  6. import cls from 'classnames';
  7. import { cssClasses } from '@douyinfe/semi-foundation/slider/constants';
  8. import BaseComponent from '../_base/baseComponent';
  9. import SliderFoundation, { SliderAdapter, SliderProps as BasicSliceProps, SliderState, tipFormatterBasicType } from '@douyinfe/semi-foundation/slider/foundation';
  10. import Tooltip from '../tooltip/index';
  11. import '@douyinfe/semi-foundation/slider/slider.scss';
  12. import { isEqual, noop } from 'lodash';
  13. const prefixCls = cssClasses.PREFIX;
  14. export interface SliderProps extends BasicSliceProps {
  15. style?: CSSProperties;
  16. railStyle?: CSSProperties;
  17. }
  18. export {
  19. SliderState
  20. };
  21. function domIsInRenderTree(e: HTMLElement) {
  22. if (!e) {
  23. return false;
  24. }
  25. return Boolean(e.offsetWidth || e.offsetHeight || e.getClientRects().length);
  26. }
  27. export default class Slider extends BaseComponent<SliderProps, SliderState> {
  28. static propTypes = {
  29. // allowClear: PropTypes.bool,
  30. defaultValue: PropTypes.oneOfType([PropTypes.number, PropTypes.array]),
  31. disabled: PropTypes.bool,
  32. included: PropTypes.bool, // Whether to juxtapose. Allow dragging
  33. marks: PropTypes.object, // Scale
  34. max: PropTypes.number,
  35. min: PropTypes.number,
  36. range: PropTypes.bool, // Whether both sides
  37. step: PropTypes.number,
  38. tipFormatter: PropTypes.func,
  39. value: PropTypes.oneOfType([PropTypes.number, PropTypes.array]),
  40. vertical: PropTypes.bool,
  41. onAfterChange: PropTypes.func, // OnmouseUp and triggered when clicked
  42. onChange: PropTypes.func,
  43. tooltipVisible: PropTypes.bool,
  44. style: PropTypes.object,
  45. className: PropTypes.string,
  46. showBoundary: PropTypes.bool,
  47. railStyle: PropTypes.object,
  48. verticalReverse: PropTypes.bool,
  49. } as any;
  50. static defaultProps: Partial<SliderProps> = {
  51. // allowClear: false,
  52. disabled: false,
  53. included: true, // No is juxtaposition. Allow dragging
  54. max: 100,
  55. min: 0,
  56. range: false, // Whether both sides
  57. step: 1,
  58. tipFormatter: (value: tipFormatterBasicType | tipFormatterBasicType[]) => value,
  59. vertical: false,
  60. showBoundary: false,
  61. onAfterChange: (value: number | number[]) => {
  62. // console.log(value);
  63. },
  64. onChange: (value: number | number[]) => {
  65. // console.log(value);
  66. },
  67. verticalReverse: false
  68. };
  69. private sliderEl: React.RefObject<HTMLDivElement>;
  70. private minHanleEl: React.RefObject<HTMLDivElement>;
  71. private maxHanleEl: React.RefObject<HTMLDivElement>;
  72. private dragging: boolean[];
  73. private eventListenerSet: Set<() => void>;
  74. private chooseMovePos: 'min' | 'max';
  75. foundation: SliderFoundation;
  76. constructor(props: SliderProps) {
  77. super(props);
  78. let { value } = this.props;
  79. if (!value) {
  80. value = this.props.defaultValue;
  81. }
  82. this.state = {
  83. // eslint-disable-next-line no-nested-ternary
  84. currentValue: value ? value : this.props.range ? [0, 0] : 0,
  85. min: this.props.min || 0,
  86. max: this.props.max || 0,
  87. focusPos: '',
  88. onChange: this.props.onChange,
  89. disabled: this.props.disabled || false,
  90. chooseMovePos: '',
  91. isDrag: false,
  92. clickValue: 0,
  93. showBoundary: false,
  94. isInRenderTree: true
  95. };
  96. this.sliderEl = React.createRef();
  97. this.minHanleEl = React.createRef();
  98. this.maxHanleEl = React.createRef();
  99. this.dragging = [false, false];
  100. // this.chooseMovePos = 'min';
  101. // this.isDrag = false;
  102. this.foundation = new SliderFoundation(this.adapter);
  103. this.eventListenerSet = new Set();
  104. }
  105. get adapter(): SliderAdapter {
  106. return {
  107. ...super.adapter,
  108. getSliderLengths: () => {
  109. if (this.sliderEl && this.sliderEl.current) {
  110. const rect = this.sliderEl.current.getBoundingClientRect();
  111. const offset = {
  112. x: this.sliderEl.current.offsetLeft,
  113. y: this.sliderEl.current.offsetTop,
  114. };
  115. return {
  116. sliderX: offset.x,
  117. sliderY: offset.y,
  118. sliderWidth: rect.width,
  119. sliderHeight: rect.height,
  120. };
  121. }
  122. return {
  123. sliderX: 0,
  124. sliderY: 0,
  125. sliderWidth: 0,
  126. sliderHeight: 0,
  127. };
  128. },
  129. getParentRect: (): DOMRect | undefined => {
  130. const parentObj = this.sliderEl && this.sliderEl.current && this.sliderEl.current.offsetParent;
  131. if (!parentObj) {
  132. return undefined;
  133. }
  134. return parentObj.getBoundingClientRect();
  135. },
  136. getScrollParentVal: () => {
  137. const scrollParent = this.foundation.getScrollParent(this.sliderEl.current);
  138. return {
  139. scrollTop: scrollParent.scrollTop,
  140. scrollLeft: scrollParent.scrollLeft,
  141. };
  142. },
  143. isEventFromHandle: (e: React.MouseEvent) => {
  144. const handles = [this.minHanleEl, this.maxHanleEl];
  145. let flag = false;
  146. handles.forEach(handle => {
  147. if (!handle) {
  148. return;
  149. }
  150. const handleInstance = handle && handle.current;
  151. const handleDom = ReactDOM.findDOMNode(handleInstance);
  152. if (handleDom && handleDom.contains(e.target as Node)) {
  153. flag = true;
  154. }
  155. });
  156. return flag;
  157. },
  158. getOverallVars: () => ({
  159. dragging: this.dragging,
  160. chooseMovePos: this.chooseMovePos,
  161. }),
  162. updateDisabled: (disabled: boolean) => {
  163. this.setState({ disabled });
  164. },
  165. transNewPropsToState<K extends keyof SliderState>(stateObj: Pick<SliderState, K>, callback = noop) {
  166. this.setState(stateObj, callback);
  167. },
  168. notifyChange: (cbValue: number | number[]) => this.props.onChange(cbValue),
  169. setDragging: (value: boolean[]) => {
  170. this.dragging = value;
  171. },
  172. updateCurrentValue: (value: number | number[]) => {
  173. const { currentValue } = this.state;
  174. if (value !== currentValue) {
  175. this.setState({ currentValue: value });
  176. }
  177. },
  178. setOverallVars: (key: string, value: any) => {
  179. this[key] = value;
  180. },
  181. getMinHandleEl: () => this.minHanleEl,
  182. getMaxHandleEl: () => this.maxHanleEl,
  183. onHandleDown: (e: React.MouseEvent) => {
  184. e.stopPropagation();
  185. e.preventDefault();
  186. this._addEventListener(document.body, 'mousemove', this.foundation.onHandleMove, false);
  187. this._addEventListener(document.body, 'mouseup', this.foundation.onHandleUp, false);
  188. this._addEventListener(document.body, 'touchmove', this.foundation.onHandleTouchMove, false);
  189. },
  190. onHandleMove: (mousePos: number, isMin: boolean, stateChangeCallback = noop, clickTrack = false, outPutValue): boolean | void => {
  191. const sliderDOMIsInRenderTree = this.foundation.checkAndUpdateIsInRenderTreeState();
  192. if (!sliderDOMIsInRenderTree) {
  193. return;
  194. }
  195. const { value } = this.props;
  196. let finalOutPutValue = outPutValue;
  197. if (finalOutPutValue === undefined) {
  198. const moveValue = this.foundation.transPosToValue(mousePos, isMin);
  199. if (moveValue === false) {
  200. return;
  201. }
  202. finalOutPutValue = this.foundation.outPutValue(moveValue);
  203. }
  204. const { currentValue } = this.state;
  205. if (!isEqual(this.foundation.outPutValue(currentValue), finalOutPutValue)) {
  206. if (!clickTrack && this.foundation.valueFormatIsCorrect(value)) {
  207. // still require afterChangeCallback when click on the track directly, need skip here
  208. return false;
  209. }
  210. this.setState({
  211. currentValue: finalOutPutValue,
  212. }, stateChangeCallback);
  213. }
  214. },
  215. setEventDefault: (e: React.MouseEvent) => {
  216. e.stopPropagation();
  217. e.preventDefault();
  218. },
  219. setStateVal: <K extends keyof SliderState>(name: K, val: SliderState[K]) => {
  220. this.setState({ [name]: val } as Pick<SliderState, K>);
  221. },
  222. checkAndUpdateIsInRenderTreeState: () => {
  223. const sliderDOMIsInRenderTree = domIsInRenderTree(this.sliderEl.current);
  224. if (sliderDOMIsInRenderTree !== this.state.isInRenderTree) {
  225. this.setState({ isInRenderTree: sliderDOMIsInRenderTree });
  226. }
  227. return sliderDOMIsInRenderTree;
  228. },
  229. onHandleEnter: (pos: SliderState['focusPos']) => {
  230. this.setState({ focusPos: pos });
  231. },
  232. onHandleLeave: () => {
  233. this.setState({ focusPos: '' });
  234. },
  235. onHandleUpBefore: (e: React.MouseEvent) => {
  236. e.stopPropagation();
  237. e.preventDefault();
  238. document.body.removeEventListener('mousemove', this.foundation.onHandleMove, false);
  239. document.body.removeEventListener('mouseup', this.foundation.onHandleUp, false);
  240. },
  241. onHandleUpAfter: () => {
  242. const { currentValue } = this.state;
  243. const value = this.foundation.outPutValue(currentValue);
  244. this.props.onAfterChange(value);
  245. },
  246. unSubscribeEventListener: () => {
  247. Array.from(this.eventListenerSet).forEach(clear => clear());
  248. },
  249. };
  250. }
  251. componentDidMount() {
  252. this.foundation.init();
  253. }
  254. componentDidUpdate(prevProps: SliderProps, prevState: SliderState) {
  255. const hasPropValueChange = !isEqual(this.props.value, prevProps.value);
  256. const hasPropDisabledChange = this.props.disabled !== prevProps.disabled;
  257. if (hasPropDisabledChange) {
  258. this.foundation.handleDisabledChange(this.props.disabled);
  259. }
  260. if (hasPropValueChange) {
  261. const nextValue = this.props.value;
  262. const prevValue = this.state.currentValue;
  263. this.foundation.handleValueChange(prevValue, nextValue);
  264. }
  265. }
  266. componentWillUnmount() {
  267. this.foundation.destroy();
  268. }
  269. renderHandle = () => {
  270. const { vertical, range, tooltipVisible, tipFormatter, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledby, 'aria-valuetext': ariaValueText, getAriaValueText, disabled } = this.props;
  271. const { chooseMovePos, isDrag, isInRenderTree } = this.state;
  272. const stylePos = vertical ? 'top' : 'left';
  273. const percentInfo = this.foundation.getMinAndMaxPercent(this.state.currentValue);
  274. const minPercent = percentInfo.min;
  275. const maxPercent = percentInfo.max;
  276. const { tipVisible, tipChildren } = this.foundation.computeHandleVisibleVal(
  277. tooltipVisible && isInRenderTree,
  278. tipFormatter,
  279. range
  280. );
  281. const transform = { top: 'translateY(-50%)', left: 'translateX(-50%)' };
  282. const minClass = cls(cssClasses.HANDLE, {
  283. [`${cssClasses.HANDLE}-clicked`]: chooseMovePos === 'min' && isDrag,
  284. });
  285. const maxClass = cls(cssClasses.HANDLE, {
  286. [`${cssClasses.HANDLE}-clicked`]: chooseMovePos === 'max' && isDrag,
  287. });
  288. const { min, max, currentValue } = this.state;
  289. const commonAria = {
  290. 'aria-label': ariaLabel,
  291. 'aria-labelledby': ariaLabelledby,
  292. 'aria-disabled': disabled
  293. };
  294. vertical && Object.assign(commonAria, { 'aria-orientation': 'vertical' });
  295. const handleContents = !range ? (
  296. <Tooltip
  297. content={tipChildren.min}
  298. position="top"
  299. trigger="custom"
  300. rePosKey={minPercent}
  301. visible={isInRenderTree && tipVisible.min}
  302. className={`${cssClasses.HANDLE}-tooltip`}
  303. >
  304. <span
  305. onMouseOver={this.foundation.checkAndUpdateIsInRenderTreeState}
  306. ref={this.minHanleEl}
  307. className={minClass}
  308. style={{
  309. [stylePos]: `${minPercent * 100}%`,
  310. zIndex: chooseMovePos === 'min' && isDrag ? 2 : 1,
  311. transform: transform[stylePos],
  312. }}
  313. onMouseDown={e => {
  314. this.foundation.onHandleDown(e, 'min');
  315. }}
  316. onMouseEnter={() => {
  317. this.foundation.onHandleEnter('min');
  318. }}
  319. onTouchStart={e => {
  320. this.foundation.onHandleTouchStart(e, 'min');
  321. }}
  322. onMouseLeave={() => {
  323. this.foundation.onHandleLeave();
  324. }}
  325. onMouseUp={e => {
  326. this.foundation.onHandleUp(e);
  327. }}
  328. onKeyUp={e => {
  329. this.foundation.onHandleUp(e);
  330. }}
  331. onTouchEnd={e => {
  332. this.foundation.onHandleUp(e);
  333. }}
  334. onFocus={e => this.foundation.onFocus(e, 'min')}
  335. role="slider"
  336. tabIndex={0}
  337. {...commonAria}
  338. aria-valuenow={currentValue as number}
  339. aria-valuemax={max}
  340. aria-valuemin={min}
  341. aria-valuetext={getAriaValueText ? getAriaValueText(currentValue as number) : ariaValueText}
  342. />
  343. </Tooltip>
  344. ) : (
  345. <React.Fragment>
  346. <Tooltip
  347. content={tipChildren.min}
  348. position="top"
  349. trigger="custom"
  350. rePosKey={minPercent}
  351. visible={isInRenderTree && tipVisible.min}
  352. className={`${cssClasses.HANDLE}-tooltip`}
  353. >
  354. <span
  355. ref={this.minHanleEl}
  356. className={minClass}
  357. style={{
  358. [stylePos]: `${minPercent * 100}%`,
  359. zIndex: chooseMovePos === 'min' ? 2 : 1,
  360. transform: transform[stylePos],
  361. }}
  362. onMouseDown={e => {
  363. this.foundation.onHandleDown(e, 'min');
  364. }}
  365. onMouseEnter={() => {
  366. this.foundation.onHandleEnter('min');
  367. }}
  368. onTouchStart={e => {
  369. this.foundation.onHandleTouchStart(e, 'min');
  370. }}
  371. onMouseLeave={() => {
  372. this.foundation.onHandleLeave();
  373. }}
  374. onMouseUp={e => {
  375. this.foundation.onHandleUp(e);
  376. }}
  377. onKeyUp={e => {
  378. this.foundation.onHandleUp(e);
  379. }}
  380. onTouchEnd={e => {
  381. this.foundation.onHandleUp(e);
  382. }}
  383. onFocus={e => this.foundation.onFocus(e, 'min')}
  384. role="slider"
  385. tabIndex={0}
  386. {...commonAria}
  387. aria-valuenow={currentValue[0]}
  388. aria-valuetext={getAriaValueText ? getAriaValueText(currentValue[0]) : ariaValueText}
  389. aria-valuemax={currentValue[1]}
  390. aria-valuemin={min}
  391. />
  392. </Tooltip>
  393. <Tooltip
  394. content={tipChildren.max}
  395. position="top"
  396. trigger="custom"
  397. rePosKey={maxPercent}
  398. visible={isInRenderTree && tipVisible.max}
  399. className={`${cssClasses.HANDLE}-tooltip`}
  400. >
  401. <span
  402. ref={this.maxHanleEl}
  403. className={maxClass}
  404. style={{
  405. [stylePos]: `${maxPercent * 100}%`,
  406. zIndex: chooseMovePos === 'max' ? 2 : 1,
  407. transform: transform[stylePos],
  408. }}
  409. onMouseDown={e => {
  410. this.foundation.onHandleDown(e, 'max');
  411. }}
  412. onMouseEnter={() => {
  413. this.foundation.onHandleEnter('max');
  414. }}
  415. onMouseLeave={() => {
  416. this.foundation.onHandleLeave();
  417. }}
  418. onMouseUp={e => {
  419. this.foundation.onHandleUp(e);
  420. }}
  421. onKeyUp={e => {
  422. this.foundation.onHandleUp(e);
  423. }}
  424. onTouchStart={e => {
  425. this.foundation.onHandleTouchStart(e, 'max');
  426. }}
  427. onTouchEnd={e => {
  428. this.foundation.onHandleUp(e);
  429. }}
  430. onFocus={e => this.foundation.onFocus(e, 'min')}
  431. role="slider"
  432. tabIndex={0}
  433. {...commonAria}
  434. aria-valuenow={currentValue[1]}
  435. aria-valuetext={getAriaValueText ? getAriaValueText(currentValue[1]) : ariaValueText}
  436. aria-valuemax={max}
  437. aria-valuemin={currentValue[0]}
  438. />
  439. </Tooltip>
  440. </React.Fragment>
  441. );
  442. return handleContents;
  443. };
  444. renderTrack = () => {
  445. const { range, included, vertical } = this.props;
  446. const percentInfo = this.foundation.getMinAndMaxPercent(this.state.currentValue);
  447. const minPercent = percentInfo.min;
  448. const maxPercent = percentInfo.max;
  449. let trackStyle: CSSProperties = !vertical ?
  450. {
  451. width: range ? `${(maxPercent - minPercent) * 100}%` : `${minPercent * 100}%`,
  452. left: range ? `${minPercent * 100}%` : 0,
  453. } :
  454. {
  455. height: range ? `${(maxPercent - minPercent) * 100}%` : `${minPercent * 100}%`,
  456. top: range ? `${minPercent * 100}%` : 0,
  457. };
  458. trackStyle = included ? trackStyle : {};
  459. return (// eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions
  460. <div className={cssClasses.TRACK} style={trackStyle} onClick={this.foundation.handleWrapClick}>
  461. {/* {this.renderTrack} */}
  462. </div>
  463. );
  464. };
  465. renderStepDot = () => {
  466. const { min, max, vertical, marks } = this.props;
  467. const stylePos = vertical ? 'top' : 'left';
  468. const labelContent =
  469. marks && Object.keys(marks).length > 0 ? (
  470. <div className={cssClasses.DOTS}>
  471. {Object.keys(marks).map(mark => {
  472. const activeResult = this.foundation.isMarkActive(Number(mark));
  473. const markClass = cls(`${prefixCls}-dot`, {
  474. [`${prefixCls}-dot-active`]: this.foundation.isMarkActive(Number(mark)) === 'active',
  475. });
  476. const markPercent = (Number(mark) - min) / (max - min);
  477. return activeResult ? (
  478. // eslint-disable-next-line jsx-a11y/no-static-element-interactions
  479. <span
  480. key={mark}
  481. onClick={this.foundation.handleWrapClick}
  482. className={markClass}
  483. style={{ [stylePos]: `calc(${markPercent * 100}% - 2px)` }}
  484. />
  485. ) : null;
  486. })}
  487. </div>
  488. ) : null;
  489. return labelContent;
  490. };
  491. renderLabel = () => {
  492. const { min, max, vertical, marks, verticalReverse } = this.props;
  493. const stylePos = vertical ? 'top' : 'left';
  494. const labelContent =
  495. marks && Object.keys(marks).length > 0 ? (
  496. <div className={cssClasses.MARKS + ((vertical && verticalReverse) ? '-reverse' : '')}>
  497. {Object.keys(marks).map(mark => {
  498. const activeResult = this.foundation.isMarkActive(Number(mark));
  499. const markPercent = (Number(mark) - min) / (max - min);
  500. return activeResult ? (
  501. // eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions
  502. <span
  503. key={mark}
  504. className={cls(`${prefixCls}-mark${(vertical && verticalReverse) ? '-reverse' : ''}`)}
  505. style={{ [stylePos]: `${markPercent * 100}%` }}
  506. onClick={this.foundation.handleWrapClick}
  507. >
  508. {marks[mark]}
  509. </span>
  510. ) : null;
  511. })}
  512. </div>
  513. ) : null;
  514. return labelContent;
  515. };
  516. render() {
  517. const wrapperClass = cls(
  518. `${prefixCls}-wrapper`,
  519. {
  520. [`${prefixCls}-disabled`]: this.state.disabled,
  521. [`${cssClasses.VERTICAL}-wrapper`]: this.props.vertical,
  522. [`${prefixCls}-reverse`]: this.props.vertical && this.props.verticalReverse
  523. },
  524. this.props.className
  525. );
  526. const boundaryClass = cls(`${prefixCls}-boundary`, {
  527. [`${prefixCls}-boundary-show`]: this.props.showBoundary && this.state.showBoundary,
  528. });
  529. const sliderCls = cls({
  530. [`${prefixCls}`]: !this.props.vertical,
  531. [cssClasses.VERTICAL]: this.props.vertical,
  532. });
  533. const slider = (
  534. <div
  535. className={wrapperClass}
  536. style={this.props.style}
  537. ref={this.sliderEl}
  538. onMouseEnter={() => this.foundation.handleWrapperEnter()}
  539. onMouseLeave={() => this.foundation.handleWrapperLeave()}
  540. >
  541. {// eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions
  542. <div
  543. className={`${prefixCls}-rail`}
  544. onClick={this.foundation.handleWrapClick}
  545. style={this.props.railStyle}
  546. />
  547. }
  548. {this.renderTrack()}
  549. {this.renderStepDot()}
  550. <div>{this.renderHandle()}</div>
  551. {this.renderLabel()}
  552. <div className={boundaryClass}>
  553. <span className={`${prefixCls}-boundary-min`}>{this.state.min}</span>
  554. <span className={`${prefixCls}-boundary-max`}>{this.state.max}</span>
  555. </div>
  556. </div>
  557. );
  558. if (!this.props.vertical) {
  559. return <div className={sliderCls}>{slider}</div>;
  560. }
  561. return slider;
  562. }
  563. private _addEventListener<T extends keyof HTMLElementEventMap>(target: HTMLElement, eventName: T, callback: (e: HTMLElementEventMap[T]) => void, ...rests: any) {
  564. if (target.addEventListener) {
  565. target.addEventListener(eventName, callback, ...rests);
  566. const clearSelf = () => {
  567. target?.removeEventListener(eventName, callback);
  568. Promise.resolve().then(() => {
  569. this.eventListenerSet.delete(clearSelf);
  570. });
  571. };
  572. this.eventListenerSet.add(clearSelf);
  573. return clearSelf;
  574. } else {
  575. return noop;
  576. }
  577. }
  578. }