Skip to content

Commit

Permalink
Merge f3a899b into 082cc86
Browse files Browse the repository at this point in the history
  • Loading branch information
nordfjord committed Feb 12, 2018
2 parents 082cc86 + f3a899b commit f928bb7
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 117 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ __Other features__

* Supports the transducer protocol. You can for instance transduce streams with
[Ramda](http://ramdajs.com/) and [transducers.js](https://github.com/jlongster/transducers.js).
* Conforms to the fantasy land [monad](https://github.com/fantasyland/fantasy-land#monad) specification
* [Atomic updates](#atomic-updates).

## Examples
Expand Down Expand Up @@ -647,7 +648,7 @@ var evenNumbers = numbers
.pipe(filter(isEven));
```
### stream.map(f) __Deprecated__
### stream.map(f)
Returns a new stream identical to the original except every
value will be passed through `f`.
Expand All @@ -666,7 +667,7 @@ var numbers = flyd.stream(0);
var squaredNumbers = numbers.map(function(n) { return n*n; });
```
### stream1.ap(stream2) __Deprecated__
### stream1.ap(stream2)
`stream1` must be a stream of functions.
Expand Down
3 changes: 1 addition & 2 deletions examples/drag-and-drop/script.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
var flyd = require('flyd');
var flatMap = require('flyd/module/flatmap');
var takeUntil = require('flyd/module/takeuntil');

document.addEventListener('DOMContentLoaded', function() {
Expand All @@ -13,7 +12,7 @@ document.addEventListener('DOMContentLoaded', function() {
document.addEventListener('mousemove', mousemove);
document.addEventListener('mouseup', mouseup);

var mousedrag = flatMap(function(md) {
var mousedrag = flyd.chain(function(md) {
var startX = md.offsetX, startY = md.offsetY;

return takeUntil(flyd.map(function(mm) {
Expand Down
10 changes: 0 additions & 10 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,16 +128,6 @@ declare module 'flyd/module/filter' {
export = _Filter;
}

declare module 'flyd/module/flatmap' {
type projection<T, V> = (val: T) => flyd.Stream<V>;
interface flatMap {
<T, V>(project: projection<T, V>, source: flyd.Stream<T>): flyd.Stream<V>;
<T, V>(project: projection<T, V>): (source: flyd.Stream<T>) => flyd.Stream<V>;
}
const _flatMap: flatMap;
export = _flatMap;
}

declare module 'flyd/module/forwardto' {
interface ForwardTo {
<T, V>(stream: flyd.Stream<V>, project: (value: V) => T): flyd.Stream<T>;
Expand Down
7 changes: 0 additions & 7 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,6 @@ flyd.fromPromise = function fromPromise(p) {
return s;
}

/* istanbul ignore next */
flyd.flattenPromise = function flattenPromise(s) {
return combine(function(s, self) {
s().then(self);
Expand Down Expand Up @@ -676,12 +675,6 @@ function flushUpdate() {
* @param {*} value
*/
function updateStreamValue(s, n) {
/* istanbul ignore if */
if (n !== undefined && n !== null && isFunction(n.then)) {
console.warn('flyd: Promise swallowing has been deprecated, please see https://github.com/paldepind/flyd#promises for more info');
n.then(s);
return;
}
s.val = n;
s.hasVal = true;
if (inStream === undefined) {
Expand Down
54 changes: 0 additions & 54 deletions module/flatmap/README.md

This file was deleted.

23 changes: 0 additions & 23 deletions module/flatmap/index.js

This file was deleted.

98 changes: 79 additions & 19 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,26 +369,86 @@ describe('stream', function() {
});
});

describe('promise swallowing', function() {
it('pushes result of promise down the stream', function(done) {
var s = flyd.fromPromise(Promise.resolve(12));
combine(function(s) {
assert.equal(s(), 12);
done();
}, [s]);
describe('Promises', function() {
describe('fromPromise', function() {
it('pushes result of promise down the stream', function(done) {
var s = flyd.fromPromise(Promise.resolve(12));
combine(function(s) {
assert.equal(s(), 12);
done();
}, [s]);
});
it('recursively unpacks promise', function(done) {
var s = flyd.fromPromise(new Promise(function(res) {
setTimeout(function() {
res(new Promise(function(res) {
setTimeout(res.bind(null, 12));
}));
}, 20);
}));
combine(function(s) {
assert.equal(s(), 12);
done();
}, [s]);
});

it('does not process out of order promises', function(done) {
var promises = [];
var delay = function(ms, val) {
var p = new Promise(function(res) {
setTimeout(function() {
res(val);
}, ms)
});
promises.push(p);
return p;
};

var s = stream();
var res = s.chain(function(val) {
return flyd.fromPromise(delay(val, val));
})
.pipe(flyd.scan(function(acc, v) {
return acc + v;
}, 0));
s(100)(50)(70)(200);

Promise.all(promises).then(function() {
assert.equal(res(), 200);
done();
});

});
});
it('recursively unpacks promise', function(done) {
var s = flyd.fromPromise(new Promise(function(res) {
setTimeout(function() {
res(new Promise(function(res) {
setTimeout(res.bind(null, 12));
}));
}, 20);
}));
combine(function(s) {
assert.equal(s(), 12);
done();
}, [s]);
describe('flattenPromise', function() {
it('processes out of order promises', function(done) {
var promises = [];
var delay = function(ms, val) {
var p = new Promise(function(res) {
setTimeout(function() {
res(val);
}, ms)
});
promises.push(p);
return p;
};

var s = stream();
var res = s.map(function(val) {
return delay(val, val);
})
.pipe(flyd.flattenPromise)
.pipe(flyd.scan(function(acc, v) {
return acc + v;
}, 0));
s(100)(50)(70)(200);

Promise.all(promises).then(function() {
assert.equal(res(), 420);
done();
});

});
});
});

Expand Down

0 comments on commit f928bb7

Please sign in to comment.