1.6.0 • Published 2 years ago

amdine v1.6.0

Weekly downloads
2
License
MIT
Repository
-
Last release
2 years ago

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]
1.6.0

2 years ago

1.5.1

2 years ago

1.5.0

2 years ago

1.2.0

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

1.4.0

2 years ago

1.3.0

2 years ago

0.1.0

3 years ago