Skip to content
This repository was archived by the owner on Dec 31, 2020. It is now read-only.
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: mobxjs/mobx-react
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 5.2.7
Choose a base ref
...
head repository: mobxjs/mobx-react
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 5.2.8
Choose a head ref
  • 2 commits
  • 3 files changed
  • 1 contributor

Commits on Sep 10, 2018

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    942f461 View commit details
  2. Published version 5.2.8

    mweststrate committed Sep 10, 2018
    Copy the full SHA
    f578aef View commit details
Showing with 23 additions and 12 deletions.
  1. +4 −0 CHANGELOG.md
  2. +1 −1 package.json
  3. +18 −11 src/Provider.js
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# MobX-React Changelog

### 5.2.8

* Make sure `mobx-react` doesn't require `Object.assign` polyfill

### 5.2.7

* Fixed issue where React 16.5 printed a warning when using `Provider`, fixes [#545](https://github.com/mobxjs/mobx-react/issues/545)
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mobx-react",
"version": "5.2.7",
"version": "5.2.8",
"description": "React bindings for MobX. Create fully reactive components.",
"main": "index.js",
"jsnext:main": "index.module.js",
29 changes: 18 additions & 11 deletions src/Provider.js
Original file line number Diff line number Diff line change
@@ -15,7 +15,8 @@ class Provider extends Component {

constructor(props, context) {
super(props, context)
this.state = Object.assign({}, props)
this.state = {}
copyStores(props, this.state)
}

render() {
@@ -25,15 +26,9 @@ class Provider extends Component {
getChildContext() {
const stores = {}
// inherit stores
const baseStores = this.context.mobxStores
if (baseStores)
for (let key in baseStores) {
stores[key] = baseStores[key]
}
copyStores(this.context.mobxStores, stores)
// add own stores
for (let key in this.props)
if (!specialReactKeys[key] && key !== "suppressChangedStoreWarning")
stores[key] = this.props[key]
copyStores(this.props, stores)
return {
mobxStores: stores
}
@@ -44,13 +39,16 @@ class Provider extends Component {
if (!prevState) return nextProps

// Maybe this warning is too aggressive?
if (Object.keys(nextProps).length !== Object.keys(prevState).length)
if (
Object.keys(nextProps).filter(validStoreName).length !==
Object.keys(prevState).filter(validStoreName).length
)
console.warn(
"MobX Provider: The set of provided stores has changed. Please avoid changing stores as the change might not propagate to all children"
)
if (!nextProps.suppressChangedStoreWarning)
for (let key in nextProps)
if (!specialReactKeys[key] && prevState[key] !== nextProps[key])
if (validStoreName(key) && prevState[key] !== nextProps[key])
console.warn(
"MobX Provider: Provided store '" +
key +
@@ -61,6 +59,15 @@ class Provider extends Component {
}
}

function copyStores(from, to) {
if (!from) return
for (let key in from) if (validStoreName(key)) to[key] = from[key]
}

function validStoreName(key) {
return !specialReactKeys[key] && key !== "suppressChangedStoreWarning"
}

// TODO: kill in next major
polyfill(Provider)