nuclo 0.1.37 → 0.1.38

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 +20 -3
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -207,13 +207,16 @@ type Product = { id: number; title: string; category: string };
207
207
  type State = { status: 'idle' | 'loading' | 'error'; products: Product[]; error?: string };
208
208
 
209
209
  let state: State = { status: 'idle', products: [] };
210
+ let searchQuery = 'phone';
210
211
 
211
212
  async function fetchProducts() {
213
+ if (!searchQuery.trim()) return;
214
+
212
215
  state.status = 'loading';
213
216
  update();
214
217
 
215
218
  try {
216
- const response = await fetch('https://dummyjson.com/products/search?q=phone');
219
+ const response = await fetch(`https://dummyjson.com/products/search?q=${searchQuery}`);
217
220
  const data = await response.json();
218
221
  state.products = data.products;
219
222
  state.status = 'idle';
@@ -225,7 +228,21 @@ async function fetchProducts() {
225
228
  }
226
229
 
227
230
  const app = div(
228
- button('Load Products', on('click', fetchProducts)),
231
+ div(
232
+ input(
233
+ {
234
+ type: 'search',
235
+ placeholder: 'Search products...',
236
+ value: () => searchQuery
237
+ },
238
+ on('input', e => {
239
+ searchQuery = e.target.value;
240
+ update();
241
+ }),
242
+ on('keydown', e => e.key === 'Enter' && fetchProducts())
243
+ ),
244
+ button('Search', on('click', fetchProducts))
245
+ ),
229
246
 
230
247
  when(() => state.status === 'loading',
231
248
  div('Loading...')
@@ -240,7 +257,7 @@ const app = div(
240
257
  )
241
258
  )
242
259
  ).else(
243
- div('No products loaded')
260
+ div('Click search to load products')
244
261
  )
245
262
  );
246
263
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nuclo",
3
3
  "private": false,
4
- "version": "0.1.37",
4
+ "version": "0.1.38",
5
5
  "type": "module",
6
6
  "main": "./dist/nuclo.cjs",
7
7
  "module": "./dist/nuclo.js",