Skip to content

Commit

Permalink
Merge pull request #1 from mastilver/passes-values-through
Browse files Browse the repository at this point in the history
feat: passes values through
  • Loading branch information
sindresorhus committed Nov 20, 2015
2 parents 1a1adf1 + 058e4da commit 516b22b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
13 changes: 12 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,16 @@ var isObservable = require('is-observable');
var symbolObservable = require('symbol-observable');

module.exports = function (x) {
return isObservable(x) ? x[symbolObservable]().forEach(function () {}) : x;
if (isObservable(x)) {
var result = [];

return x[symbolObservable]().forEach(function (value) {
result.push(value);
})
.then(function () {
return result;
});
}

return Promise.resolve(x);
};
5 changes: 3 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ $ npm install --save observable-to-promise
```js
const observableToPromise = require('observable-to-promise');

observableToPromise(Observable.of(1, 2)).then(() => {
console.log('done');
observableToPromise(Observable.of(1, 2)).then((result) => {
console.log(result);
// => [1, 2]
});
```

Expand Down
15 changes: 15 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,18 @@ test(t => {
t.true(isPromise(fn(zenObservable.of(1, 2))));
t.end();
});

test(t => {
fn(2).then(x => {
t.is(x, 2);
t.end();
});
});

test(t => {
fn(zenObservable.of(1, 2))
.then(result => {
t.same(result, [1, 2]);
t.end();
});
});

0 comments on commit 516b22b

Please sign in to comment.