@inglorious/web 6.24.0 → 6.24.1

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": "@inglorious/web",
3
- "version": "6.24.0",
3
+ "version": "6.24.1",
4
4
  "description": "A new web framework that leverages the power of the Inglorious Store combined with the performance and simplicity of lit-html.",
5
5
  "author": "Matteo Antony Mistretta <antony.mistretta@gmail.com> (https://ingloriouscoderz.it)",
6
6
  "contributors": [
@@ -3,14 +3,11 @@ import { debounce } from "@inglorious/utils/functions"
3
3
  /**
4
4
  * Wraps selected event handlers of a type with debouncing, scoped per-entity.
5
5
  *
6
- * IMPORTANT: because state is managed with `mutative`, the `entity` object
7
- * passed into a handler is a draft proxy that gets revoked as soon as the
8
- * current update tick finishes. Debounced calls fire *later*, on their own
9
- * timer, well after that draft is dead. So we must never close over `entity`
10
- * itself across the debounce boundary — only its primitive `id`. When the
11
- * debounced callback actually runs, we re-fetch a live entity from the
12
- * current state via `api.getEntity(entityId)`. Primitives and `payload` are safe to
13
- * hold onto as-is; only draft/entity references are not.
6
+ * A debounced call fires later, on its own timer, outside any update: the
7
+ * entity the event brought is a draft revoked by then. So the timer notifies
8
+ * `#id:<handler>Debounced`, which runs the original handler inside an update
9
+ * of its own, with a live draft whose changes reach subscribers. An entity
10
+ * destroyed in the meantime gets nothing.
14
11
  *
15
12
  * @param {number|Object} config - Either a single delay (ms) applied to all
16
13
  * handlers listed in `handlerNames`, or a map of handlerName -> delay (ms).
@@ -45,6 +42,9 @@ export function withDebounce(config, handlerNames) {
45
42
  const originalHandler = type[handlerName]
46
43
  if (!originalHandler) continue
47
44
 
45
+ const debouncedEvent = `${handlerName}Debounced`
46
+ behavior[debouncedEvent] = originalHandler
47
+
48
48
  behavior[handlerName] = (entity, payload, api) => {
49
49
  const entityId = entity.id
50
50
 
@@ -56,9 +56,7 @@ export function withDebounce(config, handlerNames) {
56
56
 
57
57
  if (!perEntity[handlerName]) {
58
58
  perEntity[handlerName] = debounce((entityId, payload, api) => {
59
- const liveEntity = api.getEntity(entityId)
60
- if (!liveEntity) return
61
- originalHandler(liveEntity, payload, api)
59
+ api.notify(`#${entityId}:${debouncedEvent}`, payload)
62
60
  }, delays[handlerName])
63
61
  }
64
62
 
@@ -9,17 +9,10 @@ import { throttle } from "@inglorious/utils/functions"
9
9
  * the handler once more after `delay`, using the most recent suppressed
10
10
  * call's arguments, so the final state of a burst is never dropped.
11
11
  *
12
- * IMPORTANT: because state is managed with `mutative`, the `entity` object
13
- * passed into a handler is a draft proxy that gets revoked as soon as the
14
- * current update tick finishes. The leading call always runs synchronously
15
- * (same tick as the triggering event), so the draft is still live there —
16
- * but a trailing call (when `hasTrailing: true`) fires *later*, on its own
17
- * timer, after that draft is dead. To keep one code path safe for both
18
- * cases, we never close over `entity` itself across the throttle boundary —
19
- * only its primitive `id`. Every time the wrapped handler actually runs, we
20
- * re-fetch a live entity from the current state via `api.getEntity(entityId)`.
21
- * Primitives and `payload` are safe to hold onto as-is; only draft/entity
22
- * references are not.
12
+ * Every call that gets through notifies `#id:<handler>Throttled`, which runs
13
+ * the original handler inside an update with a live draft: a trailing call
14
+ * fires on its own timer, outside any update, after the event's draft is
15
+ * revoked. An entity destroyed in the meantime gets nothing.
23
16
  *
24
17
  * @param {number|Object} config - Either a single delay (ms) applied to all
25
18
  * handlers listed in `handlerNames`, or a map of handlerName -> delay (ms).
@@ -63,6 +56,9 @@ export function withThrottle(
63
56
  const originalHandler = type[handlerName]
64
57
  if (!originalHandler) continue
65
58
 
59
+ const throttledEvent = `${handlerName}Throttled`
60
+ behavior[throttledEvent] = originalHandler
61
+
66
62
  behavior[handlerName] = (entity, payload, api) => {
67
63
  const entityId = entity.id
68
64
 
@@ -75,9 +71,7 @@ export function withThrottle(
75
71
  if (!perEntity[handlerName]) {
76
72
  perEntity[handlerName] = throttle(
77
73
  (entityId, payload, api) => {
78
- const liveEntity = api.getEntity(entityId)
79
- if (!liveEntity) return
80
- originalHandler(liveEntity, payload, api)
74
+ api.notify(`#${entityId}:${throttledEvent}`, payload)
81
75
  },
82
76
  delays[handlerName],
83
77
  { hasTrailing },