Skip to content
This repository has been archived by the owner on Sep 10, 2022. It is now read-only.

Update rxjsObservableConfig for rxjs 6 #660

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,10 @@
"rollup-plugin-size-snapshot": "^0.3.0",
"rollup-plugin-uglify": "^3.0.0",
"rx": "^4.1.0",
"rxjs": "^5.0.0",
"rxjs": "^6.0.0",
"shelljs": "^0.6.0",
"sinon": "^1.17.1",
"symbol-observable": "^1.2.0",
"webpack": "^2.4.1",
"xstream": "^5.0.5"
},
Expand Down
1 change: 1 addition & 0 deletions scripts/jest.setup.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable */
jasmine.DEFAULT_TIMEOUT_INTERVAL = 20000

import 'symbol-observable'
import Enzyme from 'enzyme'
import Adapter from 'enzyme-adapter-react-16'

Expand Down
65 changes: 32 additions & 33 deletions src/packages/recompose/__tests__/componentFromStream-test.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
import React from 'react'
import { mount } from 'enzyme'
import { Observable, Subject } from 'rxjs'
import sinon from 'sinon'
import {
first,
last,
startWith,
map,
mapTo,
combineLatest,
tap,
} from 'rxjs/operators'
import rxjsConfig from '../rxjsObservableConfig'
import { componentFromStreamWithConfig } from '../componentFromStream'

const componentFromStream = componentFromStreamWithConfig(rxjsConfig)

