close #84 set mousemoveData's source by event source
This commit is contained in:
@@ -132,12 +132,12 @@ function record(options: recordOptions = {}): listenerHandler | undefined {
|
|||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
mousemoveCb: positions =>
|
mousemoveCb: (positions, source) =>
|
||||||
wrappedEmit(
|
wrappedEmit(
|
||||||
wrapEvent({
|
wrapEvent({
|
||||||
type: EventType.IncrementalSnapshot,
|
type: EventType.IncrementalSnapshot,
|
||||||
data: {
|
data: {
|
||||||
source: IncrementalSource.MouseMove,
|
source,
|
||||||
positions,
|
positions,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import {
|
|||||||
textCursor,
|
textCursor,
|
||||||
attributeCursor,
|
attributeCursor,
|
||||||
blockClass,
|
blockClass,
|
||||||
|
IncrementalSource,
|
||||||
} from '../types';
|
} from '../types';
|
||||||
import { deepDelete, isParentRemoved, isAncestorInSet } from './collection';
|
import { deepDelete, isParentRemoved, isAncestorInSet } from './collection';
|
||||||
|
|
||||||
@@ -275,13 +276,14 @@ function initMutationObserver(
|
|||||||
function initMoveObserver(cb: mousemoveCallBack): listenerHandler {
|
function initMoveObserver(cb: mousemoveCallBack): listenerHandler {
|
||||||
let positions: mousePosition[] = [];
|
let positions: mousePosition[] = [];
|
||||||
let timeBaseline: number | null;
|
let timeBaseline: number | null;
|
||||||
const wrappedCb = throttle(() => {
|
const wrappedCb = throttle((isTouch: boolean) => {
|
||||||
const totalOffset = Date.now() - timeBaseline!;
|
const totalOffset = Date.now() - timeBaseline!;
|
||||||
cb(
|
cb(
|
||||||
positions.map(p => {
|
positions.map(p => {
|
||||||
p.timeOffset -= totalOffset;
|
p.timeOffset -= totalOffset;
|
||||||
return p;
|
return p;
|
||||||
}),
|
}),
|
||||||
|
isTouch ? IncrementalSource.TouchMove : IncrementalSource.MouseMove,
|
||||||
);
|
);
|
||||||
positions = [];
|
positions = [];
|
||||||
timeBaseline = null;
|
timeBaseline = null;
|
||||||
@@ -301,7 +303,7 @@ function initMoveObserver(cb: mousemoveCallBack): listenerHandler {
|
|||||||
id: mirror.getId(target as INode),
|
id: mirror.getId(target as INode),
|
||||||
timeOffset: Date.now() - timeBaseline,
|
timeOffset: Date.now() - timeBaseline,
|
||||||
});
|
});
|
||||||
wrappedCb();
|
wrappedCb(isTouchEvent(evt));
|
||||||
},
|
},
|
||||||
50,
|
50,
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ export enum IncrementalSource {
|
|||||||
Scroll,
|
Scroll,
|
||||||
ViewportResize,
|
ViewportResize,
|
||||||
Input,
|
Input,
|
||||||
|
TouchMove,
|
||||||
}
|
}
|
||||||
|
|
||||||
export type mutationData = {
|
export type mutationData = {
|
||||||
@@ -66,7 +67,7 @@ export type mutationData = {
|
|||||||
} & mutationCallbackParam;
|
} & mutationCallbackParam;
|
||||||
|
|
||||||
export type mousemoveData = {
|
export type mousemoveData = {
|
||||||
source: IncrementalSource.MouseMove;
|
source: IncrementalSource.MouseMove | IncrementalSource.TouchMove;
|
||||||
positions: mousePosition[];
|
positions: mousePosition[];
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -176,7 +177,10 @@ type mutationCallbackParam = {
|
|||||||
|
|
||||||
export type mutationCallBack = (m: mutationCallbackParam) => void;
|
export type mutationCallBack = (m: mutationCallbackParam) => void;
|
||||||
|
|
||||||
export type mousemoveCallBack = (p: mousePosition[]) => void;
|
export type mousemoveCallBack = (
|
||||||
|
p: mousePosition[],
|
||||||
|
source: IncrementalSource.MouseMove | IncrementalSource.TouchMove,
|
||||||
|
) => void;
|
||||||
|
|
||||||
export type mousePosition = {
|
export type mousePosition = {
|
||||||
x: number;
|
x: number;
|
||||||
|
|||||||
13
src/utils.ts
13
src/utils.ts
@@ -53,14 +53,13 @@ export function throttle<T>(
|
|||||||
let timeout: number | null = null;
|
let timeout: number | null = null;
|
||||||
let previous = 0;
|
let previous = 0;
|
||||||
// tslint:disable-next-line: only-arrow-functions
|
// tslint:disable-next-line: only-arrow-functions
|
||||||
return function() {
|
return function(args: T) {
|
||||||
let now = Date.now();
|
let now = Date.now();
|
||||||
if (!previous && options.leading === false) {
|
if (!previous && options.leading === false) {
|
||||||
previous = now;
|
previous = now;
|
||||||
}
|
}
|
||||||
let remaining = wait - (now - previous);
|
let remaining = wait - (now - previous);
|
||||||
let context = this;
|
let context = this;
|
||||||
let args = arguments;
|
|
||||||
if (remaining <= 0 || remaining > wait) {
|
if (remaining <= 0 || remaining > wait) {
|
||||||
if (timeout) {
|
if (timeout) {
|
||||||
window.clearTimeout(timeout);
|
window.clearTimeout(timeout);
|
||||||
@@ -85,7 +84,12 @@ export function hookSetter<T>(
|
|||||||
isRevoked?: boolean,
|
isRevoked?: boolean,
|
||||||
): hookResetter {
|
): hookResetter {
|
||||||
const original = Object.getOwnPropertyDescriptor(target, key);
|
const original = Object.getOwnPropertyDescriptor(target, key);
|
||||||
Object.defineProperty(target, key, isRevoked ? d : {
|
Object.defineProperty(
|
||||||
|
target,
|
||||||
|
key,
|
||||||
|
isRevoked
|
||||||
|
? d
|
||||||
|
: {
|
||||||
set(value) {
|
set(value) {
|
||||||
// put hooked setter into event loop to avoid of set latency
|
// put hooked setter into event loop to avoid of set latency
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
@@ -95,7 +99,8 @@ export function hookSetter<T>(
|
|||||||
original.set.call(this, value);
|
original.set.call(this, value);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
});
|
},
|
||||||
|
);
|
||||||
return () => hookSetter(target, key, original || {}, true);
|
return () => hookSetter(target, key, original || {}, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user