Micro Components

Micro Components Logo

This code aims at improving Javascript modularity and encapsulation.

Using micro components enforces DRY, KISS and SOLID principles in Javascript programming.

WIP. Should be done soon. In manual testing, also working a lot on the documentation.

I decided to extract this functionality from the twoBirds framework, because it is a useful tool in itself and it is framework agnostic. It relies solely on the standard DOM and native javascript or typescript.

Later this will be backported into twoBirds as a dependency, and twoBirds will become completely modularized on the base of MCs.

This is a massive undertaking. MCs are just the foundation of what I do. I am about to dump 20+ years of javascript programming into open source libraries, so feel free to fund this. The better this is funded, the faster it will be done. Given enough resources, I will start a crowdfunded company that will develop a new open source ecosystem for javascript/typescript programming. By "Open Source" I mean really free and open, as you get all my inner source code with it. Once you understand the Micro Component principle, you are back in command of your software, no matter what MC functionality you import in your system. Since Micro Components are encapsuled, off-shoring and near-shoring is no problem, and reusability is guaranteed. Your external coders do not need to access your code repository or your toolchain. They only need to understand MCs.

This is a low-level OOP approach to Javascript programming.

It aims at proving that strict OOP is a valid alternative to other frameworks functional approaches.

You can use it in vanilla JS or Typescript coding environments. It has been used to create very complex single page applications.

Also you can use it in any other framework to enhance it with missing functionality.

This functionality is portable, so you can reuse your MCs - e.g. originally written in the context of an Angular project - in your next react project right away.

In its core it consists of a two classes named MC and DC. Your class code extends from one of these classes.

This repository exports 5 independent functionalities:

  1. Micro Components contains the MC and DC classes you can use as super classes.
  2. Custom Elements lets you define and retrieve your own custom elements based on your DC instance code. Uses and re-exports (1).
  3. Convenience Observables adds observability and run time type safety to object properties.
  4. Form Values gives you 2-way binding between a HTML form and an observable.
  5. (tbd) Convenience Selectors provide jQuery like selectors for both the DOM and micro components.

Also there is a bundle file that contains all of the above.

Check the typedoc API reference if you want to drill into the source code.

To see what can be done, go to additional concepts which shows what it already has been used for.

Micro Components can be added to to a DOM element like this:

before:

<div></div>

code:

// create a custom micro component class
class MyMC extends DC{

constructor( target ){
super( target );
}

helloWorld(){
console.log( 'Hello World' );
}

}

// get some element from the DOM
const element = document.querySelector('div')

// Add the custom micro component instance to the target element
DC.add(
element,
'myMC',
new MyMC( element )
);

// Hello World
element
._mc
.myMC
.helloWorld();

after:

<div _mc></div>

_mc indicates that this HTML element contains at least one micro component. This is needed for the selectors.

The _mc attribute and properties are the only interference with the DOM, so every other system should be happy to work with this.

Feel free to contact me for any questions or inquiries:

email Frank Thürigen

And again, you can fund this.