@wrnrlr/prelude 0.1.3 → 0.1.4

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wrnrlr/prelude",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "exports": "./src/mod.ts",
5
5
  "compilerOptions": {
6
6
  "strict": false,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@wrnrlr/prelude",
3
3
  "type": "module",
4
- "version": "0.1.3",
4
+ "version": "0.1.4",
5
5
  "author": "Werner Laurensse",
6
6
  "description": "A signal based frontend library with fine-grained reactivity",
7
7
  "main": "./src/mod.ts",
@@ -126,15 +126,17 @@ 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 = (!cd.value.call) ?
130
- [...tag.classes,...cd.value.split(' ')].filter(c=>c).join(' ') :
131
- () => [...tag.classes,...cd.value().split(' ')].filter(c=>c).join(' ')
129
+ if (cd.value) {
130
+ (props2 as any).class = (cd.value?.call) ?
131
+ () => [...tag.classes,...cd.value().split(' ')].filter(c=>c).join(' ') :
132
+ [...tag.classes,...cd.value.split(' ')].filter(c=>c).join(' ')
133
+ }
132
134
  }
133
135
  if (patch) patch(props2)
134
136
  let dynamic = false
135
137
  const d = Object.getOwnPropertyDescriptors(props2)
136
138
  for (const k in d) {
137
- if (k !== "ref" && !k.startsWith('on') && d[k].value?.call) {
139
+ if (k !== 'ref' && !k.startsWith('on') && d[k].value?.call) {
138
140
  dynamicProperty(props2 as any, k)
139
141
  dynamic = true
140
142
  } 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(App, document.body)
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>