[APP][Pro] Better Logic Library - For developers

How to include the Better Logic Library?

The Basic

There are just a few simple steps to start with the most basic: include the BLL and initialize it:

  • Add BLL through NPM.
    npm install betterlogiclibrary
  • 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!

1 Like