@rettangoli/fe 0.0.8 → 0.0.9
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 +1 -1
- package/src/cli/watch.js +15 -1
- package/src/createComponent.js +8 -7
- package/src/parser.js +11 -2
package/package.json
CHANGED
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
|
-
|
|
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
|
package/src/createComponent.js
CHANGED
|
@@ -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: (
|
|
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
|
-
|
|
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
|
};
|
package/src/parser.js
CHANGED
|
@@ -332,13 +332,22 @@ export const createVirtualDom = ({
|
|
|
332
332
|
}
|
|
333
333
|
|
|
334
334
|
if (eventConfig.action) {
|
|
335
|
-
|
|
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](
|
|
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
|