This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

grp.listen init, value
#1
I've found that grp.listen() when when it has last optional param set to true, then it initially runs 2 times: 1) state=="init", 2) state=="value"

I think state=="value" should only run when value change or update on a bus, this is logically separated from "init".
Done is better than perfect
Reply
#2
This is intended behavior. You can ignore init state and/or use a variable to check if this is the first time that callback is called.
Reply
#3
Hi!

Is there any way to use grp.listen() when an object updates but not changes?

I´m doing a emergent notification and many times the message is the same. Object updates but function inside JS doesn´t run.

Code:
grp.listen("33/1/255", function(object,state) {
    if (state == 'value') {
      console.log('Show message')
      setTimeout(function(){
       console.log('Hide Messase')
      }, 4500);
    }
});
Reply
#4
Add a third argument (true) to grp.listen to catch all messages. You also need to clear the timeout on each value update otherwise your function won't work correctly.
Code:
$(function() {
  var timeout;
  grp.listen("33/1/255", function(object,state) {
    if (state == 'value') {
      console.log('Show message');
      clearTimeout(timeout);
      timeout = setTimeout(function(){
       console.log('Hide Messase');
      }, 4500);
    }
  }, true);
});
Reply
#5
(09.12.2020, 09:28)admin Wrote: Add a third argument (true) to grp.listen to catch all messages. You also need to clear the timeout on each value update otherwise your function won't work correctly.
Code:
$(function() {
  var timeout;
  grp.listen("33/1/255", function(object,state) {
    if (state == 'value') {
      console.log('Show message');
      clearTimeout(timeout);
      timeout = setTimeout(function(){
       console.log('Hide Messase');
      }, 4500);
    }
  }, true);
});

Ok Thanks!
Reply


Forum Jump: