def-module

Module madness!

not used anymore, try object-new
Last updated 4 years ago by pateketrueke .
MIT · Original npm · Tarball · package.json
$ cnpm install def-module 
SYNC missed versions from official npm registry.

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();

Current Tags

  • 0.0.1                                ...           latest (4 years ago)

1 Versions

  • 0.0.1 [deprecated]           ...           4 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (0)
None
Dev Dependencies (4)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |