Micro Components

logo

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 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.

This repository exports 5 independent functionalities:

  1. Micro Components contains the MC and DC classes you can use as super classes.
  2. Elements lets you define and use your own native web components. Uses (1).
  3. (wip) Observables add observability and run time type safety to object properties. Also they provide 1-way binding to placeholders in your template HTML.
  4. (wip) FormValues gives you 2-way binding between a HTML form and an observable object. Uses (3).
  5. (wip) Selectors provide chainable 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>

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:

  • Pure OOP Approach: The system explicitly positions itself as a strict object-oriented alternative to the functional approaches that dominate many modern frameworks.
  • Minimal Interference: The system has minimal DOM interference (only adding _mc attribute and property). This makes it unusually compatible with other frameworks or libraries.
  • Hierarchical Component Traversal: The built-in parent/child/ancestor/descendant traversal methods provide a clean way to navigate component relationships.
  • Direct DOM Integration: Unlike virtual DOM-based frameworks, this approach works directly with the actual DOM while still providing component encapsulation.
  • Outsourcing Potential: Your external coders do not need to access your code repository or your toolchain.

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.