mongodb-js / connect-backbone-to-react

Connect Backbone Models and Collections to React.
https://www.npmjs.com/package/connect-backbone-to-react
Apache License 2.0
27 stars 5 forks source link

Fix models existence check on componentWillReceiveProps #11

Closed ghmeier closed 7 years ago

ghmeier commented 7 years ago

Without this check, componentWillReceive, when used in conjunction with BackboneProvider fails with a type error if the child component is nested and does not have a models prop.

Example: For this component setup,

<BackboneProvider models={{foo}}>
  <Parent>
    <EmptyChild>
      <Child />
    </EmptyChild>
  </Parent>
</BackboneProvider>

If we run

function mapModelsToProps(models) {
  return { foo: models.foo };
}
connectBackboneToReact(mapModelsToProps, { 
  events: { 'foo': 'changed:property' }
})(Child);

And update foo, we trigger the type error.

ghmeier commented 7 years ago

Good call @bradvogel, I added a new test case.

hswolff commented 7 years ago

Update the commit message to follow our conventions and I'll be happy to merge. This should be a fix: prefix as it's a patch release.

ghmeier commented 7 years ago

Thanks @hswolff, I updated the commit message for you.

hswolff commented 7 years ago

Thanks! Published as v1.3.1.