Skip to content

Commit 55ba029

Browse files
committed
Update readme
1 parent 8b4a9c3 commit 55ba029

1 file changed

Lines changed: 27 additions & 103 deletions

File tree

readme.md

Lines changed: 27 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1,124 +1,48 @@
11
<div align="center">
2-
<h1>💎 Unyielding</h1>
3-
<a href="https://bundlephobia.com/result?p=unyielding">
4-
<img src="https://badgen.net/bundlephobia/minzip/unyielding@0.1.1" alt="minified and gzipped size">
5-
<img src="https://badgen.net/bundlephobia/min/unyielding@0.1.1" alt="minified size">
6-
<img src="https://badgen.net/bundlephobia/dependency-count/unyielding@0.1.1" alt="zero dependencies">
2+
<h1>👑 ⚙️ Yield Machine</h1>
3+
<a href="https://bundlephobia.com/result?p=yieldmachine">
4+
<img src="https://badgen.net/bundlephobia/minzip/yieldmachine@0.1.0" alt="minified and gzipped size">
5+
<img src="https://badgen.net/bundlephobia/min/yieldmachine@0.1.0" alt="minified size">
6+
<img src="https://badgen.net/bundlephobia/dependency-count/yieldmachine@0.1.0" alt="zero dependencies">
77
</a>
88
</div>
99

10-
Lightweight Components using Generator Functions
10+
State Machines using Generator Functions
1111

1212
## Install
1313

1414
```console
15-
npm add unyielding
15+
npm add yieldmachine
1616
```
1717

1818
## Examples
1919

20-
### Components
21-
2220
```javascript
23-
import { html, renderToString } from "unyielding";
24-
25-
function* NavLink(link) {
26-
yield html`<li>`;
27-
yield html`<a href="${link.url}">`;
28-
yield link.title;
29-
yield html`</a>`;
30-
yield html`<li>`;
31-
}
21+
import { call, on, start } from "yieldmachine";
3222

33-
function* Nav(links) {
34-
yield html`<nav aria-label="Primary">`;
35-
yield html`<ul>`;
36-
37-
for (const link of links) {
38-
yield NavLink(link);
23+
function Loader({ url }: { url: URL }) {
24+
function* idle() {
25+
yield on("FETCH", loading);
3926
}
40-
41-
yield html`</ul>`;
42-
yield html`</nav>`;
43-
}
44-
45-
function* PrimaryNav() {
46-
yield Nav([
47-
{ url: '/', title: 'Home' },
48-
{ url: '/pricing', title: 'Pricing' },
49-
{ url: '/features', title: 'Features' },
50-
{ url: '/terms', title: 'Terms & Conditions' },
51-
]);
52-
}
53-
54-
const html = await renderToString([PrimaryNav()]);
55-
```
56-
57-
### Attributes
58-
59-
```javascript
60-
import { attributes, html } from "unyielding";
61-
62-
function CreatePhotoForm() {
63-
yield html`<form ${attributes({ method: 'post', action: '/photo' })}>`;
64-
//
65-
yield html`</form>`;
66-
}
67-
```
68-
69-
### Data attributes
70-
71-
```javascript
72-
import { dataset, html } from "unyielding";
73-
74-
function Item({ uuid, title }) {
75-
yield html`<article ${dataset({ uuid })}>`;
76-
yield html`<h2>`;
77-
yield title;
78-
yield html`</h2>`;
79-
yield html`</article>`;
80-
}
81-
```
82-
83-
## TODO / Ideas
84-
85-
```javascript
86-
// Yield function with name of HTML tag
87-
function Nav(links) {
88-
yield html`<nav aria-label="Primary">`;
89-
90-
yield function* ul() {
91-
for (const link of links) {
92-
yield NavLink(link);
93-
}
94-
};
95-
96-
yield html`</nav>`;
97-
}
98-
99-
// Yield function with name of landmark
100-
function Page() {
101-
yield PrimaryNav();
102-
103-
yield function* main() { // <main>
104-
yield Heading("Welcome!");
27+
function* loading() {
28+
yield call(fetch, [url.toString()]);
29+
yield on("SUCCESS", success);
30+
yield on("FAILURE", failure);
10531
}
106-
107-
yield function* contentinfo() { // <footer role=contentinfo>
108-
yield FooterLinks();
32+
function* success() {}
33+
function* failure() {
34+
yield on("RETRY", loading);
10935
}
36+
37+
return idle;
11038
}
11139

112-
// Perhaps allow attributes to be set
113-
function Nav2(links) {
114-
yield function* nav() {
115-
yield attributes({ "aria-label": "Primary" });
40+
const loader = start(Loader, { url: new URL("https://example.org/") });
11641

117-
yield function* ul() {
118-
for (const link of links) {
119-
yield NavLink(link);
120-
}
121-
};
122-
}
123-
}
42+
loader.next("FETCH");
43+
loader.value; // "loading"
44+
45+
loader.promisedValue.then(response => {
46+
// Use response of fetch()
47+
});
12448
```

0 commit comments

Comments
 (0)