@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 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
- > - 🏂 *(optional)* [@e280/stz](https://github.com/e280/stz) stz is our ts standard library
28
- > - 🐢 *(optional)* [scute](https://github.com/e280/scute) is our buildy-bundly-buddy
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).. views have the good parts of web components, but they aren't cumbersome.
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 data
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e280/sly",
3
- "version": "0.0.0-8",
3
+ "version": "0.0.0-9",
4
4
  "description": "web shadow views",
5
5
  "license": "MIT",
6
6
  "type": "module",
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: (p: Pod<any>) => p[0],
5
+ status: (pod: Pod<any>) => pod[0],
6
6
 
7
- value: <V>(p: Pod<V>) => {
8
- return p[0] === "ready"
9
- ? p[1]
7
+ value: <V>(pod: Pod<V>) => {
8
+ return pod[0] === "ready"
9
+ ? pod[1]
10
10
  : undefined
11
11
  },
12
12
 
13
- error: <V>(p: Pod<V>) => {
14
- return p[0] === "error"
15
- ? p[1]
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>(p: Pod<V>, select: PodSelect<V, R>) => {
20
- switch (p[0]) {
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(p[1])
23
- case "ready": return select.ready(p[1])
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>(p: Pod<A>, fn: (a: A) => B): Pod<B> => {
29
- return podium.select<A, Pod<B>>(p, {
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>(...ps: Pod<V>[]): Pod<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 p of ps) {
42
- switch (p[0]) {
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(p[1])
48
+ values.push(pod[1])
49
49
  break
50
50
 
51
51
  case "error":
52
- errors.push(p[1])
52
+ errors.push(pod[1])
53
53
  break
54
54
  }
55
55
  }
package/s/views/use.ts CHANGED
@@ -91,7 +91,7 @@ export class Use {
91
91
  function op<V>(f: () => Promise<V>) {
92
92
  return that.once(() => Op.fn(f))
93
93
  }
94
- op.fn = op
94
+ op.fn = op as (<V>(f: () => Promise<V>) => Op<V>)
95
95
  op.promise = <V>(p: Promise<V>) => this.once(() => Op.promise(p))
96
96
  return op
97
97
  })()