Skip to content

Commit

Permalink
fix(fromEvent): rename static domEvent() to fromEvent() as extra
Browse files Browse the repository at this point in the history
Moved it to the extra folder.
  • Loading branch information
Andre Medeiros committed Apr 8, 2016
1 parent 05f519a commit c481cc8
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
7 changes: 0 additions & 7 deletions src/Stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
CombineInstanceSignature,
CombineFactorySignature,
CombineProjectFunction} from './factory/CombineProducer';
import {EventProducer} from './factory/EventProducer';
import {FromArrayProducer} from './factory/FromArrayProducer';
import {IntervalProducer} from './factory/IntervalProducer';
import {MergeProducer} from './factory/MergeProducer';
Expand Down Expand Up @@ -173,12 +172,6 @@ export class Stream<T> implements InternalListener<T> {
return new Stream<R>(new CombineProducer<R>(project, streams));
};

static domEvent(node: EventTarget,
eventType: string,
useCapture: boolean = false): Stream<Event> {
return new Stream<Event>(new EventProducer(node, eventType, useCapture));
}

map<U>(project: (t: T) => U): Stream<U> {
return new Stream<U>(new MapOperator(project, this));
}
Expand Down
9 changes: 8 additions & 1 deletion src/factory/EventProducer.ts → src/extra/fromEvent.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import {Stream} from '../Stream';
import {InternalProducer} from '../InternalProducer';
import {InternalListener} from '../InternalListener';

export class EventProducer implements InternalProducer<Event> {
export class DOMEventProducer implements InternalProducer<Event> {
private listener: EventListener;

constructor(private node: EventTarget,
Expand All @@ -20,3 +21,9 @@ export class EventProducer implements InternalProducer<Event> {
node.removeEventListener(eventType, listener, useCapture);
}
}

export default function fromEvent(node: EventTarget,
eventType: string,
useCapture: boolean = false): Stream<Event> {
return new Stream<Event>(new DOMEventProducer(node, eventType, useCapture));
}
11 changes: 6 additions & 5 deletions tests/factory/domEvent.ts → tests/extra/fromEvent.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import xs from '../../src/index';
import fromEvent from '../../src/extra/fromEvent';
import {noop} from '../../src/utils/noop';
import * as assert from 'assert';

Expand Down Expand Up @@ -36,10 +37,10 @@ class FakeEventTarget implements EventTarget {
}
};

describe('xs.domEvent', () => {
describe('fromEvent (extra)', () => {
it('should call addEventListener with expected parameters', () => {
const target = new FakeEventTarget();
const stream = xs.domEvent(target, 'test', true);
const stream = fromEvent(target, 'test', true);

stream.addListener({next: noop, error: noop, complete: noop});

Expand All @@ -49,7 +50,7 @@ describe('xs.domEvent', () => {

it('should call addEventListener with expected parameters', () => {
const target = new FakeEventTarget();
const stream = xs.domEvent(target, 'test');
const stream = fromEvent(target, 'test');

stream.addListener({next: noop, error: noop, complete: noop});

Expand All @@ -59,7 +60,7 @@ describe('xs.domEvent', () => {

it('should propagate events', (done) => {
const target = new FakeEventTarget();
const stream = xs.domEvent(target, 'test').take(3);
const stream = fromEvent(target, 'test').take(3);

let expected = [1, 2, 3];

Expand All @@ -84,7 +85,7 @@ describe('xs.domEvent', () => {

it('should call removeEventListener with expected parameters', (done) => {
const target = new FakeEventTarget();
const stream = xs.domEvent(target, 'test', true);
const stream = fromEvent(target, 'test', true);

stream.take(1).addListener({
next(x) {},
Expand Down
1 change: 0 additions & 1 deletion tests/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ describe('Stream', () => {
assert.equal(typeof xs.interval, 'function');
assert.equal(typeof xs.merge, 'function');
assert.equal(typeof xs.combine, 'function');
assert.equal(typeof xs.domEvent, 'function');
});

it('should have all the core operators as methods, plus addListener and removeListener', () => {
Expand Down

0 comments on commit c481cc8

Please sign in to comment.