Commit 9793020
fix: adds check for null model to componentWillReceiveProps (#21)
* fix: adds check for null model to componentWillReceiveProps
There are some cases where a Backbone model passed through CBR
might become undefined. (Consider the case where a view relies on
a secondary model as a "decorator", and the use of that "decorator"
model is toggled on or off.) Today, when a model becomes undefined,
CBR throws a TypeError in ComponentWillReceiveProps:
Uncaught TypeError: Cannot read property 'on' of undefined
This commit adds a check for null or undefined models before trying
to set event listeners in componentWillReceiveProps.
* Removes listeners from models which become undefined
* DRYs removeEventListener code
* Reference model directly in componentWillReceiveProps
* Checks this.context.models for models becoming undefined
Previously, we only checked this.props.models for models becoming
undefined in componentWillReceiveProps. This commit also checks
this.context.models, but only if a matching model was not found in
this.props.models -- because of the Object.assign in setModels,
if there are two models with the same mapKey, we prefer the one
in props.
* Adds test for model becoming undefined in componentWillReceiveProps
* Micro-optimize and clean componentWillReceiveProps
* Refactor undefined model test per review
* Adds testing for initial model listener bindings
* Adds tests: createListener and removeListener are called for decorator model
* Updates test titles and comments per review1 parent 1c1c265 commit 9793020
File tree
2 files changed
+99
-7
lines changed- lib
- test
2 files changed
+99
-7
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
107 | 107 | | |
108 | 108 | | |
109 | 109 | | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
110 | 116 | | |
111 | 117 | | |
112 | 118 | | |
| |||
138 | 144 | | |
139 | 145 | | |
140 | 146 | | |
141 | | - | |
142 | | - | |
143 | | - | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
144 | 165 | | |
145 | 166 | | |
| 167 | + | |
| 168 | + | |
146 | 169 | | |
147 | 170 | | |
148 | 171 | | |
| |||
156 | 179 | | |
157 | 180 | | |
158 | 181 | | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
| 182 | + | |
163 | 183 | | |
164 | 184 | | |
165 | 185 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
594 | 594 | | |
595 | 595 | | |
596 | 596 | | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
597 | 669 | | |
598 | 670 | | |
599 | 671 | | |
| |||
0 commit comments