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

Add support of space-delimited list of events #3010

Closed
wants to merge 4 commits into from

Conversation

rise2semi
Copy link

Add support of space-delimited list of events for triggerMethod.
The problem is described in #2937.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.003%) to 99.567% when pulling ee74041 on rise2semi:trigger-method-events into aaa63ae on marionettejs:next.

@@ -173,6 +173,9 @@ All arguments that are passed to the triggerMethod call are passed along to both

`triggerMethod("foo", bar)` will call `onFoo: function(bar){...})`

To trigger several events and corresponding methods split the events by the space. Example:
* `triggerMethod("render ready")` fires the "onRender" ans the "onReady" functions
Copy link
Member

Choose a reason for hiding this comment

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

- ans
+ and

Copy link
Member

Choose a reason for hiding this comment

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

actually can we use triggerMethod('foo bar')? Triggering render manually is probably not a great idea.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.003%) to 99.567% when pulling dfa4f81 on rise2semi:trigger-method-events into aaa63ae on marionettejs:next.

@rise2semi
Copy link
Author

"render" event was chosen just as an example. I've changed the event names to more abstract.
Yes, we can use triggerMethod('foo bar'). You can check it in this jsfiddle (I created a build with my changes).

@ahumphreys87
Copy link
Member

@rise2semi this is great work! Could you please write a test for events bubbling up the view tree? to prove that childEvents can listen for events triggered like this.

@paulfalgout
Copy link
Member

childViewEvents 😂

@paulfalgout
Copy link
Member

Is there any perf concerns here? This is a pretty hot function

@JSteunou
Copy link
Contributor

JSteunou commented Jun 2, 2016

On the map / trigger multiple part I dont see any perf downside, at least no more than manually triggering multiple events at once from the view. Should not be visible.

My concern is more about the 1st test, if it costs a little, it's a little x all the time triggerMethod is called, and I think it is called a lot. How much does cost this line if (eventSplitter.test(events)) { ?

@coveralls
Copy link

Coverage Status

Coverage increased (+0.003%) to 99.503% when pulling 7c141ad on rise2semi:trigger-method-events into 277edbf on marionettejs:next.

@rise2semi
Copy link
Author

rise2semi commented Jun 7, 2016

@paulfalgout I've added tests for childViewEvents.

I'm not sure that there will be performance issue with eventSplitter.test(events), Backbone has the same logic for events and I haven't heard about performance issues in this place.

@paulfalgout paulfalgout added this to the v3.x milestone Aug 2, 2016
@scott-w
Copy link
Member

scott-w commented Sep 16, 2016

Should we look to resolve these conflicts and bring this feature in for 3.1 or (potentially) 3.2?

Copy link

@chchrist chchrist left a comment

Choose a reason for hiding this comment

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

to if or not to if?

export function triggerMethod(events, ...args) {
var result;

if (eventSplitter.test(events)) {

Choose a reason for hiding this comment

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

do we need this if statement? "foo".split(/\s+/) returns an array

// event and call the "onFooBar" method and then trigger the "baz:qux" event
// and call the "onBazQux" method
export function triggerMethod(events, ...args) {
var result;

Choose a reason for hiding this comment

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

why not a const?

@@ -7,20 +7,17 @@ import getOption from './utils/getOption';
// split the event name on the ":"
const splitter = /(^|:)(\w)/gi;

// split the list of events on the space
var eventSplitter = /\s+/;

Choose a reason for hiding this comment

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

const?

@rafde
Copy link
Member

rafde commented Sep 22, 2016

@scott-w I am not a big fan of this implementation. triggerMethod is my 2nd perf woe and I am sure this implementation is going to create a hit in the perf. If I address this, it's pretty much wipes this code out.
I am leaning on closing this and starting over. @marionettejs/marionette-core any objections?

Let me think about how to help this PR move forward a bit.

@scott-w
Copy link
Member

scott-w commented Sep 27, 2016

Fair enough @rafde, I definitely see a lot of triggerMethod stuff happening when I run collection views inside collection views hammering the performance.

@rafde
Copy link
Member

rafde commented Oct 26, 2016

@rise2semi this branch is out of sync at the moment. If you are still interested in helping, please rebase and resolve conflicts.

@paulfalgout
Copy link
Member

closing as it is stale

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.

8 participants