Skip to content

pellebjerkestrand/Overworld

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Overworld

A tiny JavaScript initialization library.

Usage

Create an app.

var app = Overworld.createApp();

Create a module.

var module = Overworld.createModule();

Register modules on the app.

app.register(module);

Apps and modules are initializable. The function passed to onInitialize is run on initialization.

app.onInitialize(function(){
  // Your init code
});

module.onInitialize(function(){
  // Your init code
});

Apps are initialized manually. Modules registered with an app will initialize in the order they were added when app.initialize() is called.

app.initialize();

Something like this is common.

document.addEventListener('DOMContentLoaded', function(){
    app.initialize();
});

Why?

Imagine the code snippets below are in different files. I wanted to be able to do something like this:

(function(window){
    var app = window.app || Overworld.createApp();

    app.onInitialize(function(){
        // App init stuff
    });

    document.addEventListener('DOMContentLoaded', function(){
        app.initialize();
    });

    window.app = app;
})(window, document);
(function(window){
    var app = window.app || Overworld.createApp();

    var mod = Overworld.createModule();

    mod.onInitialize(function(){
        // Module init stuff
    });

    app.register(mod);

    window.app = app;
})(window);
(function(window){
    var app = window.app || Overworld.createApp();

    var mod = Overworld.createModule();

    mod.onInitialize(function(){
        // Module init stuff for another module
    });

    app.register(mod);

    window.app = app;
})(window);

That's why.

About

A tiny JavaScript initialization library

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published