本文整理汇总了TypeScript中rxjs/Subject.Subject.scan方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Subject.scan方法的具体用法?TypeScript Subject.scan怎么用?TypeScript Subject.scan使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rxjs/Subject.Subject
的用法示例。
在下文中一共展示了Subject.scan方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: constructor
constructor(
private _reducer: Reducer<T>,
initialState: T
) {
super(initialState);
this._dispatcher = new Subject<Action>();
this._dispatcher
.scan(
(state: T, action: Action) => this._reducer(state, action),
initialState)
.subscribe((state) => super.next(state));
}
示例2: function
/**
* pointer mode
*/
export default function(target: HTMLElement) {
const coord = new Subject<MouseEvent>();
const toggle = new Subject<any>();
const x = coord.map((e) => e.clientX + 'px');
const y = coord.map((e) => e.clientY + 'px');
x.subscribe(styleAssignOf(target, 'left'));
y.subscribe(styleAssignOf(target, 'top'));
toggle
.scan((acc) => !acc, false)
.map((bool) => bool ? 'false' : 'true')
.subscribe(attributeAssignOf(target, 'aria-hidden'));
return {
ptCoord : coord,
ptToggle : toggle
};
}
示例3: constructor
constructor(element: HTMLElement) {
this._element = element;
this._preventMouseDownOperation$ = new Subject<IPreventMouseDownOperation>();
this._preventMouseDown$ = new Subject<boolean>();
this._mouseMoveOperation$ = new Subject<IMouseMoveOperation>();
this._claimMouse$ = new Subject<IMouseClaim>();
this._mouseDown$ = Observable.fromEvent<MouseEvent>(element, "mousedown");
this._mouseLeave$ = Observable.fromEvent<MouseEvent>(element, "mouseleave");
this._mouseUp$ = Observable.fromEvent<MouseEvent>(element, "mouseup");
this._mouseOver$ = Observable.fromEvent<MouseEvent>(element, "mouseover");
this._click$ = Observable.fromEvent<MouseEvent>(element, "click");
this._mouseWheel$ = Observable.fromEvent<WheelEvent>(element, "wheel");
this._mouseWheel$
.subscribe(
(event: WheelEvent): void => {
event.preventDefault();
});
this._preventMouseDownOperation$
.scan<boolean>(
(prevent: boolean, operation: IPreventMouseDownOperation): boolean => {
return operation(prevent);
},
true)
.subscribe();
this._preventMouseDown$
.map<IPreventMouseDownOperation>(
(prevent: boolean): IPreventMouseDownOperation => {
return (previous: boolean): boolean => {
return prevent;
};
})
.subscribe(this._preventMouseDownOperation$);
this._mouseDown$
.map<IPreventMouseDownOperation>(
(e: MouseEvent): IPreventMouseDownOperation => {
return (prevent: boolean): boolean => {
if (prevent) {
e.preventDefault();
}
return prevent;
};
})
.subscribe(this._preventMouseDownOperation$);
this._mouseMove$ = this._mouseMoveOperation$
.scan<MouseEvent>(
(e: MouseEvent, operation: IMouseMoveOperation): MouseEvent => {
return operation(e);
},
null);
Observable
.fromEvent<MouseEvent>(element, "mousemove")
.map<IMouseMoveOperation>(
(e: MouseEvent) => {
return (previous: MouseEvent): MouseEvent => {
if (previous == null) {
previous = e;
}
if (e.movementX == null) {
e.movementX = e.clientX - previous.clientX;
}
if (e.movementY == null) {
e.movementY = e.clientY - previous.clientY;
}
return e;
};
})
.subscribe(this._mouseMoveOperation$);
let dragStop$: Observable<MouseEvent> = Observable
.merge<MouseEvent>(this._mouseLeave$, this._mouseUp$);
this._mouseDragStart$ = this._mouseDown$
.mergeMap<MouseEvent>((e: MouseEvent): Observable<MouseEvent> => {
return this._mouseMove$
.takeUntil(dragStop$)
.take(1);
});
this._mouseDrag$ = this._mouseDown$
.mergeMap<MouseEvent>((e: MouseEvent): Observable<MouseEvent> => {
return this._mouseMove$
.skip(1)
.takeUntil(dragStop$);
});
this._mouseDragEnd$ = this._mouseDragStart$
//.........这里部分代码省略.........
示例4: constructor
constructor(element: HTMLElement) {
this._element = element;
this._touchStart$ = Observable.fromEvent<TouchEvent>(element, "touchstart");
this._touchMove$ = Observable.fromEvent<TouchEvent>(element, "touchmove");
this._touchEnd$ = Observable.fromEvent<TouchEvent>(element, "touchend");
this._touchCancel$ = Observable.fromEvent<TouchEvent>(element, "touchcancel");
this._preventTouchMoveOperation$ = new Subject<IPreventTouchMoveOperation>();
this._preventTouchMove$ = new Subject<boolean>();
this._preventTouchMoveOperation$
.scan<boolean>(
(prevent: boolean, operation: IPreventTouchMoveOperation): boolean => {
return operation(prevent);
},
true)
.subscribe();
this._preventTouchMove$
.map<IPreventTouchMoveOperation>(
(prevent: boolean): IPreventTouchMoveOperation => {
return (previous: boolean): boolean => {
return prevent;
};
})
.subscribe(this._preventTouchMoveOperation$);
this._touchMove$
.map<IPreventTouchMoveOperation>(
(te: TouchEvent): IPreventTouchMoveOperation => {
return (prevent: boolean): boolean => {
if (prevent) {
te.preventDefault();
}
return prevent;
};
})
.subscribe(this._preventTouchMoveOperation$);
this._singleTouchMoveOperation$ = new Subject<ITouchMoveOperation>();
this._singleTouchMove$ = this._singleTouchMoveOperation$
.scan<TouchMove>(
(touch: TouchMove, operation: ITouchMoveOperation): TouchMove => {
return operation(touch);
},
new TouchMove());
this._touchMove$
.filter(
(te: TouchEvent): boolean => {
return te.touches.length === 1 && te.targetTouches.length === 1;
})
.map<ITouchMoveOperation>(
(te: TouchEvent): ITouchMoveOperation => {
return (previous: TouchMove): TouchMove => {
let touch: Touch = te.touches[0];
let current: TouchMove = new TouchMove(touch);
current.movementX = touch.pageX - previous.pageX;
current.movementY = touch.pageY - previous.pageY;
return current;
};
})
.subscribe(this._singleTouchMoveOperation$);
let singleTouchStart$: Observable<TouchEvent> = Observable
.merge<TouchEvent>(
this._touchStart$,
this._touchEnd$,
this._touchCancel$)
.filter(
(te: TouchEvent): boolean => {
return te.touches.length === 1 && te.targetTouches.length === 1;
});
let multipleTouchStart$: Observable<TouchEvent> = Observable
.merge<TouchEvent>(
this._touchStart$,
this._touchEnd$,
this._touchCancel$)
.filter(
(te: TouchEvent): boolean => {
return te.touches.length >= 1;
});
let touchStop$: Observable<TouchEvent> = Observable
.merge<TouchEvent>(
this._touchEnd$,
this._touchCancel$)
.filter(
(te: TouchEvent): boolean => {
return te.touches.length === 0;
});
this._singleTouch$ = singleTouchStart$
//.........这里部分代码省略.........