Ticket #1189 (closed feature: fixed)

Opened 5 years ago

Last modified 5 years ago

allow triggerEvent to be called with additional arguments for the listener

Reported by: tschaub Owned by: euzuro
Priority: minor Milestone: 2.6 Release
Component: Events Version: 2.5
Keywords: Cc:
State:

Description

Our triggerEvent method just calls all listeners (optionally bound to some caller). This can be modified easily to call listeners with additional arguments. This makes event stuff more fun.

Pretend a drag feature control wanted to trigger a "predragfeature" event on a layer. Listeners should expect to receive the feature in question and perhaps the start and end pixel (of the drag). In addition, if triggerEvent returns the return from the last listener, then that control can modify its behavior (undo the drag for example) if the arguments (start and end pixel in this case) don't meet some user specified criteria.

Just a mocked up example, but this would give us way more flexibility with our event magic. Basically, I'm asking for triggerEvent to take an optional third argument and return continueChain.

Attachments

trigger.patch Download (5.2 KB) - added by tschaub 5 years ago.
send listeners arguments and respect their returns

Change History

  Changed 5 years ago by pgiraud

I'm totally in favour with this feature. ExtJS behaves in a similar way and it's quite useful.

Changed 5 years ago by tschaub

send listeners arguments and respect their returns

  Changed 5 years ago by tschaub

  • keywords review added

Ok, now with tests. And they pass (in FF).

Please review.

follow-up: ↓ 4   Changed 5 years ago by crschmidt

Can you explain the change from callback.func.call to callback.func.apply? I'm not used to 'call', and I don't get the meanining.

in reply to: ↑ 3   Changed 5 years ago by elemoine

Replying to crschmidt:

Can you explain the change from callback.func.call to callback.func.apply? I'm not used to 'call', and I don't get the meanining.

You pass apply an array of arguments, while you pass call the arguments directly.

< http://blog.metawrap.com/blog/TheVeryUsefulJavaScriptCallAndApplyFunctionsForOverridingThisForAGivenFunction.aspx>

  Changed 5 years ago by tschaub

yeah - call if you have references to all of the arguments, apply otherwise

  Changed 5 years ago by crschmidt

I'm fine with this if tests pass in IE.

  Changed 5 years ago by tschaub

Yes, tests pass in IE. I will note however that while tests pass in IE, the IE debugger complains about the vector layer tests (without this patch as well). That is, tests "pass" as before in IE.

  Changed 5 years ago by pgiraud

  • keywords commit added; review removed

We should be able to commit this since the tests pass for layer_vector in IE.

  Changed 5 years ago by tschaub

  • keywords commit removed
  • status changed from new to closed
  • resolution set to fixed

(In [5398]) triggerEvent can now be called with additional arguments for the listeners - this means instead of getting news like 'hey, someone won the lottery' listeners now get news like 'hey, you won the lottery' - in addition, the triggerer gets back the return from the listener, so if a listener wants to say 'dont tell anyone else' the triggerer gets that message - thanks for the reviews (closes #1189)

Note: See TracTickets for help on using tickets.