This repository has been archived by the owner on Sep 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge rx-recompose into main project (#196)
* Merge rx-recompose into main project * createComponent -> componentFromStream * Use Observable constructor instead of Observable.create * Remove global observable and use Symbol.observable instead * configureObservable applies a pre-transform to all observables * Empty, don't need it * Fix rxjs import * Configure transforms to and from observables * Docs for configureObservable * Typo * No need to check if component has mounted * No need to check if component has unmounted * Remove Observable as global from eslintrc * Don't need didReceiveProps check * Add configs for popular stream libraries * Add config for Kefir * Implement Symbol.observable, for correctness * Bump rxjs to latest beta
- Loading branch information
Showing
27 changed files
with
596 additions
and
395 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
src/packages/recompose/__tests__/componentFromStream-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import test from 'ava' | ||
import React from 'react' | ||
import { mount } from 'enzyme' | ||
import { Observable, Subject } from 'rxjs' | ||
import setObservableConfig from '../setObservableConfig' | ||
import rxjsConfig from '../rxjsObservableConfig' | ||
import componentFromStream from '../componentFromStream' | ||
|
||
setObservableConfig(rxjsConfig) | ||
|
||
test('componentFromStream creates a component from a prop stream transformation', t => { | ||
const Double = componentFromStream(props$ => | ||
props$.map(({ n }) => <div>{n * 2}</div>) | ||
) | ||
const wrapper = mount(<Double n={112} />) | ||
const div = wrapper.find('div') | ||
t.is(div.text(), '224') | ||
wrapper.setProps({ n: 358 }) | ||
t.is(div.text(), '716') | ||
}) | ||
|
||
test('componentFromStream unsubscribes from stream before unmounting', t => { | ||
let subscriptions = 0 | ||
const vdom$ = new Observable(observer => { | ||
subscriptions += 1 | ||
observer.next(<div />) | ||
return { | ||
unsubscribe() { | ||
subscriptions -= 1 | ||
} | ||
} | ||
}) | ||
const Div = componentFromStream(() => vdom$) | ||
const wrapper = mount(<Div />) | ||
t.is(subscriptions, 1) | ||
wrapper.unmount() | ||
t.is(subscriptions, 0) | ||
}) | ||
|
||
test('componentFromStream renders nothing until the stream emits a value', t => { | ||
const vdom$ = new Subject() | ||
const Div = componentFromStream(() => vdom$.mapTo(<div />)) | ||
const wrapper = mount(<Div />) | ||
t.is(wrapper.find('div').length, 0) | ||
vdom$.next() | ||
t.is(wrapper.find('div').length, 1) | ||
}) | ||
|
||
test('handler multiple observers of props stream', t => { | ||
const Div = componentFromStream(props$ => | ||
// Adds three observers to props stream | ||
props$.combineLatest( | ||
props$, props$, | ||
props1 => <div {...props1} /> | ||
) | ||
) | ||
|
||
const wrapper = mount(<Div value={1} />) | ||
const div = wrapper.find('div') | ||
|
||
t.is(div.prop('value'), 1) | ||
wrapper.setProps({ value: 2 }) | ||
t.is(div.prop('value'), 2) | ||
}) |
14 changes: 7 additions & 7 deletions
14
...pose/__tests__/createEventHandler-test.js → ...pose/__tests__/createEventHandler-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import test from 'ava' | ||
import React from 'react' | ||
import setObservableConfig from '../setObservableConfig' | ||
import rxjsConfig from '../rxjsObservableConfig' | ||
import { mount } from 'enzyme' | ||
import { mapPropsStream } from '../' | ||
|
||
setObservableConfig(rxjsConfig) | ||
|
||
// Most of mapPropsStream's functionality is covered by componentFromStream | ||
test('mapPropsStream creates a higher-order component from a stream', t => { | ||
const Double = mapPropsStream(props$ => | ||
props$.map(({ n }) => ({ children: n * 2 })) | ||
)('div') | ||
const wrapper = mount(<Double n={112} />) | ||
const div = wrapper.find('div') | ||
t.is(div.text(), '224') | ||
wrapper.setProps({ n: 358 }) | ||
t.is(div.text(), '716') | ||
}) |
Oops, something went wrong.