You are reading a single comment by @Gordon and its replies. Click here to read the full conversation.
  • We actually do this in other places (I think in bthrm) and it works fine.

    The issue in your case is that A.on and B.on are the same function. The difference is the object they are called on. So your call to AUTOSWP2CLK.on adds an event listener, but to AUTOSWP2CLK, not to Bangle.

    You could use AUTOSWP2CLK.on.call(Bangle, eventName, func) instead and it should work though

  • Thanks for pointing out bthrm. (It's not a thing I personally use, so I never thought to check it out.) It does seem to have the same goal (modifying Bangle.on), but it goes about it in a different way. bthrm uses Bangle.origOn, and my own app uses AUTOSWP2CLK.on. I think both approaches have some advantages and disadvantages. With bthrm's approach, we don't create confusion about which object is getting an event listener and we don't need to use .call to force the event listener to be assigned to something it wouldn't normally be assigned to. (We clearly do have that issue with my approach.) However, my approach is less likely to create naming conflicts with other boot code, because it seems far more likely to me that another app will want to create an object called Bangle.origOn than an object called AUTOSWP2CLK.

    I went for a combination of the two approaches: create more children of Bangle rather than a top level object, but call them something like AUTOSWP2CLKORIG rather than just orig. This works as expected.

    Is there a proper convention for names of objects created by boot code, or am I too paranoid about naming conflicts? I feel like they should have the name of the app somewhere in there to allow different pieces of boot code to distinguish variables from each other, and also have some way to distinguish boot code variables from the main app's variables. Like maybe have boot code objects be named BOOT, and have the main apps avoid creating objects with names starting with BOOT_ which I don't think they'd really have any reason to anyways?

    TLDR: Thanks, that fixed it.

About

Avatar for Gordon @Gordon started