1.0.0 • Published 7 years ago

mami v1.0.0

Weekly downloads
1
License
ISC
Repository
github
Last release
7 years ago

Mami

This is the one who cares about your dependencies.

Example

import mami from 'mami';

const get = mami({
    loadModule: moduleName => import(`./modules/${moduleName}`).then(exports => exports['default']),
    modules: {
        dispatcher: load => load('dispatcher'),
        views: load => load('views'),
        router: load => load('router'),
        app: {
            dispatcher: get => get('dispatcher'),
            views: get => get('views').then(views => views({
                globals: {
                    appName: 'Welcome'
                }
            })),
            router: get => get('router'),
        }
    }
});

get('app').then(app => app.render(document.body));

API

mami(options: Object): Function

Option nameDescription
loadModule: FunctionFunction that load modules. It should return Promise that should return loaded module content.
modules: ObjectKeys of that object is a module name (any word). Values is a object or function that tell mami what dependencies is required.

Returns function that give you ability to get any described module.

const get = mami({
    loadModule,
    modules: {
        a: load => load('my_a')
    }
});
get('a') // returns Promise
    .then(aModuleContent => {
        console.log(aModuleContent);
    })
    .catch(error => console.log(error));