Skip to content

Commit

Permalink
refactor(fromEvent): make fromEvent just a function
Browse files Browse the repository at this point in the history
- updates tests as well
  • Loading branch information
benlesh committed Mar 2, 2018
1 parent 0a3a04a commit 31d7a3f
Show file tree
Hide file tree
Showing 3 changed files with 233 additions and 262 deletions.
37 changes: 18 additions & 19 deletions spec/observables/fromEvent-spec.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
import { expect } from 'chai';
import * as Rx from '../../src/Rx';
import { expectObservable } from '../helpers/marble-testing';
import { fromEvent, never, timer } from '../../src';
import { TestScheduler } from '../../src/testing';

declare function asDiagram(arg: string): Function;
declare const rxTestScheduler: Rx.TestScheduler;

const Observable = Rx.Observable;
declare const rxTestScheduler: TestScheduler;

/** @test {fromEvent} */
describe('Observable.fromEvent', () => {
describe('fromEvent', () => {
asDiagram('fromEvent(element, \'click\')')
('should create an observable of click on the element', () => {
const target = {
addEventListener: (eventType, listener) => {
Observable.timer(50, 20, rxTestScheduler)
timer(50, 20, rxTestScheduler)
.mapTo('ev')
.take(2)
.concat(Observable.never())
.concat(never())
.subscribe(listener);
},
removeEventListener: () => void 0,
dispatchEvent: () => void 0,
};
const e1 = Observable.fromEvent(target, 'click');
const e1 = fromEvent(target, 'click');
const expected = '-----x-x---';
expectObservable(e1).toBe(expected, {x: 'ev'});
});
Expand All @@ -44,7 +43,7 @@ describe('Observable.fromEvent', () => {
}
};

const subscription = Observable.fromEvent(obj, 'click')
const subscription = fromEvent(obj, 'click')
.subscribe(() => {
//noop
});
Expand Down Expand Up @@ -74,7 +73,7 @@ describe('Observable.fromEvent', () => {
}
};

const subscription = Observable.fromEvent(<any>obj, 'click')
const subscription = fromEvent(<any>obj, 'click')
.subscribe(() => {
//noop
});
Expand Down Expand Up @@ -104,7 +103,7 @@ describe('Observable.fromEvent', () => {
}
};

const subscription = Observable.fromEvent(obj, 'click')
const subscription = fromEvent(obj, 'click')
.subscribe(() => {
//noop
});
Expand All @@ -124,7 +123,7 @@ describe('Observable.fromEvent', () => {
}
};

Observable.fromEvent(obj as any, 'click').subscribe({
fromEvent(obj as any, 'click').subscribe({
error(err) {
expect(err).to.exist
.and.be.instanceof(Error)
Expand All @@ -146,7 +145,7 @@ describe('Observable.fromEvent', () => {
}
};

const subscription = Observable.fromEvent(<any>obj, 'click', expectedOptions)
const subscription = fromEvent(<any>obj, 'click', expectedOptions)
.subscribe(() => {
//noop
});
Expand All @@ -167,7 +166,7 @@ describe('Observable.fromEvent', () => {
}
};

Observable.fromEvent(obj, 'click').take(1)
fromEvent(obj, 'click').take(1)
.subscribe((e: any) => {
expect(e).to.equal('test');
}, (err: any) => {
Expand All @@ -194,7 +193,7 @@ describe('Observable.fromEvent', () => {
return x + '!';
}

Observable.fromEvent(obj, 'click', selector).take(1)
fromEvent(obj, 'click', selector).take(1)
.subscribe((e: any) => {
expect(e).to.equal('test!');
}, (err: any) => {
Expand All @@ -221,7 +220,7 @@ describe('Observable.fromEvent', () => {
//noop
}

Observable.fromEvent(obj, 'click', selector).take(1)
fromEvent(obj, 'click', selector).take(1)
.subscribe((e: any) => {
expect(e).not.exist;
}, (err: any) => {
Expand All @@ -248,7 +247,7 @@ describe('Observable.fromEvent', () => {
return 'no arguments';
}

Observable.fromEvent(obj, 'click', selector).take(1)
fromEvent(obj, 'click', selector).take(1)
.subscribe((e: any) => {
expect(e).to.equal('no arguments');
}, (err: any) => {
Expand All @@ -275,7 +274,7 @@ describe('Observable.fromEvent', () => {
return [].slice.call(arguments);
}

Observable.fromEvent(obj, 'click', selector).take(1)
fromEvent(obj, 'click', selector).take(1)
.subscribe((e: any) => {
expect(e).to.deep.equal([1, 2, 3]);
}, (err: any) => {
Expand All @@ -298,7 +297,7 @@ describe('Observable.fromEvent', () => {
const obj: NullProtoEventTarget = new NullProtoEventTarget();

expect(() => {
Observable.fromEvent(obj, 'foo').subscribe();
fromEvent(obj, 'foo').subscribe();
done();
}).to.not.throw(TypeError);
});
Expand Down
241 changes: 0 additions & 241 deletions src/internal/observable/FromEventObservable.ts

This file was deleted.

Loading

0 comments on commit 31d7a3f

Please sign in to comment.