-
Notifications
You must be signed in to change notification settings - Fork 0
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
Various clean up and optimizations #5
Conversation
… forgot to clean up
I'm not quite sure what to do with |
view.delegate('click', 'h1', view.increment); | ||
view.delegate('click', view.increment); | ||
view._delegate('click', 'h1', view.increment); | ||
view._delegate('click', view.increment); |
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.
Doesnt this test fail? I'm ok with the new method signature, but I rather like the no second argument form.
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.
Nope test passed.
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.
check it again... the wrong logic branch gets called (it's why I had the _.isFunction
check there)
@wyuenho Ok, so with this pull, the methods a native subview would need to override would be |
Yep. |
Still deciding on |
Also, I don't think |
But let me fix the test first. |
Turns out the 3rd param to |
@akre54 This PR should be good. We can continue the discussion on the ticket once this is merged. |
Nah, I'm not sold on |
I'm warming up to |
remove: function() { | ||
this.$el.remove(); | ||
this.undelegateEvents(); |
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.
This adds an extra call to
I'm in favor of letting the native view be responsible for removing events before deleting the element.
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.
You are right this is slower, but remember this isn't the hot path. The hot path is context creation and event delegation.
Sent from my iPhone
On 20 Feb, 2014, at 9:20 pm, Adam Krebs [email protected] wrote:
In backbone.js:
remove: function() {
this.$el.remove();
This adds an extra call to $.fn.off on the element, and creates a potential slow path. Where previously it wouldn't have to do any mucking in namespaces since it's about to be removed, now it has to do both a slow and fast remove.this.undelegateEvents();
I'm in favor of letting the native view be responsible for removing events before deleting the element.
—
Reply to this email directly or view it on GitHub.
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.
No, but potentially if you're deleting many rows, items, whatever, while creating new ones constantly it will be a hot path. That's what this PR was supposed to address.
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.
Yep. Just trying the find the right balance of abstraction and performance. When that extra function becomes a problem, you can still override remove. But trust me, no matter how you shake it, that one call to parent.removeChild's got to be way faster then jquery to offset the cost. I can run some jsperf later tonight when I get home.
Sent from my iPhone
On 20 Feb, 2014, at 9:28 pm, Adam Krebs [email protected] wrote:
In backbone.js:
remove: function() {
this.$el.remove();
No, but potentially if you're deleting many rows, items, whatever, while creating new ones constantly it will be a hot path. That's what this PR was supposed to address.this.undelegateEvents();
—
Reply to this email directly or view it on GitHub.
The main reason I want |
You sure? You aren't checking selector is '' anymore, you are checking for truthiness. Which is false, which falls to the second branch, in which case selector is actually method, and method is undefined. The test really checks out dude. |
Let me take a look. |
The test is Are you saying we should add back in the |
Just let jQuery deal with it. I just put a comment in. |
So apparently Rivet uses it's own DOM event listen shims, nothing but Stickit seems to be doing event delegation all over again. They can still use Did I miss anything? |
The minified version will mangle an underscore-prefixed method to some shorthand, making it unreliable to hook into. I'd like to create a common interface that any plugin can hook into. And delegate / undelegate seem pretty important. |
Huh? Which minifier are you talking? Uglify doesn't do it. In fact I don't think any sane minifier will do this unless you explicitly give an option (if there's such an option). Remember that the method names are just keys of an object to the compiler. You can't just change the keys arbitrarily without being able to chase down every reference of it, to do that you need to run the program to find out, which you can't do inside a compiler - halting problem. |
Whups, you're right. You have to pass an option. |
Various clean up and optimizations
No description provided.