@rettangoli/fe 0.0.8 → 0.0.10

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rettangoli/fe",
3
- "version": "0.0.8",
3
+ "version": "0.0.10",
4
4
  "description": "Frontend framework for building reactive web components",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
package/src/cli/watch.js CHANGED
@@ -7,6 +7,10 @@ import { writeViewFile } from './build.js';
7
7
  import buildRettangoliFrontend from './build.js';
8
8
  import { extractCategoryAndComponent } from '../common.js';
9
9
 
10
+ // Debounce mechanism to prevent excessive rebuilds
11
+ let rebuildTimeout = null;
12
+ const DEBOUNCE_DELAY = 200; // 200ms delay
13
+
10
14
 
11
15
  const setupWatcher = (directory, options) => {
12
16
  watch(
@@ -21,7 +25,17 @@ const setupWatcher = (directory, options) => {
21
25
  const { category, component } = extractCategoryAndComponent(filename);
22
26
  await writeViewFile(view, category, component);
23
27
  }
24
- await buildRettangoliFrontend(options);
28
+
29
+ // Debounce the rebuild
30
+ if (rebuildTimeout) {
31
+ clearTimeout(rebuildTimeout);
32
+ }
33
+
34
+ rebuildTimeout = setTimeout(async () => {
35
+ console.log('Triggering rebuild...');
36
+ await buildRettangoliFrontend(options);
37
+ }, DEBOUNCE_DELAY);
38
+
25
39
  } catch (error) {
26
40
  console.error(`Error processing ${filename}:`, error);
27
41
  // Keep the watcher running
@@ -309,17 +309,18 @@ class BaseComponent extends HTMLElement {
309
309
  dispatchEvent: this.dispatchEvent.bind(this),
310
310
  };
311
311
 
312
-
313
312
  this.transformedHandlers = {
314
- handleCallStoreAction: (event, payload) => {
313
+ handleCallStoreAction: (payload) => {
315
314
  const { render, store } = deps;
315
+ const { _event, _action } = payload;
316
316
  const context = parseAndRender(payload, {
317
- event: {
318
- target: event.target,
319
- detail: event.detail
320
- }
317
+ event: _event
321
318
  })
322
- store[payload.action](context);
319
+ console.log('context', context)
320
+ if (!store[_action]) {
321
+ throw new Error(`store action store.${store._action} is not defined`)
322
+ }
323
+ store[_action](context);
323
324
  render();
324
325
  }
325
326
  };
@@ -364,10 +365,6 @@ class BaseComponent extends HTMLElement {
364
365
  if (oldValue !== newValue && this.render) {
365
366
  // Call handleOnUpdate if it exists
366
367
  if (this.handlers?.handleOnUpdate) {
367
- const changes = {
368
- oldAttrs: { [name]: oldValue },
369
- newAttrs: { [name]: newValue }
370
- };
371
368
  const deps = {
372
369
  ...this.deps,
373
370
  refIds: this.refIds,
@@ -376,7 +373,13 @@ class BaseComponent extends HTMLElement {
376
373
  store: this.store,
377
374
  render: this.render.bind(this),
378
375
  };
379
- this.handlers.handleOnUpdate(changes, deps);
376
+ const changes = {
377
+ oldAttrs: { [name]: oldValue },
378
+ newAttrs: { [name]: newValue },
379
+ oldProps: deps.props,
380
+ newProps: deps.props,
381
+ };
382
+ this.handlers.handleOnUpdate(deps, changes);
380
383
  } else {
381
384
  requestAnimationFrame(() => {
382
385
  this.render();
package/src/parser.js CHANGED
@@ -332,13 +332,22 @@ export const createVirtualDom = ({
332
332
  }
333
333
 
334
334
  if (eventConfig.action) {
335
- handlers.handleCallStoreAction(event, eventConfig.payload)
335
+ eventHandlers[eventType] = (event) => {
336
+ handlers.handleCallStoreAction({
337
+ ...eventConfig.payload,
338
+ _event: event,
339
+ _action: eventConfig.action,
340
+ })
341
+ }
336
342
  return;
337
343
  }
338
344
 
339
345
  if (eventConfig.handler && handlers[eventConfig.handler]) {
340
346
  eventHandlers[eventType] = (event) => {
341
- handlers[eventConfig.handler](event, eventConfig.payload);
347
+ handlers[eventConfig.handler]({
348
+ ...eventConfig.payload,
349
+ _event: event,
350
+ });
342
351
  };
343
352
  } else if (eventConfig.handler) {
344
353
  // Keep this warning for missing handlers
@@ -419,7 +428,7 @@ export const createVirtualDom = ({
419
428
  // Call the specific component's handleOnUpdate instead of the parent's onUpdate
420
429
  if (element.handlers && element.handlers.handleOnUpdate) {
421
430
  const deps = {
422
- ...(element.deps || {}),
431
+ ...(element.deps),
423
432
  store: element.store,
424
433
  render: element.render.bind(element),
425
434
  handlers: element.handlers,
@@ -427,12 +436,12 @@ export const createVirtualDom = ({
427
436
  refIds: element.refIds || {},
428
437
  getRefIds: () => element.refIds || {},
429
438
  };
430
- element.handlers.handleOnUpdate({
439
+ element.handlers.handleOnUpdate(deps, {
431
440
  oldProps,
432
441
  newProps,
433
442
  oldAttrs,
434
443
  newAttrs,
435
- }, deps);
444
+ });
436
445
  }
437
446
  });
438
447
  }