@e280/sly 0.0.0-8 → 0.0.0-9
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 +11 -8
- package/package.json +1 -1
- package/s/ops/podium.ts +18 -18
- package/s/views/use.ts +1 -1
- package/x/demo/demo.bundle.min.js.map +3 -3
- package/x/index.html +1 -1
- package/x/ops/podium.d.ts +6 -6
- package/x/ops/podium.js +18 -18
- package/x/ops/podium.js.map +1 -1
- package/x/views/use.d.ts +1 -1
- package/x/views/use.js.map +1 -1
package/README.md
CHANGED
|
@@ -24,8 +24,8 @@ npm install @e280/sly lit @e280/strata @e280/stz
|
|
|
24
24
|
> [!NOTE]
|
|
25
25
|
> - 🔥 [lit](https://lit.dev/) for html rendering
|
|
26
26
|
> - ⛏️ [@e280/strata](https://github.com/e280/strata) for state management (signals, state trees)
|
|
27
|
-
> - 🏂
|
|
28
|
-
> - 🐢
|
|
27
|
+
> - 🏂 [@e280/stz](https://github.com/e280/stz) *(optional)* stz is our ts standard library
|
|
28
|
+
> - 🐢 [scute](https://github.com/e280/scute) *(optional)* is our buildy-bundly-buddy
|
|
29
29
|
|
|
30
30
|
<br/>
|
|
31
31
|
|
|
@@ -44,7 +44,8 @@ web components are best for giving html authors access to your cool widgets.. an
|
|
|
44
44
|
|
|
45
45
|
views automatically rerender whenever any state stuff from [@e280/strata](https://github.com/e280/strata) changes.
|
|
46
46
|
|
|
47
|
-
🥷 views have a [shadow root](https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_shadow_DOM), and support [slots](https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_templates_and_slots)
|
|
47
|
+
🥷 views have a [shadow root](https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_shadow_DOM), and support [slots](https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_templates_and_slots).
|
|
48
|
+
views have the good parts of web components, but they aren't cumbersome.
|
|
48
49
|
|
|
49
50
|
### 🍋 view example
|
|
50
51
|
- **import some stuff**
|
|
@@ -130,7 +131,10 @@ views automatically rerender whenever any state stuff from [@e280/strata](https:
|
|
|
130
131
|
```
|
|
131
132
|
- `$.register` automatically dashes the tag names (`MyComponent` becomes `<my-component>`)
|
|
132
133
|
|
|
133
|
-
### 🍋 view "use" reference
|
|
134
|
+
### 🍋 view "use" hooks reference
|
|
135
|
+
- 👮 **follow the hooks rules**
|
|
136
|
+
> just like [react hooks](https://react.dev/warnings/invalid-hook-call-warning), the execution order of sly's `use` hooks actually matters..
|
|
137
|
+
> you must not call these hooks under `if` conditionals, or `for` loops, or in callbacks, or after a conditional `return` statement, or anything like that.. *otherwise, heed my warning: weird bad stuff will happen..*
|
|
134
138
|
- **use.name** — set the "view" attr value, eg `<sly-view view="squarepants">`
|
|
135
139
|
```ts
|
|
136
140
|
use.name("squarepants")
|
|
@@ -309,9 +313,8 @@ import {nap} from "@e280/stz"
|
|
|
309
313
|
import {Pod, podium, Op, makeLoader, anims} from "@e280/sly"
|
|
310
314
|
```
|
|
311
315
|
|
|
312
|
-
### 🫛 pods: loading/ready/error
|
|
313
|
-
- a pod represents an async operation
|
|
314
|
-
- pods are simple json-serializable data
|
|
316
|
+
### 🫛 pods: loading/ready/error
|
|
317
|
+
- a pod represents an async operation in terms of json-serializable data
|
|
315
318
|
- there are three kinds of `Pod<V>`
|
|
316
319
|
```ts
|
|
317
320
|
// loading pod
|
|
@@ -368,8 +371,8 @@ import {Pod, podium, Op, makeLoader, anims} from "@e280/sly"
|
|
|
368
371
|
```
|
|
369
372
|
- get pod info
|
|
370
373
|
```ts
|
|
371
|
-
op.status // "loading"
|
|
372
374
|
op.pod // ["loading"]
|
|
375
|
+
op.status // "loading"
|
|
373
376
|
op.value // undefined (or value if ready)
|
|
374
377
|
```
|
|
375
378
|
```ts
|
package/package.json
CHANGED
package/s/ops/podium.ts
CHANGED
|
@@ -2,54 +2,54 @@
|
|
|
2
2
|
import {Pod, PodSelect} from "./types.js"
|
|
3
3
|
|
|
4
4
|
export const podium = {
|
|
5
|
-
status: (
|
|
5
|
+
status: (pod: Pod<any>) => pod[0],
|
|
6
6
|
|
|
7
|
-
value: <V>(
|
|
8
|
-
return
|
|
9
|
-
?
|
|
7
|
+
value: <V>(pod: Pod<V>) => {
|
|
8
|
+
return pod[0] === "ready"
|
|
9
|
+
? pod[1]
|
|
10
10
|
: undefined
|
|
11
11
|
},
|
|
12
12
|
|
|
13
|
-
error: <V>(
|
|
14
|
-
return
|
|
15
|
-
?
|
|
13
|
+
error: <V>(pod: Pod<V>) => {
|
|
14
|
+
return pod[0] === "error"
|
|
15
|
+
? pod[1]
|
|
16
16
|
: undefined
|
|
17
17
|
},
|
|
18
18
|
|
|
19
|
-
select: <V, R>(
|
|
20
|
-
switch (
|
|
19
|
+
select: <V, R>(pod: Pod<V>, select: PodSelect<V, R>) => {
|
|
20
|
+
switch (pod[0]) {
|
|
21
21
|
case "loading": return select.loading()
|
|
22
|
-
case "error": return select.error(
|
|
23
|
-
case "ready": return select.ready(
|
|
22
|
+
case "error": return select.error(pod[1])
|
|
23
|
+
case "ready": return select.ready(pod[1])
|
|
24
24
|
default: throw new Error("unknown op status")
|
|
25
25
|
}
|
|
26
26
|
},
|
|
27
27
|
|
|
28
|
-
morph: <A, B>(
|
|
29
|
-
return podium.select<A, Pod<B>>(
|
|
28
|
+
morph: <A, B>(pod: Pod<A>, fn: (a: A) => B): Pod<B> => {
|
|
29
|
+
return podium.select<A, Pod<B>>(pod, {
|
|
30
30
|
loading: () => ["loading"],
|
|
31
31
|
error: error => ["error", error],
|
|
32
32
|
ready: a => ["ready", fn(a)],
|
|
33
33
|
})
|
|
34
34
|
},
|
|
35
35
|
|
|
36
|
-
all: <V>(...
|
|
36
|
+
all: <V>(...pods: Pod<V>[]): Pod<V[]> => {
|
|
37
37
|
const values: V[] = []
|
|
38
38
|
const errors: any[] = []
|
|
39
39
|
let loading = 0
|
|
40
40
|
|
|
41
|
-
for (const
|
|
42
|
-
switch (
|
|
41
|
+
for (const pod of pods) {
|
|
42
|
+
switch (pod[0]) {
|
|
43
43
|
case "loading":
|
|
44
44
|
loading++
|
|
45
45
|
break
|
|
46
46
|
|
|
47
47
|
case "ready":
|
|
48
|
-
values.push(
|
|
48
|
+
values.push(pod[1])
|
|
49
49
|
break
|
|
50
50
|
|
|
51
51
|
case "error":
|
|
52
|
-
errors.push(
|
|
52
|
+
errors.push(pod[1])
|
|
53
53
|
break
|
|
54
54
|
}
|
|
55
55
|
}
|
package/s/views/use.ts
CHANGED