-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Adds support for string-based itemEvents #875
Conversation
I put the helper function that allows this directly on Marionette as it seems like something that could be used elsewhere. If I remember correctly it is only used in collection views in the Marionette core, so maybe it'd be better if it went there. |
cv.render(); | ||
}); | ||
|
||
it("should not break", function() { |
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.
Y U So empty?
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 couldn't really think of anything to test, you know? No function exists to test (which is the point), and nothing happens (which is also the point); I just wanted to verify that the code runs and doesn't 'splode. One might think to test that the eventsHash doesn't try to attach the function that doesn't exist, but it seems like that's all handled internally, so there's no way to extract it.
This seems like a significant-enough test for what I was trying to do. If you can think of another way to show this that you think is more substantial, I'd be happy to implement it.
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.
:}
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.
👍 Yea I was confident that was the case, just good to get clarification. Might be worth commenting something along the lines of 'Intentionally left blank' in the test?
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.
That's a good idea, @cobbweb. I added the comment.
Added the comment for that 'empty' test, tidied up some spacing, and removed unused variables in the tests. If either of you see anything else lemme know. |
Fixed it up according to @samccone's suggestions. The function is now |
Update Readme spec 👍 |
Done! |
|
||
// Transform a mapping of events => functions or function names | ||
// and return a mapping of events => functions | ||
Marionette.normalizeMethods = function(hash) { |
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 think we should have some tests for this function directly too? ping @samccone
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.
yeah unit test time (:
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.
Can you add some @jmeas?
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.
Yup. I'll have time tomorrow to get to it, I think. Sorry, should have said something 😄
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.
Sweet!
NPM issues in the build, re-ran = green :) |
Patience, friend! It'll be squashed once it's ready. I haven't added those tests yet. |
heh no worries 👍 |
@cobbweb you should be able to manually trigger a rebuild on travis |
So I'm writing these tests, and (I should have seen this sooner), but the context of the One option is to attach it directly on Another option (maybe better) would be to pass the context as the second argument. I'm leaning more toward the 2nd of these options, but I'd like to know what y'all think. |
There’s a new Marionette.helper in town, and it allows you to specify function names as strings in the itemEvents hash as well as the usual function references. s#Updated docs
All patched up.
✓ |
Is it worth mentioning pull request #790 whilst there is interest in item event bubbling stuff? |
@lukesargeant this is not introducing new bubbling, rather a declarative/extendable method to react to events that are already moving up the view chain. |
Ok, I thought it might be worth a mention as item event bubbling is the more general topic but you're right it's not strictly related to the functionality this offers. |
Makes sense. I'll go ahead and do that. |
Okay, @cobbweb, I updated the source. |
@jmeas great, looks much better than before. |
Sorry for the confusion, I don't think we want the |
Hmm, you're right, @samccone, that in most cases that code above would work, but I'm wondering if relying on the One concern I have is whether or not that method will be changed when Another concern of mine is that relying on If code reduction is a concern one idea would be to separate out the value-searching functionality into a method shared between both |
To summarize what's up with this issue right now: There's currently inconsistency between the structure of the internal methods of Marionette. If consistency is a desirable quality then some of them need to be changed to behave differently. This PR is hung up because there has no been a decision made on which implementation we ought to go with. One option to pass the context/target object of the helper, like Here are two reasons I think converting things to behave like The first is that because they're internal most users shouldn't have to overwrite them or call them directly. If that's true, then it's also true that it's less lines to just pass the context instead of directly attaching it to the prototypes. Further, as the number of internal methods increases the number of Another reason to go with passing the context is that you don't need to decide which methods are attached to each prototype. This Neither of those are incredibly strong reasons that I think passing the context really ought to be the way we go, but they are reasons to sway my opinion in that direction, which is more than I can say for the other option. But I'm sure there are a number of benefits to the other way, as well. |
@jmeas you are really spot on. The best way is to set the context on call, not to pass it in as I previously said. I agree with you that the abstraction is valuable and useful. |
So, wait, maybe I'm confused, but I was suggesting the Do you think otherwise, or did you just make a slip up in typing? :) |
Ah I do think otherwise. By using this pattern Passing the context in via an argument is also a valid way to do this, it is again just inconsistent. As to your argument about polluting the prototype, we are really not polluting it per say, rather just storing a reference to the util method with the correct context maintained (but true we are adding a key onto it). So your points are valid, however instead of breaking from the way we are doing it in this project let's just stick with the pattern in place. |
I wasn't really worried about pollution, but rather just than just having lots of @cobbweb, thoughts? |
👍 excited for this! |
I'm fine with either way, but prefer calling the function in the right context versus passing an argument. |
Alright, cool. It sounds like you and @samccone agree, and I don't feel too strongly either way, and that's what this PR is currently doing. If there's anything else you want me to change, let me know, but it looks good to me. 👍 |
@@ -18,6 +18,7 @@ Marionette.Module = function(moduleName, app, options){ | |||
this.startWithParent = true; | |||
|
|||
this.triggerMethod = Marionette.triggerMethod; | |||
this.normalizeMethods = Marionette.normalizeMethods; |
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 need for this to be here right now right?
Ah, right, @samccone. I've removed the new function from every prototype except for |
Will this work for namespaced events like |
Yessir |
eventOne: "someFn", // This will become a reference to `this.someFn` | ||
eventTwo: this.someOtherFn | ||
}; | ||
this.normalizedHash = Marionette.normalizeMethods(hash); |
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.
Should this line be either this.normalizeMethods(hash)
? Can you add that normalizeMethods
is already added to Marionette.View but has to be added by the user if they want to use it in non-view classes?
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 catch, it does need to be this.normalizeMethods(hash)
Good catch, @cobbweb. Updated! 👍 |
YOU EVER GONNA MERGE THIS, @samccone? |
ha 💃 it is on https://github.com/marionettejs/backbone.marionette/tree/dev going to run it through a few apps |
merged in dev and into master |
There’s a new Marionette.helper in town, and it allows you to specify
function names as strings in the itemEvents hash as well as the usual
function references.
Fixes #872