@twobirds/microcomponents 0.0.6 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +63 -32
- package/microcomponents_functional_requirements.md +8 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,12 +2,37 @@
|
|
|
2
2
|
|
|
3
3
|

|
|
4
4
|
|
|
5
|
+
**This code aims at improving Javascript modularity and encapsulation**.
|
|
6
|
+
|
|
7
|
+
Importing a custom MC in your client side code:
|
|
8
|
+
```javascript
|
|
9
|
+
import MyButton from '@mySampleLib/Button';
|
|
10
|
+
```
|
|
11
|
+
... is equivalent to:
|
|
12
|
+
```javascript
|
|
13
|
+
npm i @mySampleLib/Button;
|
|
14
|
+
```
|
|
15
|
+
... on the server side.
|
|
16
|
+
|
|
17
|
+
Imagine mc_modules to like a "node_modules" directory attached to a DOM node (instanceof HTMLElement).
|
|
18
|
+
|
|
19
|
+
**On the client side** MCs reside inside DOM nodes in a "_mc" property, or inside each other recursively. Usually they provide a direct interface to their inner code.
|
|
20
|
+
|
|
21
|
+
**On the server side** MCs can be used to organize your code, too.
|
|
22
|
+
|
|
5
23
|
## Status
|
|
6
|
-
WIP.
|
|
24
|
+
WIP. Micro components should be done soon, as in days.
|
|
7
25
|
|
|
8
|
-
##
|
|
26
|
+
## Disclaimer
|
|
27
|
+
I decided to extract this functionality from the [twoBirds framework](https://www.npmjs.com/package/twobirds-core), since it is framework agnostic, and relies solely on the standard DOM and native javascript or typescript, and is a useful tool in itself. Later this will be backported into twoBirds as a dependency, and twoBirds will become completely modularized on the base of MCs.
|
|
28
|
+
|
|
29
|
+
This is a massive undertaking. MCs are just the foundation of what I do. I am about to **dump** [20+ years of javascript programming](https://gitlab.com/twoBirds/microcomponents/-/blob/main/microcomponents_magic.md?ref_type=heads#things-i-already-did-with-this-in-my-own-framework-twobirds-or-in-apps-that-i-developed-with-it) **into open source libraries**, so feel free to [fund this](https://gofund.me/076c614c). 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 ecosystem for javascript/typescript programming.
|
|
30
|
+
|
|
31
|
+
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.
|
|
32
|
+
|
|
33
|
+
**Established frameworks**, in comparision, **provide a documented interface to a hidden layer of closed source inner functionality**. MCs can be used to **add an interface to components you developed using other frameworks**. So you can still use your existing code, and MCs in it. But you will want to migrate it ASAP, since MCs work with any FW.
|
|
9
34
|
|
|
10
|
-
|
|
35
|
+
## General
|
|
11
36
|
|
|
12
37
|
Using micro components enforces **DRY, KISS and SOLID** principles in Javascript programming. Read this [RFC](https://gitlab.com/twoBirds/microcomponents/-/blob/main/MicroComponentProposal_draft.md?ref_type=heads) for the shortest info, and [click here to see why you may want to use it](https://gitlab.com/twoBirds/microcomponents/-/blob/main/microcomponents_why.md?ref_type=heads).
|
|
13
38
|
|
|
@@ -21,69 +46,75 @@ Or read the more detailed [jsdoc API documentation](http://twobirds.gitlab.io/mi
|
|
|
21
46
|
|
|
22
47
|
To see what can be done, go to [additional concepts](https://gitlab.com/twoBirds/microcomponents/-/blob/main/microcomponents_magic.md?ref_type=heads) which shows what it already has been used for.
|
|
23
48
|
|
|
24
|
-
## Functional Requirements
|
|
25
|
-
|
|
26
|
-
- I want to **enrich a standard HTMLElement instance with encapsuled and modular javascript**, without having to resort to web components or big frameworks.
|
|
27
|
-
- I want to have an **interface** into this functionality that I can both tight and loosely couple.
|
|
28
|
-
- I want to **import and use Micro Components in any framework** that allows for direct DOM access.
|
|
29
|
-
- I want **a single location** in an HTMLElement instance where all this functionality is **stored and sufficiently organized**.
|
|
30
|
-
- I want to be able to use **selectors** to find those instances in the DOM.
|
|
31
|
-
- All this must stricly follow **web standards**.
|
|
32
|
-
|
|
33
|
-
|
|
34
49
|
## Simple Usage:
|
|
35
50
|
|
|
36
51
|
**Micro Components** can be added to to a DOM element like this:
|
|
37
52
|
|
|
38
53
|
before:
|
|
39
54
|
```HTML
|
|
40
|
-
<
|
|
55
|
+
<div></div>
|
|
41
56
|
```
|
|
42
57
|
|
|
43
|
-
code:
|
|
44
|
-
```
|
|
45
|
-
// create
|
|
58
|
+
code:
|
|
59
|
+
```typescript
|
|
60
|
+
// create an inner micro component class
|
|
61
|
+
class MyInnerMC extends MC{
|
|
62
|
+
|
|
63
|
+
constructor( target ){
|
|
64
|
+
super( target );
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
doSomething(){
|
|
68
|
+
console.log( this, 'something done' )
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// create a custom micro component class
|
|
46
73
|
class MyMC extends MC{
|
|
47
74
|
|
|
75
|
+
private myInner: MyInnerMC;
|
|
76
|
+
|
|
48
77
|
constructor( target ){
|
|
49
78
|
super( target );
|
|
50
79
|
this.target = target;
|
|
80
|
+
|
|
81
|
+
//add a private inner micro component
|
|
82
|
+
this.myInner = new MyInnerMC( target );
|
|
83
|
+
|
|
84
|
+
//add a public micro component
|
|
85
|
+
this.add(
|
|
86
|
+
'myPublicInnerMC',
|
|
87
|
+
new MyInnerMC( target )
|
|
88
|
+
);
|
|
51
89
|
}
|
|
52
90
|
}
|
|
53
91
|
|
|
92
|
+
// get some element from the DOM
|
|
54
93
|
const element = document.querySelector('div')
|
|
55
94
|
|
|
56
|
-
// Add the
|
|
57
|
-
let
|
|
95
|
+
// Add the custom micro component instance to the target element
|
|
96
|
+
let topLevelMC = MC.add(
|
|
58
97
|
element,
|
|
59
98
|
'myMC',
|
|
60
99
|
new MyMC( element )
|
|
61
100
|
);
|
|
62
101
|
|
|
63
|
-
// Add an inner (private) microcomponent to mcc
|
|
64
|
-
let mcc.add(
|
|
65
|
-
'myInnerMC',
|
|
66
|
-
new MyMC( element )
|
|
67
|
-
);
|
|
68
|
-
|
|
69
102
|
console.log( element._mc );
|
|
70
|
-
// { 'myMC': { target: (element) } }
|
|
103
|
+
// { 'myMC': { target: (element), _mc: { myPublicInnerMC: {...} } } }
|
|
71
104
|
|
|
72
105
|
console.log( element._mc.myMC );
|
|
73
|
-
// { target: (element) }
|
|
106
|
+
// { target: (element), _mc: { myPublicInnerMC: {...} } }
|
|
74
107
|
|
|
75
|
-
console.log(
|
|
76
|
-
// [ { target: (element) } ]
|
|
108
|
+
console.log( topLevelMC.siblings() );
|
|
109
|
+
// [ { target: (element), _mc: { myPublicInnerMC: {...} } } ]
|
|
77
110
|
```
|
|
78
111
|
|
|
79
112
|
after:
|
|
80
113
|
```HTML
|
|
81
|
-
<
|
|
114
|
+
<div _mc></button>
|
|
82
115
|
```
|
|
83
116
|
_mc indicates that this HTML element contains at least one micro component. This is needed for the **selectors**.
|
|
84
117
|
|
|
85
|
-
I decided to extract this functionality from the [twoBirds framework](https://www.npmjs.com/package/twobirds-core), since it is framework agnostic, and relies solely on the standard DOM and native javascript or typescript, and is a useful tool in itself. Also this will be a dependency in twoBirds then.
|
|
86
|
-
|
|
87
118
|
## Contact
|
|
88
119
|
Feel free to contact me for any questions or inquiries:
|
|
89
120
|
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
## Functional Requirements
|
|
2
|
+
|
|
3
|
+
- I want to **enrich a standard HTMLElement instance or any object with encapsuled and modular javascript**, without having to resort to web components or big frameworks.
|
|
4
|
+
- I want to have an **interface** into this functionality that I can both tight and loosely couple.
|
|
5
|
+
- I want to **import and use Micro Components in any framework** that allows for direct DOM access.
|
|
6
|
+
- I want **a single location** in an HTMLElement instance where all this functionality is **stored and sufficiently organized**.
|
|
7
|
+
- I want to be able to use **selectors** to find those instances in the DOM.
|
|
8
|
+
- All this must stricly follow **web standards**.
|