This code aims at improving Javascript modularity and encapsulation.
Using micro components enforces DRY, KISS and SOLID principles in Javascript programming.
When coding with this system, you create classes that extend either the MC or DC superclasses provided here. These classes provide the structure you need to build your wonderland.
In an almost literal sense they work like childrens building blocks, where a chest full of unassuming parts lets you compose whatever functionality lies in your imagination.
This systems modular approach gives you full control over your software, without the need to rely on other frameworks. On the other hand, its minimalistic stance enables you to use the resulting functionality in any other framework, and makes the learning curve neglectable.
WIP. Should be done soon. In manual testing, also working a lot on the documentation.
This repository exports 5 independent functionalities:
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>
The _mc
attribute indicates that this HTML element contains at least one micro component. This is needed for the selectors.
The _mc
attribute and property are the only interference with the DOM, so any other system should be happy to work with this.
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.
There are a few potentially unique aspects of this micro components system that might differentiate it from other frameworks:
The strongest argument might be for developers who prefer OOP, want minimal framework lock-in, and need a lightweight solution that works well with existing code or other libraries.
Feel free to contact me for any questions or inquiries:
email Frank Thürigen
And again, you can fund this.