Skip to content

Use Hooks internally (aka 7.0) #1209

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 40 commits into from
Apr 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
0b04e67
Update React to latest
markerikson Mar 18, 2019
16a66c4
Update React peer dependency to 16.8.x
markerikson Mar 18, 2019
c31b94a
Initial re-implementation of `connectAdvanced` using hooks
markerikson Mar 18, 2019
9543efe
Update tests to match v7-alpha.1 behavior
markerikson Mar 18, 2019
1f2afe9
adding a react hooks test that fails with v7 alpha
saboya Feb 26, 2019
2f4372e
wrapping store.dispatch with rlt.act, fixes component renders
saboya Feb 26, 2019
d210de1
reducing hooks test to 2 components
saboya Feb 26, 2019
30178b7
Fix case where wrapper props changed before store update render
markerikson Mar 2, 2019
8b72631
Mark ReactDOM as global in UMD builds
markerikson Mar 18, 2019
af0c3a7
Fix perf problems with out-of-bounds array access
Andarist Feb 26, 2019
266ca97
Add modules to handle importing batchedUpdates
markerikson Mar 13, 2019
0887834
Use appropriate batched update API for subscriptions
markerikson Mar 13, 2019
593592e
Inject unstable_batchedUpdates in default entry point
markerikson Mar 13, 2019
4f0012c
Provide an alternate entry point for alternate renderers
markerikson Mar 13, 2019
688a270
Remove batch arg from createListenerCollection (#1205)
migueloller Mar 17, 2019
8755d5a
Remove older React versions from Travis
markerikson Mar 19, 2019
01ce9bd
Add comments to connectAdvanced. Many much comments!
markerikson Mar 19, 2019
b855e16
Re-add test for a custom store as a prop
markerikson Mar 19, 2019
939d976
Fix null pointer exception when store is given as a prop
markerikson Mar 19, 2019
eb03a37
Ensure wrapper props are passed correctly when forwarding refs
markerikson Mar 19, 2019
53c3b79
Add a test to verify subscription passthrough with store-as-prop
markerikson Mar 19, 2019
4401bf8
add non-batched tests (#1208)
maxkostow Mar 21, 2019
b578e96
Force SSR tests to mimic a Node environment
markerikson Mar 21, 2019
e77e005
Restructure connect tests to group by category for easier reading
markerikson Mar 22, 2019
c914580
Clean up dead code in Provider tests
markerikson Mar 22, 2019
efeadb5
Add tests to verify errors are thrown for bad mapState functions
markerikson Mar 22, 2019
96fec15
Fix edge cases around saved wrapper props and error handling
markerikson Mar 22, 2019
8479774
Formatting
markerikson Mar 22, 2019
cf946db
Add a test to verify no errors are printed in SSR usage
markerikson Mar 22, 2019
6cca35e
Ignore .idea/
markerikson Mar 22, 2019
9852814
7.0.0-beta.0
markerikson Mar 22, 2019
1d6ccc1
Updated outdated SSR-test (dispatch in ancestors) (#1213)
Ephem Mar 22, 2019
79982c9
Added test for injecting dynamic reducers on client and server (#1211)
Ephem Mar 22, 2019
73c0fbd
Remove WebStorm gitignore
timdorr Apr 3, 2019
17451c1
[FIX]: #1219 Save references before update (#1220)
josepot Apr 4, 2019
6c0f301
Re-ignore .idea/
markerikson Apr 4, 2019
1097eed
7.0.0-beta.1
markerikson Apr 4, 2019
cd99c72
Update the codecov config to be more forgiving.
timdorr Apr 4, 2019
c5fff64
Merge 'origin/master' into v7-beta
timdorr Apr 4, 2019
d8cd1a2
add test to verify that mapStateToProps is always called with latest …
MrWolfZ Apr 4, 2019
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ test/react/*/test/**/*.spec.js
test/react/**/src
test/jest-config.json
lcov.info
.idea/

lib/core/metadata.js
lib/core/MetadataBlog.js
Expand Down
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ language: node_js
node_js: node
cache: npm
env:
- REACT=16.4
- REACT=16.5
- REACT=16.6
- REACT=16.8
script:
- npm test
Expand Down
2 changes: 1 addition & 1 deletion docs/api/connect.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ The second parameter is normally referred to as `ownProps` by convention.

```js
// binds on component re-rendering
<button onClick={() => this.props.toggleTodo(this.props.todoId)} />
;<button onClick={() => this.props.toggleTodo(this.props.todoId)} />

// binds on `props` change
const mapDispatchToProps = (dispatch, ownProps) => {
Expand Down
1 change: 0 additions & 1 deletion docs/introduction/quick-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ export default connect(
)(Counter)
```


## Help and Discussion

The **[#redux channel](https://discord.gg/0ZcbPKXt5bZ6au5t)** of the **[Reactiflux Discord community](http://www.reactiflux.com)** is our official resource for all questions related to learning and using Redux. Reactiflux is a great place to hang out, ask questions, and learn - come join us!
Expand Down
8 changes: 4 additions & 4 deletions docs/using-react-redux/accessing-store.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,16 @@ export default connect(
mapDispatch,
null,
{ context: MyContext }
)(MyComponent);
)(MyComponent)

// or, call connect as normal to start
const ConnectedComponent = connect(
mapState,
mapDispatch
)(MyComponent);
)(MyComponent)

// Later, pass the custom context as a prop to the connected component
<ConnectedComponent context={MyContext} />
;<ConnectedComponent context={MyContext} />
```

The following runtime error occurs when React Redux does not find a store in the context it is looking. For example:
Expand Down Expand Up @@ -132,7 +132,7 @@ function MyConnectedComponent() {
// component where it can be used in lifecycle methods
}}
</ReactReduxContext.Consumer>
);
)
}
```

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-redux",
"version": "6.0.1",
"version": "7.0.0-beta.1",
"description": "Official React bindings for Redux",
"keywords": [
"react",
Expand Down Expand Up @@ -36,7 +36,7 @@
"coverage": "codecov"
},
"peerDependencies": {
"react": "^16.4.0-0",
"react": "^16.8.4",
"redux": "^2.0.0 || ^3.0.0 || ^4.0.0-0"
},
"dependencies": {
Expand Down
8 changes: 5 additions & 3 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ const env = process.env.NODE_ENV

const config = {
input: 'src/index.js',
external: Object.keys(pkg.peerDependencies || {}),
external: Object.keys(pkg.peerDependencies || {}).concat('react-dom'),
output: {
format: 'umd',
name: 'ReactRedux',
globals: {
react: 'React',
redux: 'Redux'
redux: 'Redux',
'react-dom': 'ReactDOM'
}
},
plugins: [
Expand All @@ -32,7 +33,8 @@ const config = {
'node_modules/react-is/index.js': [
'isValidElementType',
'isContextConsumer'
]
],
'node_modules/react-dom/index.js': ['unstable_batchedUpdates']
}
})
]
Expand Down
11 changes: 11 additions & 0 deletions src/alternate-renderers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Provider from './components/Provider'
import connectAdvanced from './components/connectAdvanced'
import { ReactReduxContext } from './components/Context'
import connect from './connect/connect'

import { getBatch } from './utils/batch'

// For other renderers besides ReactDOM and React Native, use the default noop batch function
const batch = getBatch()

export { Provider, connectAdvanced, ReactReduxContext, connect, batch }
54 changes: 23 additions & 31 deletions src/components/Provider.js
Original file line number Diff line number Diff line change
@@ -1,63 +1,55 @@
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { ReactReduxContext } from './Context'
import Subscription from '../utils/Subscription'

class Provider extends Component {
constructor(props) {
super(props)

const { store } = props

this.notifySubscribers = this.notifySubscribers.bind(this)
const subscription = new Subscription(store)
subscription.onStateChange = this.notifySubscribers

this.state = {
storeState: store.getState(),
store
store,
subscription
}

this.previousState = store.getState()
}

componentDidMount() {
this._isMounted = true
this.subscribe()

this.state.subscription.trySubscribe()

if (this.previousState !== this.props.store.getState()) {
this.state.subscription.notifyNestedSubs()
}
}

componentWillUnmount() {
if (this.unsubscribe) this.unsubscribe()

this.state.subscription.tryUnsubscribe()

this._isMounted = false
}

componentDidUpdate(prevProps) {
if (this.props.store !== prevProps.store) {
if (this.unsubscribe) this.unsubscribe()

this.subscribe()
this.state.subscription.tryUnsubscribe()
const subscription = new Subscription(this.props.store)
subscription.onStateChange = this.notifySubscribers
this.setState({ store: this.props.store, subscription })
}
}

subscribe() {
const { store } = this.props

this.unsubscribe = store.subscribe(() => {
const newStoreState = store.getState()

if (!this._isMounted) {
return
}

this.setState(providerState => {
// If the value is the same, skip the unnecessary state update.
if (providerState.storeState === newStoreState) {
return null
}

return { storeState: newStoreState }
})
})

// Actions might have been dispatched between render and mount - handle those
const postMountStoreState = store.getState()
if (postMountStoreState !== this.state.storeState) {
this.setState({ storeState: postMountStoreState })
}
notifySubscribers() {
this.state.subscription.notifyNestedSubs()
}

render() {
Expand Down
Loading