How to use the fromEvent function from rxjs

Find comprehensive JavaScript rxjs.fromEvent code examples handpicked from public code repositorys.

7
8
9
10
11
12
13
14
15
16

// Stream of connections
const connection$ = io$
  .pipe(
    switchMap(io =>
      fromEvent(io, 'connection')
        .pipe(
          map(client => ({ io, client }))
        )
    )
fork icon6
star icon26
watch icon4

+ 7 other calls in file

25
26
27
28
29
30
31
32
33

const gameStarts$ = fromEvent(demo.gameEvents, 'round_start').pipe(
    tap(() => console.log('GAME STARTED')),
    first(),
);
const gameEnds$ = fromEvent(demo, 'end').pipe(
    tap(() => console.log('GAME ENDED')),
    first(),
);
fork icon0
star icon10
watch icon2

+ 13 other calls in file

44
45
46
47
48
49
50
51
52
53
);

// Some demos have round_end not round_officially_ended. Some are the other way around.
// So we'll use both and do the best we can with that.
let lastRoundScore = {};
const roundEndsWinner$ = fromEvent(demo.gameEvents, 'round_end').pipe(
    rxop.filter(e => (e.winner === demofile.TEAM_TERRORISTS || e.winner === demofile.TEAM_CTS) && e.reason < 11),
    rxop.map(e => {
        if (e.winner === demofile.TEAM_TERRORISTS) return {winner: 'T'};
        else if (e.winner === demofile.TEAM_CTS) return {winner: 'CT'};
fork icon0
star icon10
watch icon2

+ 9 other calls in file

28
29
30
31
32
33
34
35
36
37
input.min = '0';
input.max = '100';
it.value = (Math.random() * (100 - 0 + 1) + 0);
input.value = it.value.toString();
input.className = 'slider';
fromEvent(input, 'mousemove').subscribe((event: Event) => {
    let target: any = event.target!;
    let newVar = target['value'];
    // console.log(newVar);
    it.value = Number(newVar);
fork icon0
star icon3
watch icon3

+ 11 other calls in file

75
76
77
78
79
80
81
82
83
84
  subOptions.symKeyID = symKeyID;
}

const emitter = subscribe('messages', subOptions);

const obsData = fromEvent(emitter, 'data').pipe(map(result => ({
  data: JSON.parse(toAscii(result.payload)),
  payload: result.payload,
  recipientPublicKey: result.recipientPublicKey,
  result,
fork icon533
star icon0
watch icon132

+ 7 other calls in file

16
17
18
19
20
21
22
23
24
25
ofType(ADDED_FLIC_CLIENT),
mergeMap(({
        flicClient,
        hostname,
}) => (
        fromEvent(
                flicClient,
                'ready',
        )
        .pipe(
fork icon2
star icon6
watch icon2

+ 11 other calls in file

95
96
97
98
99
100
101
102
103
104
        .forEach(this.onSpaceKey.bind(this));

        function normalizeKeypressEvents(value, key) {
                return { value: value, key: key || {} };
        }
        fromEvent(this.rl.input, 'keypress', normalizeKeypressEvents)
        .pipe(filter(({ key }) => key && key.name === 'tab'), share())
        .pipe(takeUntil(validation.success))
        .forEach(this.onTabKey.bind(this));
}
fork icon3
star icon3
watch icon3

10
11
12
13
14
15
16
17
18
19
  .pipe(takeUntil(fromEvent(rl, 'close')))
  // Ignore `enter` key. On the readline, we only care about the `line` event.
  .pipe(filter(({ key }) => key.name !== 'enter' && key.name !== 'return'));

return {
  line: fromEvent(rl, 'line'),
  keypress: keypress,

  normalizedUpKey: keypress.pipe(
    filter(
fork icon0
star icon2
watch icon1

+ 3 other calls in file

152
153
154
155
156
157
158
159
160
  .forEach(this.onSpaceKey.bind(this, false));

function normalizeKeypressEvents(value, key) {
  return { value: value, key: key || {} };
}
fromEvent((this.rl as any).input, 'keypress', normalizeKeypressEvents)
  .pipe(filter(({ key }) => key && key.name === 'tab'), share())
  .pipe(takeUntil(validation.success))
  .forEach(this.onSpaceKey.bind(this, true));
fork icon25
star icon0
watch icon0

+ 11 other calls in file

50
51
52
53
54
55
56
57
58
 * Given a ring, creates a stream out of its move actions
 * @param ring
 * @returns {Observable<*>}
 */
function createRingMoveStream(ring){
        const move$ = fromEvent(ring, 'move');
        const err$ = fromEvent(ring, 'error').pipe(
                mergeMap((err) => throwError(err))
        );
fork icon0
star icon1
watch icon5

+ 7 other calls in file

48
49
50
51
52
53
54
55
56
57
exports.concat = rxjs.concat;
exports.defer = rxjs.defer;
exports.empty = rxjs.empty;
exports.forkJoin = rxjs.forkJoin;
exports.from = rxjs.from;
exports.fromEvent = rxjs.fromEvent;
exports.fromEventPattern = rxjs.fromEventPattern;
exports.generate = rxjs.generate;
exports.iif = rxjs.iif;
exports.interval = rxjs.interval;
fork icon299
star icon0
watch icon1

472
473
474
475
476
477
478
479
480
481

// close the stdio target if we have one defined
if (stdioTarget) {
  Rx.combineLatest([
    Rx.fromEvent(this._process.stderr, 'end'),
    Rx.fromEvent(this._process.stdout, 'end'),
  ])
    .pipe(Rx.first())
    .subscribe(() => {
      stdioTarget.end();
fork icon0
star icon0
watch icon1

+ 203 other calls in file

61
62
63
64
65
66
67
68
69
70
    this.process = undefined;
    const endDate = new Date(Date.now());
    this.timer.next({ startDate, endDate });
    this.error.next(event);
});
Rx.fromEvent(child, 'close').subscribe(([exitCode, signal]) => {
    this.process = undefined;
    this.exited = true;
    const endDate = new Date(Date.now());
    this.timer.next({ startDate, endDate });
fork icon0
star icon0
watch icon1

+ 21 other calls in file

45
46
47
48
49
50
51
52
53
54
handle(commands) {
    const { inputStream } = this;
    if (!inputStream) {
        return { commands };
    }
    Rx.fromEvent(inputStream, 'data')
        .pipe((0, operators_1.map)((data) => String(data)))
        .subscribe((data) => {
        const dataParts = data.split(/:(.+)/);
        const targetId = dataParts.length > 1 ? dataParts[0] : this.defaultInputTarget;
fork icon0
star icon0
watch icon1

+ 9 other calls in file

59
60
61
62
63
64
65
66
67
68
}

setupRxjsListeners() {
  this.watchMouseDown$ = fromEvent(this.watchContainer, 'mousedown').pipe(getRxjsTarget())
  this.watchMouseUp$ = fromEvent(this.watchContainer, 'mouseup').pipe(getRxjsTarget())
  this.watchKeyDown$ = fromEvent(this.wholePage, 'keydown').pipe(getRxjsTargetFromKey())
  this.watchKeyUp$ = fromEvent(this.wholePage, 'keyup').pipe(getRxjsTargetFromKey())

  this.mergeEvents();
  this.subscribeToEvents();
fork icon0
star icon0
watch icon34

+ 15 other calls in file

14
15
16
17
18
19
20
21
22
);
// .subscribe(console.log);

// 网页载入完毕后就开始计时,等啊等,等到 button 点击后开始连续打印
const button = document.getElementById('submit');
const buttonEvents = fromEvent(button, 'click');

interval(1000).pipe(take(10), skipUntil(buttonEvents));
// .subscribe(console.log);
fork icon0
star icon0
watch icon2

+ 3 other calls in file

292
293
294
295
296
297
298
299
300
301
var _this = this;
if (!kendo_angular_common_1.isDocumentAvailable()) {
    return;
}
this.ngZone.runOutsideAngular(function () {
    _this.documentClick = rxjs_1.fromEvent(document, 'click').pipe(operators_1.filter(function (event) {
        return !(_this.wrapper !== event.target && _this.wrapper.contains(event.target));
    }));
    _this.blurSubscription = rxjs_1.merge(_this.documentClick, _this.navigation.onTab).subscribe(function () {
        if (_this.navigation.focused) {
fork icon0
star icon0
watch icon0

224
225
226
227
228
229
230
231
232
233
};
VirtualizationComponent.prototype.scrollStep = function (start, end) {
    return Math.abs(end - start) / (this.scrollDuration / FRAME_DURATION);
};
VirtualizationComponent.prototype.scroll$ = function () {
    return kendo_angular_common_1.isDocumentAvailable() ? rxjs_1.fromEvent(this.container.nativeElement, 'scroll') : rxjs_1.EMPTY;
};
VirtualizationComponent.prototype.initServices = function () {
    var _this = this;
    this.rowHeightService = this.createRowHeightService();
fork icon0
star icon0
watch icon0

81
82
83
84
85
86
87
88
89
90
    var filterElement = utils_1.closest(e.target, _this.filter);
    if (filterElement) {
        _this.hideElementTitle({ nativeElement: filterElement });
    }
});
_this.mouseOverSubscription = rxjs_1.fromEvent(wrapper, 'mouseover')
    .pipe(operators_1.debounceTime(100), operators_1.filter(function () { return _this.filter !== ''; }))
    .subscribe(function (e) { return _this.onMouseOver(e); });
_this.mouseOutSubscription = rxjs_1.fromEvent(wrapper, 'mouseout')
    .pipe(operators_1.debounceTime(100))
fork icon0
star icon0
watch icon0

+ 4 other calls in file

203
204
205
206
207
208
209
210
211
212
    var rtl = _a.rtl;
    return (_this.direction = rtl ? 'rtl' : 'ltr');
});
if (kendo_angular_common_3.isDocumentAvailable()) {
    this.zone.runOutsideAngular(function () {
        return (_this.closeOverflowSubscription = rxjs_1.fromEvent(document, 'click')
            .pipe(operators_1.filter(function () { return !!_this.popupRef; }), operators_1.filter(function (ev) { return !_this.popupRef.popup.instance.container.nativeElement.contains(ev.target); }), operators_1.filter(function (ev) { return !_this.overflowButton.nativeElement.contains(ev.target); }))
            .subscribe(function () {
            _this.zone.run(function () {
                _this.popupOpen = false;
fork icon0
star icon0
watch icon0