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.

Localbus unlisten
#1
Hello,

I am creating a custom app and am using the localbus script of the LM. Is there a way to unlisten to an object and to remove the callback?
I am using angular as spa framework and DOM is created and destroyed as is best practise. This means listeners should be created and destroyed but currently the callbacks cannot be unsubscribed to.

Please advise.
Reply
#2
Try this:
Code:
localbus.unlistenobject = function(addr, callback) {
  var id = localbus.encodega(addr);
  
  if (id) {
    var callbacks = localbus.listeners.object[ id ];
    
    if (callbacks) {
      var index = callbacks.indexOf(callback);

      if (index >= 0) {
        callbacks.splice(index, 1);
      }
    }
  }
};
Reply
#3
(29.10.2021, 10:19)admin Wrote: Try this:
Code:
localbus.unlistenobject = function(addr, callback) {
  var id = localbus.encodega(addr);
 
  if (id) {
    var callbacks = localbus.listeners.object[ id ];
   
    if (callbacks) {
      var index = callbacks.indexOf(callback);

      if (index >= 0) {
        cbs.splice(index, 1);
      }
    }
  }
};

Yes! Perfect. Thanks.

Is there also a way to wait for the localbus initialization process to finish? It does not return a promise or such so now we do not know when all object states are received and socket is connected...

Thanks again!
Reply
#4
There's a jQuery event triggered on connect/disconnect:
Code:
$(localbus).on('connect', ...);
$(localbus).on('disconnect', ...);
Reply


Forum Jump: