amdine
TypeScript icon, indicating that this package has built-in type declarations

1.6.0 • Public • Published

amdine (WIP)

amdine is a dependency resolution for nodeJs.

Why

Import dependencies based on path (require("../whatever"), import a from './foo') is a bad idea, cause is difficult mock. Also, some people don't like classes on javascript. This library try to solve doing resolution based on name, with AMD flavour (not in deep).

How to initialize

import amdine from 'amdine';

// import all your modules that use amdine

amdine.init();

How to use

define function is the core. Use it to define modules.

Signature

define = (factory: Function) => void;
define = (name: string, factoryOrValue: Function) => void;
define = (dependencies: string[], factory: Function) => void;
define = (name: string, dependencies: string[], factory: Function) => void;

Examples:

define('my-object', function(){ return {} as myModule });

define('my-object', {value: 'hello'});

define('my-number', 42);

define('logger', function () {
  return { log: console.log };
});

define('my-task', ['logger'], function (logger) {
  logger.log('hello in task');
});

define('state', function () {
  function createState(){
    const state = {};
    function setState(newState) {
      state = newState;
    }
    return [state, setState];
  }
  return createState;
});

define('my-mod', ['state', 'logger'], function (createState, logger) {
  const [ state, setState ] = createState;
  logger.log(state);
});

For more examples look examples folder

Get module resolved

Following last example:

const state = admine.get('state');
state; // [state, setState]

Readme

Keywords

none

Package Sidebar

Install

npm i amdine

Weekly Downloads

2

Version

1.6.0

License

MIT

Unpacked Size

9.09 kB

Total Files

6

Last publish

Collaborators

  • davidbernal