@dooboostore/simple-web-component 1.0.51 → 1.0.53
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/README.md +7 -8
- package/dist/cjs/decorators/addEventListener.js +8 -3
- package/dist/cjs/decorators/addEventListener.js.map +2 -2
- package/dist/cjs/decorators/requestAnimationFrame.js +10 -2
- package/dist/cjs/decorators/requestAnimationFrame.js.map +2 -2
- package/dist/cjs/decorators/setInterval.js +4 -2
- package/dist/cjs/decorators/setInterval.js.map +2 -2
- package/dist/cjs/decorators/setTimeout.js +4 -2
- package/dist/cjs/decorators/setTimeout.js.map +2 -2
- package/dist/cjs/decorators/subscribeSwcAppMessage.js +14 -1
- package/dist/cjs/decorators/subscribeSwcAppMessage.js.map +2 -2
- package/dist/cjs/elements/SwcAppMixin.js +7 -1
- package/dist/cjs/elements/SwcAppMixin.js.map +2 -2
- package/dist/esm/decorators/addEventListener.js +8 -3
- package/dist/esm/decorators/addEventListener.js.map +2 -2
- package/dist/esm/decorators/requestAnimationFrame.js +10 -2
- package/dist/esm/decorators/requestAnimationFrame.js.map +2 -2
- package/dist/esm/decorators/setInterval.js +4 -2
- package/dist/esm/decorators/setInterval.js.map +2 -2
- package/dist/esm/decorators/setTimeout.js +4 -2
- package/dist/esm/decorators/setTimeout.js.map +2 -2
- package/dist/esm/decorators/subscribeSwcAppMessage.js +14 -1
- package/dist/esm/decorators/subscribeSwcAppMessage.js.map +2 -2
- package/dist/esm/elements/SwcAppMixin.js +7 -1
- package/dist/esm/elements/SwcAppMixin.js.map +2 -2
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +44 -8
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +3 -3
- package/dist/types/decorators/addEventListener.d.ts.map +1 -1
- package/dist/types/decorators/requestAnimationFrame.d.ts +7 -4
- package/dist/types/decorators/requestAnimationFrame.d.ts.map +1 -1
- package/dist/types/decorators/setInterval.d.ts +6 -4
- package/dist/types/decorators/setInterval.d.ts.map +1 -1
- package/dist/types/decorators/setTimeout.d.ts +6 -4
- package/dist/types/decorators/setTimeout.d.ts.map +1 -1
- package/dist/types/decorators/subscribeSwcAppMessage.d.ts +12 -0
- package/dist/types/decorators/subscribeSwcAppMessage.d.ts.map +1 -1
- package/dist/types/elements/SwcAppMixin.d.ts.map +1 -1
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +44 -8
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +3 -3
- package/package.json +2 -2
- package/src/decorators/addEventListener.ts +10 -3
- package/src/decorators/requestAnimationFrame.ts +17 -5
- package/src/decorators/setInterval.ts +9 -5
- package/src/decorators/setTimeout.ts +9 -5
- package/src/decorators/subscribeSwcAppMessage.ts +27 -0
- package/src/elements/SwcAppMixin.ts +11 -1
package/README.md
CHANGED
|
@@ -1048,15 +1048,14 @@ onSecond() { }
|
|
|
1048
1048
|
|
|
1049
1049
|
Declaratively schedule work tied to the component. Every timer the decorator starts is cleared automatically on disconnect. There are two modes (`type` option):
|
|
1050
1050
|
|
|
1051
|
-
- `type: '
|
|
1052
|
-
- `type: '
|
|
1051
|
+
- `type: 'onConnected'` (**default**) - starts on connect and calls the decorated method itself on every tick/fire.
|
|
1052
|
+
- `type: 'returnValue'` - nothing starts automatically. When you call the method, its return value (a function, or the function under `valueKey`) becomes the repeating/delayed callback, called with `(id: number)`. The original return value passes through. Aliases: `@setIntervalReturnValue`, `@setTimeoutReturnValue`, `@requestAnimationFrameReturnValue`.
|
|
1053
1053
|
|
|
1054
1054
|
```typescript
|
|
1055
1055
|
@elementDefine('live-clock')
|
|
1056
1056
|
class LiveClock extends HTMLElement {
|
|
1057
1057
|
// Auto-start on connect
|
|
1058
1058
|
@setInterval(1000, {
|
|
1059
|
-
type: 'onConnected',
|
|
1060
1059
|
parameter: (set) => [Date.now()],
|
|
1061
1060
|
created: (set, id) => console.log('interval started, timer id:', id)
|
|
1062
1061
|
})
|
|
@@ -1065,13 +1064,13 @@ class LiveClock extends HTMLElement {
|
|
|
1065
1064
|
}
|
|
1066
1065
|
|
|
1067
1066
|
// Fires once, 3 seconds after connect
|
|
1068
|
-
@setTimeout(3000
|
|
1067
|
+
@setTimeout(3000)
|
|
1069
1068
|
onceAfter3s() {
|
|
1070
1069
|
console.log('3 seconds have passed');
|
|
1071
1070
|
}
|
|
1072
1071
|
|
|
1073
|
-
//
|
|
1074
|
-
@
|
|
1072
|
+
// 'returnValue': starts when you call startPolling()
|
|
1073
|
+
@setIntervalReturnValue(900)
|
|
1075
1074
|
startPolling() {
|
|
1076
1075
|
return (id: number) => console.log('interval', id, 'ticked');
|
|
1077
1076
|
}
|
|
@@ -1080,7 +1079,7 @@ class LiveClock extends HTMLElement {
|
|
|
1080
1079
|
|
|
1081
1080
|
**`@setInterval(interval, options?)` / `@setTimeout(delay, options?)`:**
|
|
1082
1081
|
- `interval` / `delay` - milliseconds. `setInterval` repeats; `setTimeout` fires once.
|
|
1083
|
-
- `type` - `'
|
|
1082
|
+
- `type` - `'onConnected'` (default) | `'returnValue'`
|
|
1084
1083
|
- `parameter?: (set: HelperHostSet) => any[]` - (`onConnected`) arguments for each tick/fire; omitted → no arguments.
|
|
1085
1084
|
- `created?: (set: HelperHostSet, id: number) => void` - called once right after the timer is armed. For logging only; cleanup is automatic.
|
|
1086
1085
|
- `filter` / `before` / `finally` - (`onConnected`) per-tick hooks; `before` result → `@setIntervalBeforeReturn` / `@setTimeoutBeforeReturn`.
|
|
@@ -1089,7 +1088,7 @@ class LiveClock extends HTMLElement {
|
|
|
1089
1088
|
**`@requestAnimationFrame(options?)`** (bare form also works) - same two modes. The frame callback is `(timestamp, prevValue) => any`: return `undefined`/`null` to stop the loop, anything else is passed as `prevValue` to the next frame. Options: `type`, `created`, `valueKey`.
|
|
1090
1089
|
|
|
1091
1090
|
```typescript
|
|
1092
|
-
@
|
|
1091
|
+
@requestAnimationFrameReturnValue // starts when you call animate()
|
|
1093
1092
|
animate() {
|
|
1094
1093
|
return (ts: number, prev = 0) => (prev < 100 ? prev + 1 : null); // stops at 100
|
|
1095
1094
|
}
|
|
@@ -2044,7 +2044,9 @@ class EventListenerLifeCycler {
|
|
|
2044
2044
|
const currentWin = helperHostSet.$w;
|
|
2045
2045
|
const { type, options } = meta;
|
|
2046
2046
|
const opts = { capture: options.capture, once: options.once, passive: options.passive };
|
|
2047
|
+
const matchedTargets = /* @__PURE__ */ new WeakMap();
|
|
2047
2048
|
const handler = async (event2) => {
|
|
2049
|
+
const matchedElement = matchedTargets.get(event2) ?? event2.currentTarget;
|
|
2048
2050
|
const helper = options.filter || options.before || options.finally ? import_Utils.SwcUtils.getHelperAndHostSet(target, currentWin) : void 0;
|
|
2049
2051
|
if (options.filter) {
|
|
2050
2052
|
if (!await options.filter(event2, { currentThis: inst, helper })) return;
|
|
@@ -2053,12 +2055,12 @@ class EventListenerLifeCycler {
|
|
|
2053
2055
|
if (options.stopImmediatePropagation) event2.stopImmediatePropagation();
|
|
2054
2056
|
if (options.preventDefault) event2.preventDefault();
|
|
2055
2057
|
const currentHostSet = import_Utils.SwcUtils.getHostSet(inst);
|
|
2056
|
-
const legacyArgs = [event2, { currentHostSet, $matchedElement:
|
|
2058
|
+
const legacyArgs = [event2, { currentHostSet, $matchedElement: matchedElement }, { event: event2, ...currentHostSet, $el: target, $root: target }];
|
|
2057
2059
|
const currentHelperSet = import_Utils.SwcUtils.getHelperSet(currentWin);
|
|
2058
2060
|
const currentHelperHostSet = { ...currentHelperSet, ...currentHostSet, $this: inst };
|
|
2059
2061
|
const buildArgs = (beforeReturn) => (0, import_parameter.buildSwcParameterArgs)(inst, meta.propertyKey, {
|
|
2060
2062
|
eventObject: event2,
|
|
2061
|
-
matchedElement
|
|
2063
|
+
matchedElement,
|
|
2062
2064
|
hostSet: currentHostSet,
|
|
2063
2065
|
helperHostSet: currentHelperHostSet,
|
|
2064
2066
|
helperSet: currentHelperSet,
|
|
@@ -2092,7 +2094,10 @@ class EventListenerLifeCycler {
|
|
|
2092
2094
|
next: (e) => handler(e).catch((err) => console.error("Event handler error:", err)),
|
|
2093
2095
|
error: (err) => console.error("Event stream error:", err)
|
|
2094
2096
|
});
|
|
2095
|
-
const wrappedHandler = (event2) =>
|
|
2097
|
+
const wrappedHandler = (event2) => {
|
|
2098
|
+
matchedTargets.set(event2, event2.currentTarget);
|
|
2099
|
+
eventSubject.next(event2);
|
|
2100
|
+
};
|
|
2096
2101
|
target.addEventListener(type, wrappedHandler, opts);
|
|
2097
2102
|
const onRemoves = options.removeListener ? [{ fn: options.removeListener, opts: options }] : [];
|
|
2098
2103
|
this.getBoundListeners(inst).push({ target, type, handler: wrappedHandler, options: opts, subscription, onRemoves, meta });
|