2.2.0-0 โข Published 7 months ago
@web-companions/gfc v2.2.0-0
Generator Functional Components. A wrapper for creating Web components with JS Generator function
Features
- ๐ Fast: Built with standards based Custom Elements and JS Generator.
- ๐ช Typed: Written in TypeScript.
- โ๏ธ JSX: Can be used with JSX or without it (babel-plugin-transform-jsx-to-tt).
- ๐ชข Flexible: Fit to different template libraries.
- ๐งน No dependencies
Table of contents
Installation
npm install @web-companions/gfc --save
Usage
For the best DX I suggest using this library with babel-plugin-transform-jsx-to-tt and lit-html or another library to rendering templates to DOM.
index.jsx
import { EG, p } from '@web-companions/gfc';
import { render } from 'lit-html';
/**
* Counter element
*/
export const counterElement = EG({
props: {
msg: p.req<string>(),
},
})(function* (props) {
let count = 0;
while (true) {
props = yield render(
<>
<button
type="button"
onclick={() => {
count++;
this.next();
}}
>
{props?.msg}
</button>
<i>{count}</i>
</>,
this
);
}
});
// define a new custom Counter element with tag 'demo-counter-element'
const CounterElement = counterElement('demo-counter-element');
/**
* ROOT element
*/
EG({
props: {
header: p.req<string>('header'),
},
})(function* (props) {
while (true) {
props = yield render(
<div
style={css`
margin: 10px;
`}
>
<h3>{props.header}</h3>
<CounterElement msg={'Counter Element'}></CounterElement>
</div>,
this
);
}
})('demo-fc');
More examples are here.
Notice
Node view
- This type of view could be created only inside an Element view.
- If some of Node view will be rendered by a condition we should create them with prepared ref objects. Otherwise, some of Nodes can start to use the same inner state.
License
2.1.6
8 months ago
2.1.5
8 months ago
2.2.0-0
7 months ago
2.1.0-develop.1
1 year ago
2.1.0-develop.0
1 year ago
2.1.2
12 months ago
2.1.1
1 year ago
2.1.4
11 months ago
2.1.3
11 months ago
2.1.0
1 year ago
1.2.0
2 years ago
1.1.1
2 years ago
1.1.1-develop.0
2 years ago
2.0.3
2 years ago
2.0.2
2 years ago
2.0.0-develop.2
2 years ago
2.0.0-develop.0
2 years ago
2.0.0-develop.1
2 years ago
2.0.1
2 years ago
2.0.0
2 years ago
1.2.0-develop.0
2 years ago
1.3.0-develop.0
2 years ago
1.1.0
2 years ago
1.1.0-develop.2
2 years ago
1.0.2
2 years ago
1.0.1
2 years ago
1.1.0-develop.1
2 years ago
1.0.0
2 years ago
1.1.0-develop.0
2 years ago
1.0.0-0
2 years ago
0.0.1
3 years ago
0.0.2
3 years ago
0.0.1-develop.4
3 years ago
0.0.1-develop.2
3 years ago
0.0.1-develop.3
3 years ago
0.0.1-develop.1
3 years ago
0.0.1-develop.0
3 years ago