本文整理匯總了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$
//.........這裏部分代碼省略.........