Skip to content

Commit 469073c

Browse files
Garret Meierhswolff
authored andcommitted
fix: Add models existence check on props update
1 parent 247e8dd commit 469073c

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

lib/connect-backbone-to-react.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ module.exports = function connectBackboneToReact(
119119
// Bind event listeners for each model that changed.
120120
Object.keys(this.models).forEach(mapKey => {
121121
const model = this.models[mapKey];
122-
if (this.props.models[mapKey] === this.models[mapKey] ||
122+
if ((this.props.models && this.props.models[mapKey] === this.models[mapKey]) ||
123123
(this.context.models && this.context.models[mapKey] === this.models[mapKey])) {
124124
return; // Did not change.
125125
}

test/backbone-provider.test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,5 +98,12 @@ describe('BackboneProvider', function() {
9898
wrapper.find('.name').everyWhere(n => n.text() === 'Harry')
9999
);
100100
});
101+
102+
it('should handle updates to passed props', function() {
103+
const model = new Model({ name: 'Jill' });
104+
wrapper.setProps({ models: { user: model }});
105+
106+
wrapper.find('.name').everyWhere(n => n.text() === 'Jill');
107+
});
101108
});
102109
});

0 commit comments

Comments
 (0)