kefirjs / kefir

A Reactive Programming library for JavaScript
https://kefirjs.github.io/kefir/
MIT License
1.87k stars 97 forks source link

Property loses current value for pool.toProperty.flatMap.map #162

Closed aindlq closed 9 years ago

aindlq commented 9 years ago

I'm using latest stable version - 3.1.0.

const pool = Kefir.pool();
const property = pool.toProperty();
pool.plug(Kefir.constant(1));
property.log(); //[pool.toProperty] <value:current> 1

const property2 = property.flatMap(v => Kefir.constant(v + 1));
property2.log();//[pool.toProperty.flatMap] <value:current> 2

const property3 = property2.map(v => v + 1);
property3.log();//nothing
iofjuupasli commented 9 years ago

flatMap returns stream, not property

rpominov commented 9 years ago

Yeah, @iofjuupasli is right. You can convert it to a property like this:

const property2 = property.flatMap(v => Kefir.constant(v + 1)).toProperty();
aindlq commented 9 years ago

What is the reason to not preserve observable type for flatMap?

rpominov commented 9 years ago

Frankly I can't remember the original reasoning. But I think we should leave it as is, so people won't have to migrate.

Although we should fix the docs, it isn't mentioned that flatMap always returns a stream.