test('componentFromStream creates a component from a prop stream transformation', () => {
const Double = componentFromStream(props$ =>
props$.map(({ n }) =>
<div>
{n * 2}
</div>
props$.pipe(
map(({ n }) =>
<div>
{n * 2}
</div>
)
)
)
const wrapper = mount(<Double n={112} />)
Expand Down Expand Up @@ -42,7 +52,7 @@ test('componentFromStream unsubscribes from stream before unmounting', () => {

test('componentFromStream renders nothing until the stream emits a value', () => {
const vdom$ = new Subject()
const Div = componentFromStream(() => vdom$.mapTo(<div />))
const Div = componentFromStream(() => vdom$.pipe(mapTo(<div />)))
const wrapper = mount(<Div />)
expect(wrapper.find('div').length).toBe(0)
vdom$.next()
Expand All @@ -54,7 +64,7 @@ test('handler multiple observers of props stream', () => {
const Other = () => <div />
const Div = componentFromStream(props$ =>
// Adds three observers to props stream
props$.combineLatest(props$, props$, props1 => <Other {...props1} />)
props$.pipe(combineLatest(props$, props$, props1 => <Other {...props1} />))
)

const wrapper = mount(<Div data-value={1} />)
Expand All @@ -71,18 +81,24 @@ test('complete props stream before unmounting', () => {
let counter = 0

const Div = componentFromStream(props$ => {
const first$ = props$.first().do(() => {
counter += 1
})
const first$ = props$.pipe(
first(),
tap(() => {
counter += 1
})
)

const last$ = props$
.last()
.do(() => {
const last$ = props$.pipe(
last(),
tap(() => {
counter -= 1
})
.startWith(null)
}),
startWith(null)
)

return props$.combineLatest(first$, last$, props1 => <div {...props1} />)
return props$.pipe(
combineLatest(first$, last$, props1 => <div {...props1} />)
)
})

const wrapper = mount(<Div />)
Expand All @@ -93,20 +109,3 @@ test('complete props stream before unmounting', () => {
wrapper.unmount()
expect(counter).toBe(0)
})

test('completed props stream should throw an exception', () => {
Copy link
Contributor Author

@wuct wuct May 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like rxjs 6 doesn't throw this error anymore. I need dig deeper into this test.

const Div = componentFromStream(props$ => {
const first$ = props$.filter(() => false).first().startWith(null)

return props$.combineLatest(first$, props1 => <div {...props1} />)
})

const wrapper = mount(<Div />)

expect(wrapper.find('div').length).toBe(1)

const error = sinon.stub(console, 'error')

expect(() => wrapper.unmount()).toThrowError(/no elements in sequence/)
expect(error.called).toBe(true)
})
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react'
import { mount } from 'enzyme'
import { Observable } from 'rxjs'
import { map } from 'rxjs/operators'
import { Stream as MostStream } from 'most'
import mostConfig from '../mostObservableConfig'
import rxjsConfig from '../rxjsObservableConfig'
Expand All @@ -20,10 +21,12 @@ test('componentFromStreamWithConfig creates a stream with the correct stream typ

const RXJSComponent = componentFromStreamWithConfig(rxjsConfig)(props$ => {
expect(props$ instanceof Observable).toBe(true)
return props$.map(v =>
<div>
{String(v)}
</div>
return props$.pipe(
map(v =>
<div>
{String(v)}
</div>
)
)
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ import React from 'react'
import { mount } from 'enzyme'
import { Stream as MostStream } from 'most'
import { Observable } from 'rxjs'
import { map } from 'rxjs/operators'
import { mapPropsStreamWithConfig } from '../'
import rxConfig from '../rxjsObservableConfig'
import mostConfig from '../mostObservableConfig'

// Most of mapPropsStreamConfig's functionality is covered by componentFromStream
test('mapPropsStreamWithConfig creates a higher-order component from a stream and a observable config', () => {
const Double = mapPropsStreamWithConfig(rxConfig)(props$ =>
props$.map(({ n }) => ({ children: n * 2 }))
props$.pipe(map(({ n }) => ({ children: n * 2 })))
)('div')
const wrapper = mount(<Double n={112} />)
const div = wrapper.find('div')
Expand All @@ -28,7 +29,7 @@ test('mapPropsStreamWithConfig creates a stream with the correct config', () =>

const RXJSComponent = mapPropsStreamWithConfig(rxConfig)(props$ => {
expect(props$ instanceof Observable).toBe(true)
return props$.map(v => v)
return props$.pipe(map(v => v))
})('div')

mount(<RXJSComponent />)
Expand Down
11 changes: 7 additions & 4 deletions src/packages/recompose/__tests__/setObservableConfig-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react'
import { mount } from 'enzyme'
import { map } from 'rxjs/operators'
import rxjs5Config from '../rxjsObservableConfig'
import rxjs4Config from '../rxjs4ObservableConfig'
import mostConfig from '../mostObservableConfig'
Expand All @@ -22,10 +23,12 @@ const testTransform = transform => {
test('works with RxJS 5', () => {
setObservableConfig(rxjs5Config)
testTransform(props$ =>
props$.map(({ n }) =>
<div>
{n * 2}
</div>
props$.pipe(
map(({ n }) =>
<div>
{n * 2}
</div>
)
)
)
})
Expand Down
4 changes: 2 additions & 2 deletions src/packages/recompose/rxjsObservableConfig.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Rx from 'rxjs'
import { from } from 'rxjs'

const config = {
fromESObservable: Rx.Observable.from,
fromESObservable: from,
toESObservable: stream => stream,
}

Expand Down
24 changes: 14 additions & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5580,18 +5580,18 @@ rx@^4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/rx/-/rx-4.1.0.tgz#a5f13ff79ef3b740fe30aa803fb09f98805d4782"

rxjs@^5.0.0:
version "5.5.9"
resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-5.5.9.tgz#12a0487794b00f5eb370fec2751bd973a89886fb"
dependencies:
symbol-observable "1.0.1"

rxjs@^5.0.0-beta.11:
version "5.4.1"
resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-5.4.1.tgz#b62f757f279445d265a18a58fb0a70dc90e91626"
dependencies:
symbol-observable "^1.0.1"

rxjs@^6.0.0:
version "6.0.0"
resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-6.0.0.tgz#d647e029b5854617f994c82fe57a4c6747b352da"
dependencies:
tslib "^1.9.0"

safe-buffer@^5.0.1, safe-buffer@^5.1.0, safe-buffer@^5.1.1, safe-buffer@~5.1.0, safe-buffer@~5.1.1:
version "5.1.1"
resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.1.tgz#893312af69b2123def71f57889001671eeb2c853"
Expand Down Expand Up @@ -6026,14 +6026,14 @@ swap-case@^1.1.0:
lower-case "^1.1.1"
upper-case "^1.1.1"

[email protected]:
version "1.0.1"
resolved "https://registry.yarnpkg.com/symbol-observable/-/symbol-observable-1.0.1.tgz#8340fc4702c3122df5d22288f88283f513d3fdd4"

[email protected], symbol-observable@^1.0.1, symbol-observable@^1.0.2:
version "1.0.4"
resolved "https://registry.yarnpkg.com/symbol-observable/-/symbol-observable-1.0.4.tgz#29bf615d4aa7121bdd898b22d4b3f9bc4e2aa03d"

symbol-observable@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/symbol-observable/-/symbol-observable-1.2.0.tgz#c22688aed4eab3cdc2dfeacbb561660560a00804"

symbol-tree@^3.2.2:
version "3.2.2"
resolved "https://registry.yarnpkg.com/symbol-tree/-/symbol-tree-3.2.2.tgz#ae27db38f660a7ae2e1c3b7d1bc290819b8519e6"
Expand Down Expand Up @@ -6190,6 +6190,10 @@ tryit@^1.0.1:
version "1.0.3"
resolved "https://registry.yarnpkg.com/tryit/-/tryit-1.0.3.tgz#393be730a9446fd1ead6da59a014308f36c289cb"

tslib@^1.9.0:
version "1.9.0"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.9.0.tgz#e37a86fda8cbbaf23a057f473c9f4dc64e5fc2e8"

[email protected]:
version "0.0.0"
resolved "https://registry.yarnpkg.com/tty-browserify/-/tty-browserify-0.0.0.tgz#a157ba402da24e9bf957f9aa69d524eed42901a6"
Expand Down