-
Notifications
You must be signed in to change notification settings - Fork 616
How to Component at DemocracyOS
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.
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 withinmodule-name
. - A
module.exports
clause insideindex.js
file exporting modules functionality.
Examples are:
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
withincomponent-name
with keys:name
,description
,dependencies
(if any),local
dependencies (if any),scripts
, andmain
. - An
index.js
file withincomponent-name
listed inscripts
and added asmain
too incomponent.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:
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:
Visit our official website - Developed by Democracia en Red and contributors from the world over!