-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Conversation
const identity = t => t | ||
|
||
test('mapPropsStream maps a stream of owner props to a stream of child props', t => { | ||
const SmartButton = mapPropsStream(props$ => { | ||
const { handler: onClick, stream: increment$ } = createEventHandler() | ||
const count$ = increment$ | ||
.startWith(0) | ||
.scan(total => total + 1) | ||
::startWith(0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bind operator is still at stage 0 so syntax may change in future and there are no guarantees it will be included in spec
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well it's a test, so oh well for now :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason I'm importing each helper separately is to ensure as much as possible that we're not depending on any RxJS-specific functionality.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, I understand that
It'll be cool if we can use not only RxJS but also most and other libraries. But this means recompose should use |
also interesting thread |
const mapPropsStream = transform => BaseComponent => { | ||
const factory = createEagerFactory(BaseComponent) | ||
return componentFromStream(ownerProps$ => | ||
Observable.create(observer => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't see .create
in proposal https://github.com/zenparsing/es-observable
may be better to use new Observable(observer =>
instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch!
As long as Observable is a global that follows the spec, it should work, right? |
Hmmm.. Probably you are right and it will work. I think I can create PR with some tests for most as well if you are not opposed =) |
Good idea at @chicoxyzzy ref cujojs/most#160 It will allow to remove global Observable ref, and the only downside |
We can still use bind syntax after converting ES-compatible stream to RxJS observable |
Just checked out. RxJS API and Most.js API are not 100% compatible so current docs from PR will work only for Rx but not Most. |
The original import Rx from 'rxjs/Rx';
import { from } from 'most';
const RxObservable = Rx.Observable.from(SomeObservable);
const MostObservable = from(SomeObservable); |
Eventually this also can make integration with mobx possible (for first time it will be possible using |
Redux does the same thing reduxjs/redux#1632 However IMO it's not so trivial to add |
I'm not sure we're on the same page. What is a "Recompose stream"? Are you referring to The purpose of A code example explaining what you mean would be helpful. |
Oh wait, I think I see what you mean about removing the global Observable. |
@chicoxyzzy @istarkov Alright, I just pushed a commit that removes the global Observable. The one downside I discovered to this approach, rather than mandating that your favorite observable library be available as an recompose/src/packages/recompose/__tests__/mapPropsStream-test.js Lines 20 to 29 in fbb62b6
I'm thinking maybe we could expose a global module like import configureObservable from 'recompose/configureObservable'
configureObservable(observable => Rx.Observable.from(observable))
// Then...
mapPropsStream(props$ => {
// props$ is an RxJS stream
}) What do you think of that idea? |
Pushed an implementation of |
|
||
const createEventHandler = () => { | ||
const emitter = createChangeEmitter() | ||
const transform = getTransform() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@acdlite Maybe allow pass to configureObservable
subject-like anything? And use change-emitter
if only passed Observable
dont has method next
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@typeetfunc Subject
is Rx-related thing. There are no subjects in most. There is https://github.com/TylorS/most-subject but @TylorS once said in most.js gitter chat that it's more like motorcycle/cycle-related thing.
Discussion about Subjects in most cujojs/most#164
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chicoxyzzy Thanks for links. Also observer dont has interop point like symbol-observable
- tc39/proposal-observable#89. Perhaps my proposal was a bit hasty :)
@acdlite I think it's worth it 👍 |
One thing I can suggest is to add tests for most to be sure Observable iterop compatibility works fine |
About 2 commits above:
|
Just trying to implement some most tests (actually an analogue of first one from mapStreamProps) but it seems like |
help me understand |
@istarkov Please don't add commits to a PR that's not yours without approval. Best way to do that is to submit a PR to this branch :) What is the value of the test file without bind syntax? I don't see any. |
@acdlite What about |
const enhance = compose(
getContext(contextTypes),
mapPropsStream(props$ => {
// context is part of props$
})
) |
d278dd8
to
5732a70
Compare
@acdlite oh sorry, i missed it. Thanks :) |
this.subscription = this.vdom$.subscribe( | ||
vdom => { | ||
this.subscription = this.vdom$.subscribe({ | ||
next: vdom => { | ||
this.didReceiveVdom = true | ||
if (!this.componentHasMounted) { | ||
this.state = { vdom } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why check on hasMounted? (It was a bug in react, but it solved)
Also looks like this.state = {}
could be changed on this.setState
as this method does not called from contructor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was a bug in react, but it solved
Link?
Also looks like this.state = {} could be changed on this.setState as this method does not called from contructor
You're right. This is left over from when it used to subscribe inside the constructor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Link ?
One of:
facebook/react#5719
fixed in 15.1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The check is to prevent calling setState
if the component has already unmounted. That issue seems unrelated? Could be wrong.
Re-commenting down here because original comment is on outdated diff: @istarkov The |
Looks like there is no need to check |
Oh duh that's right |
Didn't made any progress with my most.js tests yet and sorry for sort of offtopic but I think you may be interested in future of function bind syntax tc39/proposal-bind-operator#24 (comment) TL;DR
|
|
||
// Stream of vdom | ||
vdom$ = propsToVdom(this.props$); | ||
vdom$ = toObservable(propsToVdom(this.props$)); | ||
|
||
didReceiveVdom = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
vdom: null
could me moved into state initializer, so there will be no need in didReceiveVdom
at all
Summing up my previous comment I propose to add test which @istarkov provided earlier (without bind syntax) so no one will suffer refactoring their code after getting inspiration from test files. Also IMO tests should be written in JavaScript, not some dialect no one will understand one day 😃 |
Yeah I'll remove the The tests in |
@istarkov @chicoxyzzy Just added tests for compatibility with RxJS 4/5, most, xstream, and Bacon. I've also added modules that export the config for each library. Are there any other stream libraries that we should include? |
Wow! Last commit is super cool! |
@acdlite the only library I know besides these is Kefir. It's API should be similiar to Bacon |
@chicoxyzzy Huzzah, and it already does all the hard work for us! https://rpominov.github.io/kefir/#from-es-observable |
I actually Kefir's naming better, too: |
Symbol.observable
.createComponent
tocomponentFromStream