@wrnrlr/prelude 0.1.3 → 0.1.5
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.json +1 -1
- package/package.json +1 -1
- package/src/hyperscript.ts +4 -4
- package/src/mod.ts +1 -1
- package/src/reactive.ts +11 -0
- package/www/demo.html +14 -1
package/deno.json
CHANGED
package/package.json
CHANGED
package/src/hyperscript.ts
CHANGED
@@ -126,15 +126,15 @@ export function hyperscript(r:Runtime, patch?:any):HyperScript {
|
|
126
126
|
if (tag.id) e.setAttribute('id',tag.id)
|
127
127
|
if (tag.classes?.length) {
|
128
128
|
const cd = Object.getOwnPropertyDescriptor(props2,'class') ?? ({value:'',writable:true,enumerable:true} as any);
|
129
|
-
(props2 as any).class = (
|
130
|
-
[...tag.classes,...cd.value.split(' ')].filter(c=>c).join(' ') :
|
131
|
-
|
129
|
+
(props2 as any).class = (cd.value?.call) ?
|
130
|
+
() => [...tag.classes,...(cd.value()??'').split(' ')].filter(c=>c).join(' ') :
|
131
|
+
[...tag.classes,...(cd.value??'').split(' ')].filter(c=>c).join(' ')
|
132
132
|
}
|
133
133
|
if (patch) patch(props2)
|
134
134
|
let dynamic = false
|
135
135
|
const d = Object.getOwnPropertyDescriptors(props2)
|
136
136
|
for (const k in d) {
|
137
|
-
if (k !==
|
137
|
+
if (k !== 'ref' && !k.startsWith('on') && d[k].value?.call) {
|
138
138
|
dynamicProperty(props2 as any, k)
|
139
139
|
dynamic = true
|
140
140
|
} else if (d[k].get) dynamic = true
|
package/src/mod.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
// @ts-nocheck:
|
2
2
|
export type {Getter,Setter,Fn,EqualsFn,ErrorFn,RootFn,UpdateFn} from './reactive.ts'
|
3
|
-
export {signal,effect,untrack,batch,memo,root,wrap,onMount} from './reactive.ts'
|
3
|
+
export {signal,effect,untrack,batch,memo,root,wrap,onMount,onCleanup} from './reactive.ts'
|
4
4
|
export {nbsp} from './constants.ts'
|
5
5
|
export {Show,List} from './controlflow.ts'
|
6
6
|
export {runtime, type Runtime} from './runtime.ts'
|
package/src/reactive.ts
CHANGED
@@ -327,10 +327,21 @@ export function onMount(fn: () => void) {
|
|
327
327
|
effect(() => untrack(fn));
|
328
328
|
}
|
329
329
|
|
330
|
+
/** Runs an effect `fn` once before the reactive scope is disposed */
|
330
331
|
export function onCleanup(fn: Fn):void {
|
331
332
|
OBSERVER?.cleanups.push(fn)
|
332
333
|
}
|
333
334
|
|
335
|
+
|
336
|
+
/**
|
337
|
+
@internal
|
338
|
+
@experimental
|
339
|
+
*/
|
340
|
+
export function autoclean(fn: Fn):Fn {
|
341
|
+
const cleanup = untrack(fn)
|
342
|
+
if (cleanup) OBSERVER?.cleanups.push(fn)
|
343
|
+
}
|
344
|
+
|
334
345
|
export function onError(fn: ErrorFn):void {
|
335
346
|
if ( !OBSERVER ) return
|
336
347
|
OBSERVER.contexts[SYMBOL_ERRORS] ||= []
|
package/www/demo.html
CHANGED
@@ -5,11 +5,24 @@
|
|
5
5
|
|
6
6
|
import {h,signal,effect,batch,wrap,render,onMount,List} from '../src/mod.ts'
|
7
7
|
|
8
|
+
function Test(props) {
|
9
|
+
return h('h1.red', {class:'yellow'}, 'Hello')
|
10
|
+
}
|
11
|
+
|
8
12
|
function App() {
|
9
13
|
const fruits = ['apple', 'banana', 'cherry']
|
10
14
|
return h(List, {each:fruits}, f => f)
|
11
15
|
}
|
12
16
|
|
13
|
-
render(
|
17
|
+
render(Test, document.body)
|
14
18
|
|
15
19
|
</script>
|
20
|
+
|
21
|
+
<style>
|
22
|
+
.red {
|
23
|
+
background-color: red;
|
24
|
+
}
|
25
|
+
.yellow {
|
26
|
+
color:yellow;
|
27
|
+
}
|
28
|
+
</style>
|