Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bug where resize() isn't called on some widgets
If there were multiple static widgets in the same document, not all would receive resize() calls. Repro case is to create an R Markdown ioslides presentation, and on slide 4 add one leaflet map, and on slide 5 add another one. Only the second one would be rendered properly. Here's an example, see slide 4: https://rawgit.com/ldecicco-USGS/toxEval/master/samplePres.html This was due to me using function-scoped variables inside of a loop that created closures: for (var i = 0; i < bindings.length; i++) { var binding = bindings[i]; var matches = binding.find(document.documentElement); for (var j = 0; j < matches.length; j++) { var el = matches[j]; function resizeHandler() { // do stuff with binding and el } } } The binding and el variables are scoped to the entire function, so all the iterations all share the same variable, and therefore all the resizeHandler closures are bound to the same binding and el values (the final ones). The solution is to change the for-loops into forEach calls, since the callback function into forEach will result in an isolated scope being created for each iteration.
- Loading branch information
1582c46
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if this is related in some way to #102 . Thanks for finding and fixing.