Can you use dojo on.once() with map::update-end event?

1903
5
Jump to solution
01-31-2017 11:56 AM
JerryGarcia
Occasional Contributor II

If so, can someone provide example code?

Thanks!

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Jerry,

   I use dojo on.once quit often in code.

on.once(map, "update-end", function(){
    // will only fire once...
});‍‍‍

View solution in original post

5 Replies
thejuskambi
Occasional Contributor III

Hello Jerry,

I am not able to understand the objective of a example. on.once is a method in dojo, used to listen to an event only once. it would be similar to code below.

var handle = on(map, "click", function(evt){
   ...
   handle.remove();
}

It does not matter, which event. you can use on.once on any event, which you would like to listen just once.

JerryGarcia
Occasional Contributor II

Thanks.  But, it is not always that simple...    I want my code to fire only once. I have a couple callbacks when the event occurs.  So...  I need to wait until the callbacks are finished or, I was thinking, use the nifty on.once dojo functionality.  I'm still not clear how to invoke it's magic.  

None of the following works:

on.once(...);

on(...).once();

handle.once();

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Jerry,

   I use dojo on.once quit often in code.

on.once(map, "update-end", function(){
    // will only fire once...
});‍‍‍
by Anonymous User
Not applicable

This works as long as the dojo.on module is called first, like so:

require(["dojo/on"],
function(on) {
on.once(map, "update-end", function(){
    // will only fire once...
});
});

Thanks for this great tip!

JerryGarcia
Occasional Contributor II

I see.  Pretty simple.  Thanks!

0 Kudos