Skip to content
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

A little clarification. #19

Merged
merged 1 commit into from
Mar 14, 2014
Merged

A little clarification. #19

merged 1 commit into from
Mar 14, 2014

Conversation

braddunbar
Copy link

This resolves my remaining issues with view hooks and I thought it would be easier to discuss here than on the ever growing hooks thread. Comments inline. :)

  • Rename #_remove as #_removeElement.
  • Add #_setAttributes instead of using #setElement.
  • Slim down tests a bit.
  • #delegate returns this.

@@ -1073,15 +1073,15 @@
// Remove this view's element from the document and all event listeners
// attached to it. Exposed for subclasses using an alternative DOM
// manipulation API.
_remove: function() {
_removeElement: function() {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did some grepping and _remove is a fairly popular method name in views already. Also, I think _removeElement is a bit more accurate.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

K good call. I think it was removeElement first, then we were going for parity between the setElement/remove and internal methods.

@@ -1149,6 +1142,7 @@
// `selector` and `listener` are both optional.
undelegate: function(eventName, selector, listener) {
this.$el.off(eventName + '.delegateEvents' + this.cid, selector, listener);
return this;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really not sure about this. Now you can do this:

view.undelegate('click', view.onClick).delegateEvents() // oops redelegated again

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you could just as easily call the two in succession. I'm not overly worried about this though. I'll drop the return.

@wyuenho
Copy link

wyuenho commented Mar 14, 2014

Since we are doing cleanups anyway, can we refactor away this constant '.delegateEvents' + this.cid?

@braddunbar
Copy link
Author

@wyuenho Rebased on #18 and I think I addressed all your comments above. Thanks for the feedback!

@akre54
Copy link
Owner

akre54 commented Mar 14, 2014

@wyueho its not a constant. It's unique per-view. And setting it as a property on the view when its only used twice seems overkill.

@wyuenho
Copy link

wyuenho commented Mar 14, 2014

I meant drying it up :)

Sent from my iPhone

On 14 Mar, 2014, at 11:02 pm, Adam Krebs notifications@github.com wrote:

@wyueho its not a constant. It's unique per-view. And setting it as a property on the view when its only used twice seems overkill.


Reply to this email directly or view it on GitHub.

@akre54
Copy link
Owner

akre54 commented Mar 14, 2014

What do you propose?

strictEqual(view.el.nodeType, 1);

if (Backbone.$) {
ok(view.$el instanceof Backbone.$);
strictEqual(view.$el[0], view.el);
} else {
strictEqual(view.$el, undefined);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

por que no?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already decided elsewhere to leave testing subclasses with Backbone tests out of jashkenas#3003. Just sticking to that.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok cool. This is with the assumption that if you're using View you've got Backbone.$ set, yeah? We can tease out the acceptance tests later then probably.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe pull out the Backbone.$ check then?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure.

@braddunbar
Copy link
Author

@akre54 Updated! Anything else?

@@ -29,18 +29,13 @@
ok(result.length === +result.length);
});

test("jQuery", function() {
test("$el", function() {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe throw a 3 here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely. Thanks!

* Rename #_remove as #_removeElement.
* Add #_setAttributes instead of using #setElement.
* Slim down tests a bit.
* #delegate returns this.
test("remove", 2, function() {
var el = view.el;
test("remove", 1, function() {
var view = new Backbone.View;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how come? Isn't the setup view good enough?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Been trying for a long time to get away from the setup view/collection/model/router/history. Using shared objects tends to cause subtle bugs or change the meaning of other tests unintentionally, especially when it's just as concise to use an isolated instance.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair 'nuff. But noise and all that?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha! This is a brand new test though, right?

akre54 added a commit that referenced this pull request Mar 14, 2014
@akre54 akre54 merged commit 155a738 into akre54:view-native-hooks Mar 14, 2014
@braddunbar braddunbar deleted the view-hooks branch March 14, 2014 16:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants