nuclo 0.1.36 → 0.1.37

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.
Files changed (2) hide show
  1. package/README.md +17 -9
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -203,17 +203,19 @@ render(app, document.body);
203
203
  ```ts
204
204
  import 'nuclo';
205
205
 
206
- type State = { status: 'idle' | 'loading' | 'error'; data: any[]; error?: string };
206
+ type Product = { id: number; title: string; category: string };
207
+ type State = { status: 'idle' | 'loading' | 'error'; products: Product[]; error?: string };
207
208
 
208
- let state: State = { status: 'idle', data: [] };
209
+ let state: State = { status: 'idle', products: [] };
209
210
 
210
- async function fetchData() {
211
+ async function fetchProducts() {
211
212
  state.status = 'loading';
212
213
  update();
213
214
 
214
215
  try {
215
- const response = await fetch('/api/data');
216
- state.data = await response.json();
216
+ const response = await fetch('https://dummyjson.com/products/search?q=phone');
217
+ const data = await response.json();
218
+ state.products = data.products;
217
219
  state.status = 'idle';
218
220
  } catch (err) {
219
221
  state.status = 'error';
@@ -223,16 +225,22 @@ async function fetchData() {
223
225
  }
224
226
 
225
227
  const app = div(
226
- button('Load Data', on('click', fetchData)),
228
+ button('Load Products', on('click', fetchProducts)),
227
229
 
228
230
  when(() => state.status === 'loading',
229
231
  div('Loading...')
230
232
  ).when(() => state.status === 'error',
231
233
  div({ className: 'error' }, () => `Error: ${state.error}`)
232
- ).when(() => state.data.length > 0,
233
- list(() => state.data, item => div(item.name))
234
+ ).when(() => state.products.length > 0,
235
+ list(() => state.products, product =>
236
+ div(
237
+ { className: 'product-card' },
238
+ h3(product.title),
239
+ p(() => `Category: ${product.category}`)
240
+ )
241
+ )
234
242
  ).else(
235
- div('No data loaded')
243
+ div('No products loaded')
236
244
  )
237
245
  );
238
246
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nuclo",
3
3
  "private": false,
4
- "version": "0.1.36",
4
+ "version": "0.1.37",
5
5
  "type": "module",
6
6
  "main": "./dist/nuclo.cjs",
7
7
  "module": "./dist/nuclo.js",