Skip to content

How to Component at DemocracyOS

Rod Wilhelmy edited this page Mar 20, 2014 · 2 revisions

A component is basically a piece of code that is reusable and / or detachable. Intentionally, all developed components are initially coupled to the main application. Any component that is detachable will, in time, be decoupled from DemocracyOS and developed in parallel.

To sum up, a component is anything from class definition to a lib built on top of a bunch of classes, a simple function helper or an asset or even a collection of assets, and more...

There are three types of components at DemocracyOS:

  • Those intended to work for server only.
  • Those intended to work for client only.
  • Those intended to work for both server and client.

Components for server only

Server side components are also called node modules since all backend at DemocracyOS runs in NodeJS.

The minimum structure a module must have is:

  • A module-name folder inside /lib directory.
  • An index.js file within module-name.
  • A module.exports clause inside index.js file exporting modules functionality.

Examples are:

Components for client only

Client side components are developed with Component. Their structure is explained in the provided source wiki.

The minimum structure a component must have is:

  • A component-name folder inside /lib directory.
  • A component.json within component-name with keys: name, description, dependencies (if any), local dependencies (if any), scripts, and main.
  • An index.js file within component-name listed in scripts and added as main too in component.json.

The best, simpler and complete way to do the above is installing Component(1) and running

$ cd lib
$ component create component-name
$ cd component-name
$ ls
    .gitignore
    History.md
    Makefile
    Readme.md
    component.json
    index.js

Which will also create .gitignore, Makefile, and History.md files.

Examples are:

Components for both server and client

The use of components for both the client and server meet the only requirement of having an index.js in combination of a descriptor file component.json naming as its main script the same index.js used on the server. The key with this type of components is to have common code written once and shared without restrictions.

Examples of this are: