@wrnrlr/prelude 0.2.21 → 0.2.23
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/deno.jsonc +1 -1
- package/package.json +1 -1
- package/src/mod.ts +1 -30
- package/src/reactive.ts +20 -0
- package/src/show.ts +1 -1
package/deno.jsonc
CHANGED
package/package.json
CHANGED
package/src/mod.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
export type {Getter,Setter,Signal} from './reactive.ts'
|
2
|
-
export {signal,effect,untrack,batch,memo,root,context,useContext,wrap,fuse,onMount,onCleanup,renderEffect} from './reactive.ts'
|
2
|
+
export {signal,effect,untrack,batch,memo,root,children,context,useContext,wrap,fuse,on,onMount,onCleanup,renderEffect} from './reactive.ts'
|
3
3
|
export {nbsp} from './constants.ts'
|
4
4
|
export {List} from './list.ts'
|
5
5
|
export {Show} from './show.ts'
|
@@ -11,32 +11,3 @@ export {resource,makeAbortable,abortable} from './resource.js'
|
|
11
11
|
import {r} from './runtime.ts'
|
12
12
|
export const render = r.render
|
13
13
|
export {Dialog,useDialog,Input,Checkbox,Select} from './form.js'
|
14
|
-
|
15
|
-
// const r:Runtime = /*#__PURE__*/ (typeof window === 'object') ? runtime(window) : undefined as unknown as Runtime
|
16
|
-
|
17
|
-
/** h
|
18
|
-
@example Element with a single child
|
19
|
-
```js
|
20
|
-
h('h1','Hello World!')
|
21
|
-
```
|
22
|
-
@example Element with multiple children
|
23
|
-
```js
|
24
|
-
h('p',['Hello ',h('em','World!')])
|
25
|
-
```
|
26
|
-
@example Component with event handler
|
27
|
-
```js
|
28
|
-
h(Input,{onInput:e => {}})
|
29
|
-
```
|
30
|
-
@group Hyperscript
|
31
|
-
*/
|
32
|
-
// export const h: HyperScript = /*#__PURE__*/ hyperscript(r, parseHtmlTag)
|
33
|
-
|
34
|
-
/** render
|
35
|
-
|
36
|
-
Render component to DOM element.
|
37
|
-
|
38
|
-
```js
|
39
|
-
render(()=>'hi', document.body)
|
40
|
-
```
|
41
|
-
*/
|
42
|
-
// export const render:(code:()=>void, element:Element, init:unknown) => void = /*#__PURE__*/ r?.render
|
package/src/reactive.ts
CHANGED
@@ -466,3 +466,23 @@ function observe<T>(fn: Fn<T>, observer: Observer | undefined, tracking: boolean
|
|
466
466
|
TRACKING = TRACKING_PREV;
|
467
467
|
}
|
468
468
|
}
|
469
|
+
|
470
|
+
export function on( deps: any, fn: any, options?: any ): any {
|
471
|
+
const isArray = Array.isArray(deps);
|
472
|
+
let prevInput: any;
|
473
|
+
let defer = options && options.defer;
|
474
|
+
return prevValue => {
|
475
|
+
let input: any;
|
476
|
+
if (isArray) {
|
477
|
+
input = Array(deps.length) as unknown as S;
|
478
|
+
for (let i = 0; i < deps.length; i++) (input as unknown as any)[i] = deps[i]();
|
479
|
+
} else input = deps();
|
480
|
+
if (defer) {
|
481
|
+
defer = false;
|
482
|
+
return prevValue;
|
483
|
+
}
|
484
|
+
const result = untrack(() => fn(input, prevInput, prevValue));
|
485
|
+
prevInput = input;
|
486
|
+
return result;
|
487
|
+
};
|
488
|
+
}
|
package/src/show.ts
CHANGED
@@ -43,6 +43,6 @@ export function Show<T>(props:ShowProps<T>) {
|
|
43
43
|
const child = props.children
|
44
44
|
const fn = typeof child === "function" && child.length > 0
|
45
45
|
return fn ? untrack(() => child(() => props.when)) : child
|
46
|
-
} else return props
|
46
|
+
} else return props?.fallback || []
|
47
47
|
})
|
48
48
|
}
|