Logic Machine Forum
Localbus unlisten - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Localbus unlisten (/showthread.php?tid=3653)



Localbus unlisten - Smeagol - 29.10.2021

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.


RE: Localbus unlisten - admin - 29.10.2021

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);
      }
    }
  }
};



RE: Localbus unlisten - Smeagol - 30.10.2021

(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!


RE: Localbus unlisten - admin - 01.11.2021

There's a jQuery event triggered on connect/disconnect:
Code:
$(localbus).on('connect', ...);
$(localbus).on('disconnect', ...);