The Better Logic App has a new addition: A library and library management for other apps to consume.
The new Decoder
BLL now has new expression cards, but also a new coding for text arguments within flowcards.
For instance, when you place this within a textargument: Hello, today is {[date("dddd")]}, BLL will automaticly find those expressions within the texts and decode/execute them.
Users currently have access to lodash, mathjs and basic javascript commands.
But also the custom DateTime and Number module.
A user can for instance use this within the Save Image Token flowcard from the FTP Client App.
This image will be saved with the custom timestamp the user writes himself.
Users can also add there own custom functions within the Better Logic App Settings, which they then can use in all Apps, yours too!
NPM modules can be loaded from BLL, which reduces the installation time and size of your App.
Currenty you can load the next NPM’s
math.js 11.3.3
lodash 4.17.21.
Basis for your settings
Currently you can reference to the next files in Settings or (Re)Pair screens:
Add the permission to your app.json "permissions": ["homey:app:net.i-dev.betterlogic"]
Import the BL module in the app.js:. const { BL } = require('betterlogiclibrary');
Initialize the BL in the app.js onInit: await BL.init({homey:this.homey});
There will be no error’s thrown if BLL is not installed or not available, if no modules are used, it is put on silent mode.
Making it not required, but a bonus for users who wish to use BLL coding: If your app supports it, they just need to install BLL (which they already will have i guess).
Decoder
Now, to use the decoder, you do not need any modules loaded. The texts will be decoded by the BLL App, so you do not need to include math.js or lodash into your app to support decoding.
All you need to do, is run the text you wish to decode through the decoder:
Import the BL module. const { BL } = require('betterlogiclibrary');
Use it! Here is an path argument that i want to have decoded: args.path = await BL.decode(args.path);
That’s it!
Including modules
To include modules like lodash, follow these steps:
Include the module(s) in the BL initialization:
let bl = await new BL({
homey:this.homey,
modules:[
"_",
"math",
"datetime"
]});
Now you can use it anywhere: BL._.find BL._.pickBy BL.datetime.toString('dd-MM-yyyy') BL.datetime.toString('dddd') = monday
How does it work?
The BLL loader loads modules through the BLL Api. This massively reduces the app install size.
Only requested modules are loaded and the Static BL is generated.
Every time the BLL get’s an update or is installed, all updated files and modules will be reloaded into your app. Your app doesn’t even need a restart for this!
I have updated the code, i think you will not get any TS errors anymore (i don’t at least )
Yes, i have changed the contructor (removed it) and created a static init method: await BL.init({homey:this.homey, silent:true});
It will still create a BL object, which i need, because the BLL object that manages updates and format/setting changes, is an active object.
Edit:
i might change that if it’s better, but it will not effect the usage: all currently exposed methods are static indeed (for BL at least), so it would not break apps.
Well, yes, Better Logic is now Beter Logic Library.
But it already contained (most of) these Libraries that are now exposed to be consumed by other apps.
The BL app had a size of about 3MB before (App size).
It is now just 3.05MB
Okay, i did update angluarjs, matjs etc. and added a few new libraries and now am using the minified versions.
The NPM betterlogiclibrary is just a small loader which you can use in other apps to:
Decode BLL coding in text-arguments.
Use DateTime Object.
Use custom functions from BLL.
Use Modules for settings, like angularjs and the newest font-awesomes.
Load node modules: Loadash and math.js (already a part of BL).
When an app includes a node module through BLL, The node_modules’ file is read and send as text to the consuming app, where is it build using the normal import constructor.
So it’s pretty memory/size efficient.
Ok, thanks, that explains what ‘happened’ to the app, never looked into it so didn’t even know all these libraries were already in there.
(Apart from lodash it seemed a bit of an overkill to me for what the app did, that’s why I asked)
Well, the Math.js is used in a few flowcards with expressions, but having updated it and more importantly, using the minified version, really saves a lot of space.
When I don’t have BLL installed, I get an error, with BLL installed, it’s fine.
BL.init({homey: this.homey});
console.log("Output: " + await BL.decode("Hello, today is {[date(\"dddd\")]}").catch(this.error));
2023-02-28T20:16:47.959Z [err] [Homey:63c568c5e1c0180b8a2acafe] BL.init Error: Better Logic Library is not installed.
at BL.getAppApi (/app/node_modules/betterlogiclibrary/src/bl.js:344:35)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async BL.init (/app/node_modules/betterlogiclibrary/src/bl.js:200:28)
at async Function.init (/app/node_modules/betterlogiclibrary/src/bl.js:157:9)
[err] [Homey:63c568c5e1c0180b8a2acafe] TypeError: Cannot read properties of undefined (reading 'resolve')
at BL.init (/app/node_modules/betterlogiclibrary/src/bl.js:217:44)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async Function.isInit (/app/node_modules/betterlogiclibrary/src/bl.js:100:9)
at async Function.decode (/app/node_modules/betterlogiclibrary/src/bl.js:40:13)
at async TelegramNotifications.onInit (/app/app.js:56:34)
at async SDK._initApp (/node_modules/@athombv/homey-apps-sdk-v3/lib/SDK.js:249:7)
at async SDK.createClient (/node_modules/@athombv/homey-apps-sdk-v3/lib/SDK.js:131:7)
at async /homey-app-runner/lib/App.js:372:22
at async App.createClient (/homey-app-runner/lib/App.js:416:5)
Output: undefined
Works perfectly with Google Services, also just optional.
I just removed BLL completly, restarted my HP2023 with GS on it, no errors, everything works correctly (only bll coding is not converted ofc, but thats how it’s suppose to be).