@wrnrlr/prelude 0.1.2 → 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.2",
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.2",
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",
@@ -81,7 +81,7 @@ export function List<T>(props:ListProps<T>) {
81
81
  }
82
82
  const mapper = indexes ? mapperWithIndexes : mapperWithoutIndexes
83
83
  return memo(() => {
84
- const newItems = list.call ? list() : []
84
+ const newItems = list.call ? list() : list
85
85
  // (newItems)[$TRACK]; // top level tracking
86
86
  return untrack(() => {
87
87
  const temp = new Array(newItems.length) // new mapped array
@@ -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] ||= []
@@ -5,7 +5,7 @@
5
5
  font-style: normal;
6
6
  font-weight: 400;
7
7
  font-display: block;
8
- src: url("./assets/fonts/far.woff2") format("woff2"), url("./assets/fonts/far.ttf") format("truetype");
8
+ src: url("/fonts/far.woff2") format("woff2"), url("/fonts/far.ttf") format("truetype");
9
9
  }
10
10
 
11
11
  @font-face {
@@ -13,7 +13,7 @@
13
13
  font-style: normal;
14
14
  font-weight: 900;
15
15
  font-display: block;
16
- src: url("./assets/fonts/fas.woff2") format("woff2"), url("./assets/fonts/fas.ttf") format("truetype");
16
+ src: url("/fonts/fas.woff2") format("woff2"), url("/fonts/fas.ttf") format("truetype");
17
17
  };
18
18
 
19
19
  @font-face {
@@ -21,7 +21,7 @@
21
21
  font-style: normal;
22
22
  font-weight: 400;
23
23
  font-display: block;
24
- src: url("./assets/fonts/fab.woff2") format("woff2"), url("./assets/fonts/fab.ttf") format("truetype");
24
+ src: url("/fonts/fab.woff2") format("woff2"), url("/fonts/fab.ttf") format("truetype");
25
25
  }
26
26
 
27
27
  .icon {display:flex; display:inline-block}
package/www/demo.html ADDED
@@ -0,0 +1,28 @@
1
+ <!DOCTYPE html>
2
+ <title>Demo</title>
3
+
4
+ <script type="module">
5
+
6
+ import {h,signal,effect,batch,wrap,render,onMount,List} from '../src/mod.ts'
7
+
8
+ function Test(props) {
9
+ return h('h1.red', {class:'yellow'}, 'Hello')
10
+ }
11
+
12
+ function App() {
13
+ const fruits = ['apple', 'banana', 'cherry']
14
+ return h(List, {each:fruits}, f => f)
15
+ }
16
+
17
+ render(Test, document.body)
18
+
19
+ </script>
20
+
21
+ <style>
22
+ .red {
23
+ background-color: red;
24
+ }
25
+ .yellow {
26
+ color:yellow;
27
+ }
28
+ </style>
package/www/index.html CHANGED
@@ -36,7 +36,7 @@
36
36
  <section class="flex column items-center py-8 gap-8">
37
37
  <h1 class="center text-5xl">Just write JavaScript!</h1>
38
38
  <p class="center text-2xl">Instead of JSX, Prelude uses HyperScript,<br>
39
- a DSL that lets you defined components in JavaScript.</p>
39
+ a DSL that lets you define components in JavaScript.</p>
40
40
  <div class="flex items-center content-center gap-8">
41
41
  <pre><code class="language-js">import {h, signal, render} from 'prelude'
42
42
 
@@ -70,7 +70,7 @@ render(Counter, window.counter)</code></pre>
70
70
 
71
71
  <footer class="flex px-2 py-2 gap-8" style="background-color: var(--neutral-100);">
72
72
  <div class="flex column justify-center gap-3">
73
- <a href="https://npm.com/@wrnrlr/prelude">NPM</a>
73
+ <a href="https://www.npmjs.com/package/@wrnrlr/prelude">NPM</a>
74
74
  <a href="https://jsr.io/@wrnrlr/prelude">JSR</a>
75
75
  </div>
76
76
  <div class="flex column justify-center gap-3">
@@ -17,7 +17,7 @@ import {html} from "@codemirror/lang-html"
17
17
  const playing = signal(true)
18
18
  const examples = [
19
19
  {name:'counter',title:'Counter'},
20
- {name:'todo',title:'Todo'},
20
+ {name:'todo',title:'Todo App'},
21
21
  // {name:'admin',title:'Admin'}
22
22
  ]
23
23
 
@@ -3,7 +3,7 @@
3
3
 
4
4
  <script type="module">
5
5
 
6
- import {h,signal,render} from '/prelude/bundle.js'
6
+ import {h,signal,render} from 'https://esm.sh/@wrnrlr/prelude'
7
7
 
8
8
  function Input(props) {
9
9
  const onInput = e => props.value(parseInt(e.target.value))
@@ -3,7 +3,7 @@
3
3
 
4
4
  <script type="module">
5
5
 
6
- import {h,signal,effect,batch,wrap,render,List} from '/prelude/bundle.js'
6
+ import {h,signal,effect,batch,wrap,render,List} from 'https://esm.sh/@wrnrlr/prelude'
7
7
 
8
8
  const data = [
9
9
  {description:'Buy groceries',done:false},
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes