Skip to content

Commit

Permalink
Merge pull request #97 from zenparsing/remove-for-each
Browse files Browse the repository at this point in the history
Remove forEach and add "subscribe" overload
  • Loading branch information
zenparsing authored Jun 13, 2016
2 parents 7162ae6 + 0b2f567 commit ef98438
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 384 deletions.
29 changes: 7 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,23 +65,6 @@ Upon cancelation, the Observable's cleanup function will be executed.
subscription.unsubscribe();
```

Alternatively, we can subscribe to an Observable with the **forEach** method, which accepts
a single callback and returns a Promise.

```js
commandKeys(inputElement).forEach(val => {
console.log("Received key command: " + val);
});
```

```js
Observable.of(1, 2, 3, 4, 5)
.map(n => n * n)
.filter(n => n > 10)
.forEach(n => console.log(n))
.then(() => console.log("All done!"));
```

### Motivation ###

The Observable type represents one of the fundamental protocols for processing asynchronous
Expand Down Expand Up @@ -120,11 +103,13 @@ interface Observable {

constructor(subscriber : SubscriberFunction);

// Subscribes to the sequence
// Subscribes to the sequence with an observer
subscribe(observer : Observer) : Subscription;

// Subscribes to the sequence with a callback, returning a promise
forEach(onNext : any => any) : Promise;
// Subscribes to the sequence with callbacks
subscribe(onNext : Function,
onError? : Function,
onComplete? : Function) : Subscription;

// Returns itself
[Symbol.observable]() : Observable;
Expand All @@ -143,7 +128,7 @@ interface Subscription {
unsubscribe() : void;

// A boolean value indicating whether the subscription is closed
get closed() : Boolean
get closed() : Boolean;
}

function SubscriberFunction(observer: SubscriptionObserver) : (void => void)|Subscription;
Expand Down Expand Up @@ -265,6 +250,6 @@ interface SubscriptionObserver {
complete(completeValue);

// A boolean value indicating whether the subscription is closed
get closed() : Boolean
get closed() : Boolean;
}
```
Loading

0 comments on commit ef98438

Please sign in to comment.