0.18.0 • Published 4 years ago

blocnode v0.18.0

Weekly downloads
3
License
MIT
Repository
github
Last release
4 years ago

Blocnode

Blocnode is a little library constructor that help dev to organise there code in a namespaced library.

The idea is to have a full namespace in our application and make loading module very simple. In other way it's also possible to use the module in a standalone mode with the proper code.

Creating the namespace

// Creating the bloc
let Library = new Blocnode();
// Creating a class to include
class MyClass {}
// Include the class
Library.namespace('My.Test.Path').MyClass = MyClass;

Creating a module

In FileOne.js :

/**
 * When creating a module, be sure to have the library in parameter.
 * An empty lib or an instance already declared
 */
module.exports = (function(Library = new (require('blocnode'))()) {
    // Creating a class to include
    class MyClass {}
    // Include the class
    Library.namespace('My.Test.Path').MyClass = MyClass;
    // Creating a value like constant or variable
    const MyConstant = "My Beautifull CONST";
    // Include the value
    Library.namespace('My.Test.Path').MyConst = MyConstant;
 
    return Library;
});

In index.js

// Creating the new Library and including the modules in it.
let Blocnode = new (require('blocnode'))([
    './FileOne.js',
    'my-node-module-npm-name'
]);

// expecting : My Beautifull CONST
console.log(Blocnode.My.Test.Path.MyConst);

In standalone

If you just want to use your module in stand alone mode, you can use it like this :

In standalone.js

// Creating the new Library and including the modules in it.
let MyModule = (require('./FileOne.js'))();
// expecting : My Beautifull CONST
console.log(MyModule.My.Test.Path.MyConst);

Note:

When creating a module, because module are loaded one by one, if you call a module not loaded, inside in the private's module context, you will have undefined error.

Use the private's module context to set it up or make operation that don't need the Library.

/**
 * When creating a module, be sure to have the library in parameter.
 * An empty lib or an instance already declared
 */
module.exports = (function(Library = new (require('blocnode'))()) {
    /**
     * Here is the private context, the entire Library is not loaded
     */
    console.log(Library.My.Not.Loaded.Module);

    class MyClass {
       constructor() {
           /**
            * Here the context of MyClass. When you instanciate it,
            * all module are loaded, so you can use the entire Library
            */
           console.log(Library.My.Loaded.Module);
       }
    }

    Library.namespace('My.Test.Path').MyClass = MyClass;

    return Library;
});
0.18.0

4 years ago

0.17.1

4 years ago

0.17.0

4 years ago

0.16.5

4 years ago

0.16.3

4 years ago

0.16.4

4 years ago

0.15.5

4 years ago

0.15.0

4 years ago

0.16.0

4 years ago

0.15.1

4 years ago

0.16.1

4 years ago

0.14.2

5 years ago

0.14.1

5 years ago

0.14.0

6 years ago

0.13.1

6 years ago

0.13.0

6 years ago

0.1.3

6 years ago

0.1.21

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago

0.0.2

6 years ago

0.0.16

6 years ago

0.0.15

6 years ago

0.0.142

6 years ago

0.0.141

6 years ago

0.0.14

6 years ago

0.0.13

6 years ago

0.0.12

6 years ago

0.0.11

6 years ago

0.0.9

6 years ago

0.0.8

6 years ago

0.0.7

6 years ago

0.0.6

6 years ago