我在听 mousemove
事件直到mouseup
.我正在做 takeUntil
.
我的代码:
const onMouseMove = fromEvent(window, "mousemove");
const onMouseUp = fromEvent(window, "mouseup");
const resizePanel = onMouseMove
.pipe(
takeUntil(onMouseUp),
map(
(event: MouseEvent) => {
this.isDragging = true;
this.resizePanel(event.clientX);
}
)
);
我有一个变量
isDragging: boolean
,我想设置为 false
, 当 mouseup
发生,例如后 takeUntil
在我的代码中。它一定很简单,但我无法弄清楚。
最佳答案
你可能想尝试这样的事情
const onMouseMove = fromEvent(window, "mousemove");
const onMouseUp = fromEvent(window, "mouseup");
const resizePanel = onMouseMove
.pipe(
takeUntil(onMouseUp.pipe(tap(() => this.isDragging = false))),
map(
(event: MouseEvent) => {
this.isDragging = true;
this.resizePanel(event.clientX);
}
)
);
这个想法是添加一个
pipe
与 tap
运营商到 onMouseUp
用作 takeUntil
的参数
关于rxjs - 在 takeUntil 之后做一些 Action ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52886276/