Thorin libraries

In a Thorin app, libraries are those bits of code that can be reused in various parts of the application, such as a payment gateway or a communication layer between other services. If you find yourself writing the same code twice, consider moving it to a library and call your functions from there.

Since libraries can come in various sizes and forms, Thorin is quite open when registering your libraries in your app. You can use classes, objects or prototypes try following the pattern below.

thorin.addLibrary(module, name)
Registers the given library module inside the thorin app, so that it can be accessible via thorin.lib(name) from anywhere inside your application.
  • modulestring | function the library module to register (see below use cases)
  • namestring the name of the library
Ways to call:
  • thorin.addLibrary(module=string) // will use require(module) and use its name property
  • thorin.addLibrary(module=string, name=string) // will use require(module) and use the given name
  • thorin.addLibrary(module=function) // will use the given function, prototype or class and use its name property
  • thorin.addLibrary(module=function, name=string) // will use the given function, prototype or class and use the given name
'use strict'
// Option 1
class MyLib {
   doSomething() {}
thorin.addLibrary(MyLib, 'libName');
// Option 2
const libOne = {
   doSomething: () => {}
thorin.addLibrary(libOne, 'libOne');

// Option 3
const libTwo = function myLib() {} = 'libTwo';

// Option 4
const libThree = function myLibThree() {}
thorin.addLibrary(libThree);  // use the function's name as the fallback.
Do you have a question or is something missing?

You can always create a new issue on GitHub or contact one of the core founders by chat.