JSPM

  • Created
  • Published
  • Downloads 21949
  • Score
    100M100P100Q134631F
  • License MIT

A semantic dependency injection framework

Package Exports

  • componentsjs

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (componentsjs) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Components.js

A semantic dependency injection framework

Build Status npm version

This repository contains the source code of Components.js. Full documentation on its usage can be found at http://componentsjs.readthedocs.io/.

Introduction

Components.js is a dependency injection framework for JavaScript applications.

Instead of hard-wiring software components together, Components.js allows these components to be instantiated and wired together declaratively using semantic configuration files. The advantage of these semantic configuration files is that software components can be uniquely and globally identified using URIs.

Configurations can be written in any RDF serialization, such as JSON-LD.

This software is aimed for developers who want to build modular and easily configurable and rewireable JavaScript applications.

Quick Start

Components.js can be installed using npm:

$ [sudo] npm install componentsjs

1. Define your module and its components

my-module.jsonld:

{
  "@context": [
    "https://linkedsoftwaredependencies.org/contexts/components.jsonld",
    { "ex": "http://example.org/" }
  ],
  "@id": "ex:MyModule",
  "@type": "Module",
  "requireName": "my-module",
  "components": [
    {
      "@id": "ex:MyModule/MyComponent",
      "@type": "Class",
      "requireElement": "MyComponent",
      "parameters": [
        { "@id": "ex:MyModule/MyComponent#name", "unique": true }
      ],
      "constructorArguments": [
        { "@id": "ex:MyModule/MyComponent#name" }
      ]
    }
  ]
}

The npm module my-module exports a component with the name MyComponent.

The constructor of MyComponent takes a single name argument.

2. Create a configuration file containing a component instantiation

config-my-component.jsonld:

{
  "@context": [
    "https://linkedsoftwaredependencies.org/contexts/components.jsonld",
    {
      "ex": "http://example.org/",
      "name": "ex:MyModule/MyComponent#name"
    }
  ],
  "@id": "http://example.org/myInstance",
  "@type": "ex:MyModule/MyComponent",
  "name": "John"
}

This configuration is a semantic representation of the instantiation of MyComponent with name set to "John".

3. Instantiate your component programmatically

...
const Loader = require('componentsjs').Loader;

const loader = new Loader();
await loader.registerModuleResourcesUrl('path/or/url/to/my-module.jsonld');
const myComponent = await loader.instantiateFromUrl(
    'http://example.org/myInstance', 'path/or/url/to/config-my-component.jsonld');
...

myComponent is an instance of type MyComponent, as defined in the config file.

License

Components.js is written by Ruben Taelman.

This code is copyrighted by Ghent University – imec and released under the MIT license.