1.0.0 • Published 7 years ago

core.plugin.core.get_definition_object v1.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
7 years ago

core.getDefinitionObject

Extends core with a function called getDefinitionObject:

core.getDefinitionObject() normalizes the arguments of an instanciating type into an object. this is to allow type constructors to take a list arguments instead of on keyed object. core.getDefinitionObject() will normalize the list of arguments into an object.

core.plugin(
    require('core.plugin.core.get_definition_object')
);

// pass in a number of arguments in order:
var definitionObject = core.getDefinitionObject(
    'SomeModule',          // the name of the module
    ['SomeDependency'],    // dependencies
    (SomeDependency) => {  // get function, will be called when all dependencies have loaded, expected to return the module.

        return {
            doStuff(){ ... }
        };
    },
    'module',   // the core type of this instance
    () => {     // done function, will be called when the instance is ready.
        console.log('SomeModule has loaded')
    }
);

// or pass in a full object ( will be returned as is )
definitionObject = core.getDefinitionObject({
    $_type: 'component',
    name: 'SomeComponent',
    dependencies: ['SomeDependency'],
    get(SomeDependency){

        return {
            render(){ ... }
        };
    },
    done(){
        console.log('SomeComponent loaded')
    }
});

in both cases of the example the result will be the same.

1.0.0

7 years ago