-
Notifications
You must be signed in to change notification settings - Fork 195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Delete all links/plots using 'update' event #106
Delete all links/plots using 'update' event #106
Conversation
Allow delete all plots/links in the `update` event.
fnRemoveElement(elem); | ||
}); | ||
// Empty plots array | ||
plots.length = 0; |
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.
Why haven't you wrote "plots = {};" for resetting the object ? Is your way faster ?
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.
Good question. I actually did some research because I wasn't sure. Turned out = {}
is not the best way to do it: it will keep any referenced array as is. See this SO answer: http://stackoverflow.com/a/1232046
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.
Hmm, in any case, I think it shouldn't work properly because the variables plots and areas are objects and not arrays, so they shouldn't have the 'length' property.
Moreover, by using this way for resetting an array, I wonder how the garbage collector behaves ?
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.
Oh right, I don't know why I supposed that plots
or links
were array! They are object! I will change it.
For array, setting length to 0 will shrink the array size automatically.
Hello, Thank you for the change, and the explanation :) I merge your PR ! |
…all-links-plots Delete all links/plots using 'update' event
Allows to refresh the entire map (#104)
Usage:
Working JSFiddle : http://jsfiddle.net/q0mdfxvr/2/