Latest Threat ResearchGlassWorm Loader Hits Open VSX via Developer Account Compromise.Details
Socket
Book a DemoInstallSign in
Socket

entwine

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

entwine

Immutable Dependency Injection

latest
Source
npmnpm
Version
0.1.0
Version published
Maintainers
1
Created
Source

Entwine

Entwine

Immutable dependency injection in Node.js inspired (very) heavily by Component.

Installation

npm install --save entwine

Usage

let entwine = require('entwine');

//
// Database component
//

class Database extends entwine.component({config: {}, conn: nul}) {
  start() {
    let self = this;

    return connectToDatabase(this.config).then(conn => self.set('conn', conn));
  }

  stop() {
    let self = this;

    return disconnectFromDatabase(this.conn).then(() => self.remove('conn'));
  }
}

function database(config) {
  return new Database({config: config});
}

//
// Server component
//

class Server extends entwine.component({config: {}, socket: null, database: null}) {
  start() {
    let self = this;

    return listenOnPort(this.config).then(socket => self.set('socket', socket));
  }

  stop() {
    let self = this;

    return unlistenOnPort(this.config).then(() => self.remove('socket'));
  }
}

function server(config) {
  return new Server({config: config});
}

//
// System
//

entwine.system({
  server: server(serverConfig),
  database: database(databaseConfig)
},{
  server: ['database']
}).start().then(s => {
  console.log('system started');
  return s.stop();
}).then(() => {
  console.log('system stopped');
});

Keywords

cucumber

FAQs

Package last updated on 09 Dec 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts