Have ideas to improve npm?Join in the discussion! »

This package has been deprecated

Author message:

not used anymore, try object-new

def-module

0.0.1 • Public • Published

def-module

travis-ci codecov

Experimental DSL for module definitions.

$ npm i def-module -S

Containers

By calling def() we are creating definition containers.

const def = require('def-module');
const $ = def();
  • def()— self-contained context
  • def('module')— named module definition on global context
  • def('module', context)— module is defined into the given context
  • def(parent, 'module')— module inherits all definitions from given parent

Shared containers can be achieved by passing the same context.

function container(...args) {
  return def(...args, container);
}

Definitions

Any container, once declared, can be extended through definitions.

$('Base')({
  constructor() {
    console.log('beep', this.value);
  },
  prototype: {
    get value() {
      return 42;
    },
  },
});

The declared functionality is later composed when creating new objects.

const base = $.Base.new();
 
// beep 42

This new() method is very powerful, e.g. $.Base.new(...args, extra)

Inheritance

We can define modules with inherited functionality also.

$($.Base, 'Child')({
  constructor() {
    console.log('boop', this.value);
  },
  prototype: {
    value: -42,
  },
});

Instances are composed from multiple definitions at once, prototypes are always merged and constructors are called in order.

// note that `new` is supported
const o = new $.Child();
 
// beep -42
// boop -42

We don't need to call super() since there is no parent instances.

Nesting

Module definitions can be nested through using key paths.

const home = $('App.controllers.HomeController').new();

Keywords

none

Install

npm i def-module

DownloadsWeekly Downloads

1

Version

0.0.1

License

MIT

Last publish

Collaborators

  • avatar