Private methods in a module, and modules in BangleApps #6368
Replies: 1 comment
-
Posted at 2020-12-08 by @gfwilliams Could you give me an example of what's not working that you expect? I just tried and this works...
But one thing I can see is you've got:
But Posted at 2020-12-08 by OmegaRogue that works, thanks! But do I need to make the Corner draw functions into public methods or is there some way to make them into private methods? Posted at 2020-12-08 by @gfwilliams You could pass in the constants, if that is what you need?
Posted at 2020-12-08 by OmegaRogue It's not the most elegant way, because i need to pass in the entire object because both constants and variables are required, but it works
Posted at 2020-12-09 by @gfwilliams Great! You could always keep using
But IMO that's maybe even a bit less tidy than just passing it in as an argument Posted at 2020-12-09 by OmegaRogue Would it be possible to use JavaScript classes in modules? Because then I could use actual private methods, and IMO that would be more elegant than using a constructor function with prototype methods and constants Posted at 2020-12-09 by @gfwilliams You could use JS classes I believe but that doesn't help you - private fields are still only a JS proposal and not part of standard JS or implemented in Espruino: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/Private_class_fields Posted at 2020-12-09 by OmegaRogue i could of course just make the functions into public methods, but they aren't that useful outside of the module itself Posted at 2020-12-09 by @gfwilliams Keeping them private would allow minification, which would be a big bonus. Do you need separate functions for each corner? being able to bring them into one function would probably increase the execution speed a lot. Also, not sure if this helps but:
Posted at 2020-12-09 by OmegaRogue I can just do two small fillRects for it, and I can bring them into one function:
but that seems a bit redundant, because depending on the corner position the operations are different Posted at 2020-12-09 by OmegaRogue one possible solution to that would be to use scaled, floored sine functions to get the correct signs, but i don't know if that would be faster or slower Posted at 2020-12-09 by @gfwilliams I just meant whether you just needed it at all, or could roll it all into Do you have a need to draw individual corners on their own? Posted at 2020-12-09 by OmegaRogue yes, because only some corners are needed for the frames with corners only on one side Posted at 2020-12-09 by OmegaRogue either way, this is definetly shorter:
Posted at 2020-12-09 by @gfwilliams Good plan - I'm not sure s1 gets set up? You could actually do:
and remove the whole I've just updated the app loader to allow local modules for you: https://github.com/espruino/BangleApps#modules So add the module in Posted at 2020-12-09 by OmegaRogue I don't know if it's just a problem with my fork of the app loader often only updating partly after a new deployment, but my apps are still not uploading to my bangle now with the module Posted at 2020-12-09 by OmegaRogue at least not the launcher Posted at 2020-12-09 by OmegaRogue and the watchface is uploading, but after that the bangle is stuck at searching for gps time Posted at 2020-12-10 by @gfwilliams Maybe start up the Chrome Debug Console, right-click on the normal page refresh icon, and choose If that doesn't work, maybe you could post up what's shown by the debug console when you try to upload your app and maybe what error the Web IDE gives when you connect to the Bangle and long-press BTN3 to reload the app? Also if you had a link to your app loader online then I could try it here Posted at 2020-12-10 by OmegaRogue https://gist.github.com/OmegaRogue/0beda87a1a80dccb3bc4e8d8c84b70cb Posted at 2020-12-10 by @gfwilliams Ahh - so yeah, what's happened is the
But on yours it looks like:
Posted at 2020-12-10 by OmegaRogue how do I get it to update the core submodule? Posted at 2020-12-10 by OmegaRogue this is my current folder structure (.git and .idea folders are hidden) Posted at 2020-12-10 by @gfwilliams
Posted at 2020-12-10 by OmegaRogue That didn't work, but i got it to work locally by changing into the core directory, checking out the master branch and then pulling, but I haven't been able to get it to update on GitHub Posted at 2020-12-10 by @gfwilliams If you:
That might do it - there must be a bunch of stuff online about this though Posted at 2020-12-10 by OmegaRogue that does nothing |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2020-12-08 by OmegaRogue
I'm trying to write a module for shared code between my BangleJs Apps.
According to the tutorial, everything should be working at this Point.
I required the module with the GitHub URL to it and it downloads, but when i create the object that should have all public functions and constants, it only has the variables that were set in the constructor.
Am I doing something wrong or is the tutorial not working?
Here is the module: https://github.com/OmegaVoid/EspruinoDocs/blob/master/modules/dane_arwes.js
Beta Was this translation helpful? Give feedback.
All reactions