react-native-audio-browser 0.2.0-next.61 → 0.2.0-next.63

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 (51) hide show
  1. package/android/src/main/java/com/audiobrowser/browser/BrowserManager.kt +16 -6
  2. package/android/src/main/java/com/audiobrowser/player/PlaybackStateMachine.kt +9 -6
  3. package/android/src/main/java/com/audiobrowser/player/PlayerListener.kt +0 -5
  4. package/android/src/test/java/com/audiobrowser/browser/BrowserManagerInvalidationTest.kt +14 -0
  5. package/android/src/test/java/com/audiobrowser/player/PlaybackStateMachineTest.kt +7 -6
  6. package/android/src/test/java/com/audiobrowser/player/PlayerRetryTest.kt +35 -0
  7. package/ios/Browser/BrowserManager.swift +22 -7
  8. package/ios/HybridAudioBrowser+Options.swift +14 -0
  9. package/ios/HybridAudioBrowser.swift +4 -1
  10. package/ios/Player/DeferredSeek.swift +4 -1
  11. package/ios/Player/Player.swift +10 -7
  12. package/ios/Tests/DeferredSeekTests.swift +12 -4
  13. package/ios/Tests/PlayerPolicyTests.swift +86 -0
  14. package/lib/commonjs/CLAUDE.md +2 -2
  15. package/lib/commonjs/features/sleepTimer.js +8 -12
  16. package/lib/commonjs/features/sleepTimer.js.map +1 -1
  17. package/lib/commonjs/utils/LazyNativeEmitter.js +3 -3
  18. package/lib/commonjs/utils/NativeUpdatedValue.js +10 -13
  19. package/lib/commonjs/utils/NativeUpdatedValue.js.map +1 -1
  20. package/lib/commonjs/utils/useNativeUpdatedValue.js +12 -20
  21. package/lib/commonjs/utils/useNativeUpdatedValue.js.map +1 -1
  22. package/lib/commonjs/utils/useNativeValueRefreshedBy.js +10 -5
  23. package/lib/commonjs/utils/useNativeValueRefreshedBy.js.map +1 -1
  24. package/lib/module/CLAUDE.md +2 -2
  25. package/lib/module/features/sleepTimer.js +9 -13
  26. package/lib/module/features/sleepTimer.js.map +1 -1
  27. package/lib/module/utils/LazyNativeEmitter.js +3 -3
  28. package/lib/module/utils/NativeUpdatedValue.js +10 -13
  29. package/lib/module/utils/NativeUpdatedValue.js.map +1 -1
  30. package/lib/module/utils/useNativeUpdatedValue.js +13 -21
  31. package/lib/module/utils/useNativeUpdatedValue.js.map +1 -1
  32. package/lib/module/utils/useNativeValueRefreshedBy.js +11 -6
  33. package/lib/module/utils/useNativeValueRefreshedBy.js.map +1 -1
  34. package/lib/typescript/src/features/sleepTimer.d.ts.map +1 -1
  35. package/lib/typescript/src/utils/LazyNativeEmitter.d.ts +3 -3
  36. package/lib/typescript/src/utils/NativeUpdatedValue.d.ts +4 -13
  37. package/lib/typescript/src/utils/NativeUpdatedValue.d.ts.map +1 -1
  38. package/lib/typescript/src/utils/useNativeUpdatedValue.d.ts +4 -4
  39. package/lib/typescript/src/utils/useNativeUpdatedValue.d.ts.map +1 -1
  40. package/lib/typescript/src/utils/useNativeValueRefreshedBy.d.ts +3 -4
  41. package/lib/typescript/src/utils/useNativeValueRefreshedBy.d.ts.map +1 -1
  42. package/package.json +1 -1
  43. package/src/CLAUDE.md +2 -2
  44. package/src/features/sleepTimer.test.ts +25 -26
  45. package/src/features/sleepTimer.ts +9 -9
  46. package/src/utils/LazyNativeEmitter.ts +3 -3
  47. package/src/utils/NativeUpdatedValue.ts +10 -13
  48. package/src/utils/useNativeUpdatedValue.test.ts +30 -22
  49. package/src/utils/useNativeUpdatedValue.ts +13 -17
  50. package/src/utils/useNativeValueRefreshedBy.test.ts +68 -0
  51. package/src/utils/useNativeValueRefreshedBy.ts +13 -6
@@ -9,14 +9,10 @@ exports.NativeUpdatedValue = void 0;
9
9
  * `onQueueChanged`, `onTrackMetadata`, …). Subscribe with {@link addListener};
10
10
  * the returned function unsubscribes. The emitter is not callable itself.
11
11
  *
12
- * It listens to native from module load and keeps the latest payload in
13
- * {@link lastValue}. The remote-control exports and `onGate` use
14
- * `LazyNativeEmitter`, which listens only once a listener is added.
15
- *
16
- * `lastValue` is the last payload native sent, not a fresh reading: it is
17
- * `undefined` before the first event, and for the queue and active track it
18
- * can be stale after an in-place change (a favorite toggle). Use the getter
19
- * (`getQueue`, `getActiveTrack`, …) when you need the current value.
12
+ * It listens to native from module load. The remote-control exports and
13
+ * `onGate` use `LazyNativeEmitter`, which listens only once a listener is
14
+ * added. It keeps no payload: use the getter (`getQueue`, `getActiveTrack`, …)
15
+ * for the current value.
20
16
  *
21
17
  * @example
22
18
  * ```typescript
@@ -33,16 +29,17 @@ class NativeUpdatedValue {
33
29
  listeners = new Set();
34
30
 
35
31
  /**
36
- * The last payload native sent, or `undefined` before the first. Not a fresh
37
- * reading: use the matching getter (`getQueue`, …) for the current value.
32
+ * Events received so far, so a hook can tell whether one landed between its
33
+ * render and its subscription.
34
+ * @internal
38
35
  */
39
- lastValue = undefined;
36
+ eventCount = 0;
40
37
 
41
38
  /** @internal */
42
39
  constructor(setter) {
43
40
  // Install native callback immediately at module load
44
41
  setter(data => {
45
- this.lastValue = data;
42
+ this.eventCount++;
46
43
  for (const listener of this.listeners) {
47
44
  listener(data);
48
45
  }
@@ -64,7 +61,7 @@ class NativeUpdatedValue {
64
61
  * Creates a native value subscription.
65
62
  *
66
63
  * @param setter - Function that sets the native callback property
67
- * @returns The subscription instance with lastValue and addListener
64
+ * @returns The subscription instance
68
65
  * @internal
69
66
  */
70
67
  static emitterize(setter) {
@@ -1 +1 @@
1
- {"version":3,"names":["NativeUpdatedValue","listeners","Set","lastValue","undefined","constructor","setter","data","listener","addListener","callback","add","delete","emitterize","exports"],"sourceRoot":"../../../src","sources":["utils/NativeUpdatedValue.ts"],"mappings":";;;;;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,kBAAkB,CAAI;EACzBC,SAAS,GAAG,IAAIC,GAAG,CAAc,CAAC;;EAE1C;AACF;AACA;AACA;EACEC,SAAS,GAAkBC,SAAS;;EAEpC;EACAC,WAAWA,CAACC,MAA6C,EAAE;IACzD;IACAA,MAAM,CAAEC,IAAO,IAAK;MAClB,IAAI,CAACJ,SAAS,GAAGI,IAAI;MACrB,KAAK,MAAMC,QAAQ,IAAI,IAAI,CAACP,SAAS,EAAE;QACrCO,QAAQ,CAACD,IAAI,CAAC;MAChB;IACF,CAAC,CAAC;EACJ;;EAEA;AACF;AACA;AACA;AACA;AACA;EACEE,WAAWA,CAACC,QAAqB,EAAc;IAC7C,IAAI,CAACT,SAAS,CAACU,GAAG,CAACD,QAAQ,CAAC;IAC5B,OAAO,MAAM,IAAI,CAACT,SAAS,CAACW,MAAM,CAACF,QAAQ,CAAC;EAC9C;;EAEA;AACF;AACA;AACA;AACA;AACA;AACA;EACE,OAAOG,UAAUA,CACfP,MAA6C,EACtB;IACvB,OAAO,IAAIN,kBAAkB,CAACM,MAAM,CAAC;EACvC;AACF;AAACQ,OAAA,CAAAd,kBAAA,GAAAA,kBAAA","ignoreList":[]}
1
+ {"version":3,"names":["NativeUpdatedValue","listeners","Set","eventCount","constructor","setter","data","listener","addListener","callback","add","delete","emitterize","exports"],"sourceRoot":"../../../src","sources":["utils/NativeUpdatedValue.ts"],"mappings":";;;;;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,kBAAkB,CAAI;EACzBC,SAAS,GAAG,IAAIC,GAAG,CAAc,CAAC;;EAE1C;AACF;AACA;AACA;AACA;EACEC,UAAU,GAAG,CAAC;;EAEd;EACAC,WAAWA,CAACC,MAA6C,EAAE;IACzD;IACAA,MAAM,CAAEC,IAAO,IAAK;MAClB,IAAI,CAACH,UAAU,EAAE;MACjB,KAAK,MAAMI,QAAQ,IAAI,IAAI,CAACN,SAAS,EAAE;QACrCM,QAAQ,CAACD,IAAI,CAAC;MAChB;IACF,CAAC,CAAC;EACJ;;EAEA;AACF;AACA;AACA;AACA;AACA;EACEE,WAAWA,CAACC,QAAqB,EAAc;IAC7C,IAAI,CAACR,SAAS,CAACS,GAAG,CAACD,QAAQ,CAAC;IAC5B,OAAO,MAAM,IAAI,CAACR,SAAS,CAACU,MAAM,CAACF,QAAQ,CAAC;EAC9C;;EAEA;AACF;AACA;AACA;AACA;AACA;AACA;EACE,OAAOG,UAAUA,CACfP,MAA6C,EACtB;IACvB,OAAO,IAAIL,kBAAkB,CAACK,MAAM,CAAC;EACvC;AACF;AAACQ,OAAA,CAAAb,kBAAA,GAAAA,kBAAA","ignoreList":[]}
@@ -8,36 +8,28 @@ var _react = require("react");
8
8
  /**
9
9
  * Generic hook for values that are fetched from native and updated via callbacks.
10
10
  *
11
- * Reads the initial value from emitter.lastValue to avoid race conditions between
12
- * initial getter() call and subscription setup.
11
+ * Reads the getter on mount, and again on subscribing only if an event landed
12
+ * since, so a change between render and subscription is not missed.
13
13
  *
14
- * @param getter - Fallback synchronous function to get the current value if emitter has no lastValue yet
15
- * @param emitter - NativeUpdatedValue that stores lastValue and provides subscription
14
+ * @param getter - Synchronous function returning the current value
15
+ * @param emitter - NativeUpdatedValue that provides the subscription
16
16
  * @param eventKey - Optional key to extract from the event object passed to the callback
17
17
  * @returns The current value, updated when the callback fires
18
18
  */
19
19
  function useNativeUpdatedValue(getter, emitter, eventKey) {
20
- const [value, setValue] = (0, _react.useState)(() => {
21
- const {
22
- lastValue
23
- } = emitter;
24
- if (lastValue != null) {
25
- return eventKey !== undefined ? lastValue[eventKey] : lastValue;
26
- }
27
- return getter();
28
- });
20
+ const eventCountAtRender = (0, _react.useRef)(emitter.eventCount);
21
+ const [value, setValue] = (0, _react.useState)(getter);
29
22
  (0, _react.useEffect)(() => {
30
- const {
31
- lastValue
32
- } = emitter;
33
- if (lastValue != null) {
34
- const newValue = eventKey !== undefined ? lastValue[eventKey] : lastValue;
35
- setValue(newValue);
36
- }
23
+ if (emitter.eventCount !== eventCountAtRender.current) setValue(getter);
24
+ // A re-run, for another emitter or eventKey, always reads afresh.
25
+ eventCountAtRender.current = NaN;
37
26
  return emitter.addListener(event => {
38
27
  const newValue = eventKey !== undefined ? event[eventKey] : event;
39
28
  setValue(newValue);
40
29
  });
30
+ // The getter is read once per subscription: an inline one, new each render,
31
+ // would otherwise overwrite every event with a re-read.
32
+ // eslint-disable-next-line react-hooks/exhaustive-deps
41
33
  }, [emitter, eventKey]);
42
34
  return value;
43
35
  }
@@ -1 +1 @@
1
- {"version":3,"names":["_react","require","useNativeUpdatedValue","getter","emitter","eventKey","value","setValue","useState","lastValue","undefined","useEffect","newValue","addListener","event"],"sourceRoot":"../../../src","sources":["utils/useNativeUpdatedValue.ts"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,qBAAqBA,CACnCC,MAAe,EACfC,OAA8B,EAC9BC,QAAkB,EACf;EACH,MAAM,CAACC,KAAK,EAAEC,QAAQ,CAAC,GAAG,IAAAC,eAAQ,EAAC,MAAM;IACvC,MAAM;MAAEC;IAAU,CAAC,GAAGL,OAAO;IAC7B,IAAIK,SAAS,IAAI,IAAI,EAAE;MACrB,OAAQJ,QAAQ,KAAKK,SAAS,GAAGD,SAAS,CAACJ,QAAQ,CAAC,GAAGI,SAAS;IAClE;IACA,OAAON,MAAM,CAAC,CAAC;EACjB,CAAC,CAAC;EAEF,IAAAQ,gBAAS,EAAC,MAAM;IACd,MAAM;MAAEF;IAAU,CAAC,GAAGL,OAAO;IAC7B,IAAIK,SAAS,IAAI,IAAI,EAAE;MACrB,MAAMG,QAAQ,GAAGP,QAAQ,KAAKK,SAAS,GAAGD,SAAS,CAACJ,QAAQ,CAAC,GAAGI,SAAS;MACzEF,QAAQ,CAACK,QAAa,CAAC;IACzB;IACA,OAAOR,OAAO,CAACS,WAAW,CAAEC,KAAK,IAAK;MACpC,MAAMF,QAAQ,GAAGP,QAAQ,KAAKK,SAAS,GAAGI,KAAK,CAACT,QAAQ,CAAC,GAAGS,KAAK;MACjEP,QAAQ,CAACK,QAAa,CAAC;IACzB,CAAC,CAAC;EACJ,CAAC,EAAE,CAACR,OAAO,EAAEC,QAAQ,CAAC,CAAC;EAEvB,OAAOC,KAAK;AACd","ignoreList":[]}
1
+ {"version":3,"names":["_react","require","useNativeUpdatedValue","getter","emitter","eventKey","eventCountAtRender","useRef","eventCount","value","setValue","useState","useEffect","current","NaN","addListener","event","newValue","undefined"],"sourceRoot":"../../../src","sources":["utils/useNativeUpdatedValue.ts"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,qBAAqBA,CACnCC,MAAe,EACfC,OAA8B,EAC9BC,QAAkB,EACf;EACH,MAAMC,kBAAkB,GAAG,IAAAC,aAAM,EAACH,OAAO,CAACI,UAAU,CAAC;EACrD,MAAM,CAACC,KAAK,EAAEC,QAAQ,CAAC,GAAG,IAAAC,eAAQ,EAACR,MAAM,CAAC;EAE1C,IAAAS,gBAAS,EAAC,MAAM;IACd,IAAIR,OAAO,CAACI,UAAU,KAAKF,kBAAkB,CAACO,OAAO,EAAEH,QAAQ,CAACP,MAAM,CAAC;IACvE;IACAG,kBAAkB,CAACO,OAAO,GAAGC,GAAG;IAChC,OAAOV,OAAO,CAACW,WAAW,CAAEC,KAAK,IAAK;MACpC,MAAMC,QAAQ,GAAGZ,QAAQ,KAAKa,SAAS,GAAGF,KAAK,CAACX,QAAQ,CAAC,GAAGW,KAAK;MACjEN,QAAQ,CAACO,QAAa,CAAC;IACzB,CAAC,CAAC;IACF;IACA;IACA;EACF,CAAC,EAAE,CAACb,OAAO,EAAEC,QAAQ,CAAC,CAAC;EAEvB,OAAOI,KAAK;AACd","ignoreList":[]}
@@ -5,25 +5,30 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.useNativeValueRefreshedBy = useNativeValueRefreshedBy;
7
7
  var _react = require("react");
8
+ const eventCountOf = emitters => emitters.reduce((sum, emitter) => sum + emitter.eventCount, 0);
9
+
8
10
  /**
9
11
  * Hook for a native-fetched value that must stay fresh across SEVERAL event
10
12
  * sources — e.g. the active track, which changes on a queue transition
11
13
  * (`onActiveTrackChanged`) but is also mutated in place by a favorite toggle
12
14
  * (`onFavoriteChanged`).
13
15
  *
14
- * Unlike {@link useNativeUpdatedValue}, this never reads a cached event
15
- * payload: every trigger re-reads `getter()`, and the mount effect re-reads
16
- * once after the subscriptions attach (so an event firing between render and
17
- * effect cannot be missed). The getters are cheap synchronous Nitro calls.
16
+ * Every trigger re-reads `getter()`, and the mount effect re-reads it only if
17
+ * an event landed since the render read, so none is missed.
18
18
  *
19
19
  * @param getter - Synchronous native getter for the current value
20
20
  * @param emitters - Event sources that invalidate the value (a stable,
21
21
  * module-level array — identity changes resubscribe)
22
22
  */
23
23
  function useNativeValueRefreshedBy(getter, emitters) {
24
+ const eventCountAtRender = (0, _react.useRef)(eventCountOf(emitters));
24
25
  const [value, setValue] = (0, _react.useState)(getter);
25
26
  (0, _react.useEffect)(() => {
26
- setValue(getter());
27
+ if (eventCountOf(emitters) !== eventCountAtRender.current) {
28
+ setValue(getter());
29
+ }
30
+ // A re-run, for another getter or emitters, always reads afresh.
31
+ eventCountAtRender.current = NaN;
27
32
  const cleanups = emitters.map(emitter => emitter.addListener(() => setValue(getter())));
28
33
  return () => cleanups.forEach(cleanup => cleanup());
29
34
  // eslint-disable-next-line react-hooks/exhaustive-deps
@@ -1 +1 @@
1
- {"version":3,"names":["_react","require","useNativeValueRefreshedBy","getter","emitters","value","setValue","useState","useEffect","cleanups","map","emitter","addListener","forEach","cleanup"],"sourceRoot":"../../../src","sources":["utils/useNativeValueRefreshedBy.ts"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,yBAAyBA,CACvCC,MAAe,EACfC,QAAiC,EAC9B;EACH,MAAM,CAACC,KAAK,EAAEC,QAAQ,CAAC,GAAG,IAAAC,eAAQ,EAACJ,MAAM,CAAC;EAE1C,IAAAK,gBAAS,EAAC,MAAM;IACdF,QAAQ,CAACH,MAAM,CAAC,CAAC,CAAC;IAClB,MAAMM,QAAQ,GAAGL,QAAQ,CAACM,GAAG,CAAEC,OAAO,IACpCA,OAAO,CAACC,WAAW,CAAC,MAAMN,QAAQ,CAACH,MAAM,CAAC,CAAC,CAAC,CAC9C,CAAC;IACD,OAAO,MAAMM,QAAQ,CAACI,OAAO,CAAEC,OAAO,IAAKA,OAAO,CAAC,CAAC,CAAC;IACrD;EACF,CAAC,EAAE,CAACX,MAAM,EAAE,GAAGC,QAAQ,CAAC,CAAC;EAEzB,OAAOC,KAAK;AACd","ignoreList":[]}
1
+ {"version":3,"names":["_react","require","eventCountOf","emitters","reduce","sum","emitter","eventCount","useNativeValueRefreshedBy","getter","eventCountAtRender","useRef","value","setValue","useState","useEffect","current","NaN","cleanups","map","addListener","forEach","cleanup"],"sourceRoot":"../../../src","sources":["utils/useNativeValueRefreshedBy.ts"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAOA,MAAMC,YAAY,GAAIC,QAAiC,IACrDA,QAAQ,CAACC,MAAM,CAAC,CAACC,GAAG,EAAEC,OAAO,KAAKD,GAAG,GAAGC,OAAO,CAACC,UAAU,EAAE,CAAC,CAAC;;AAEhE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,yBAAyBA,CACvCC,MAAe,EACfN,QAAiC,EAC9B;EACH,MAAMO,kBAAkB,GAAG,IAAAC,aAAM,EAACT,YAAY,CAACC,QAAQ,CAAC,CAAC;EACzD,MAAM,CAACS,KAAK,EAAEC,QAAQ,CAAC,GAAG,IAAAC,eAAQ,EAACL,MAAM,CAAC;EAE1C,IAAAM,gBAAS,EAAC,MAAM;IACd,IAAIb,YAAY,CAACC,QAAQ,CAAC,KAAKO,kBAAkB,CAACM,OAAO,EAAE;MACzDH,QAAQ,CAACJ,MAAM,CAAC,CAAC,CAAC;IACpB;IACA;IACAC,kBAAkB,CAACM,OAAO,GAAGC,GAAG;IAChC,MAAMC,QAAQ,GAAGf,QAAQ,CAACgB,GAAG,CAAEb,OAAO,IACpCA,OAAO,CAACc,WAAW,CAAC,MAAMP,QAAQ,CAACJ,MAAM,CAAC,CAAC,CAAC,CAC9C,CAAC;IACD,OAAO,MAAMS,QAAQ,CAACG,OAAO,CAAEC,OAAO,IAAKA,OAAO,CAAC,CAAC,CAAC;IACrD;EACF,CAAC,EAAE,CAACb,MAAM,EAAE,GAAGN,QAAQ,CAAC,CAAC;EAEzB,OAAOS,KAAK;AACd","ignoreList":[]}
@@ -39,8 +39,8 @@ error until it was unified.
39
39
  Two emitter classes, picked by what the event _is_:
40
40
 
41
41
  - `NativeUpdatedValue` — state with a current value (playback, options,
42
- progress). Subscribes to native at module load so no update is missed, and
43
- caches `lastValue` so hooks can read synchronously.
42
+ progress). Subscribes to native at module load so no update is missed; hooks
43
+ read the matching getter, never a cached payload.
44
44
  - `LazyNativeEmitter` — discrete events with no current value (remote controls,
45
45
  gate hits). Assigns the native callback on the first `addListener`, so an
46
46
  event nobody listens to costs nothing.
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
 
3
- import { useEffect, useState } from 'react';
3
+ import { useEffect, useRef, useState } from 'react';
4
4
  import { nativeBrowser } from '../native';
5
5
  import { NativeUpdatedValue } from '../utils/NativeUpdatedValue';
6
6
 
@@ -85,15 +85,12 @@ export const onSleepTimerChanged = NativeUpdatedValue.emitterize(cb => nativeBro
85
85
  * @returns true if any sleep timer is active, false otherwise
86
86
  */
87
87
  export function useSleepTimerActive() {
88
+ const eventCountAtRender = useRef(onSleepTimerChanged.eventCount);
88
89
  const [isActive, setIsActive] = useState(() => getSleepTimer() !== null);
89
90
  useEffect(() => {
90
- // Re-sync before subscribing: a change between the initial read above and this effect would
91
- // otherwise be missed for good. `undefined` means nothing has fired yet, whereas `null` is a
92
- // real value — the timer being cleared — so it has to re-sync too.
93
- const {
94
- lastValue
95
- } = onSleepTimerChanged;
96
- if (lastValue !== undefined) setIsActive(lastValue !== null);
91
+ if (onSleepTimerChanged.eventCount !== eventCountAtRender.current) {
92
+ setIsActive(getSleepTimer() !== null);
93
+ }
97
94
  return onSleepTimerChanged.addListener(timer => {
98
95
  setIsActive(timer !== null);
99
96
  });
@@ -114,17 +111,16 @@ export function useSleepTimerActive() {
114
111
  export function useSleepTimer(params) {
115
112
  const updateInterval = params?.updateInterval ?? 1000;
116
113
  const inactive = params?.inactive ?? false;
114
+ const eventCountAtRender = useRef(onSleepTimerChanged.eventCount);
117
115
  const [state, setState] = useState(() => {
118
116
  const timerState = getSleepTimer();
119
117
  return addSecondsLeft(timerState);
120
118
  });
121
119
  const time = state && 'time' in state ? state.time : undefined;
122
120
  useEffect(() => {
123
- // Re-sync before subscribing — see useSleepTimerActive.
124
- const {
125
- lastValue
126
- } = onSleepTimerChanged;
127
- if (lastValue !== undefined) setState(addSecondsLeft(lastValue));
121
+ if (onSleepTimerChanged.eventCount !== eventCountAtRender.current) {
122
+ setState(addSecondsLeft(getSleepTimer()));
123
+ }
128
124
  return onSleepTimerChanged.addListener(event => {
129
125
  setState(addSecondsLeft(event));
130
126
  });
@@ -1 +1 @@
1
- {"version":3,"names":["useEffect","useState","nativeBrowser","NativeUpdatedValue","getSleepTimer","setSleepTimer","seconds","options","fadeDuration","setSleepTimerToEndOfTrack","clearSleepTimer","onSleepTimerChanged","emitterize","cb","useSleepTimerActive","isActive","setIsActive","lastValue","undefined","addListener","timer","useSleepTimer","params","updateInterval","inactive","state","setState","timerState","addSecondsLeft","time","event","update","sleepTimer","result","secondsLeft","clear","initialTimeoutId","setTimeout","intervalId","setInterval","clearTimeout","clearInterval","Math","max","round","Date","now"],"sourceRoot":"../../../src","sources":["features/sleepTimer.ts"],"mappings":";;AAAA,SAASA,SAAS,EAAEC,QAAQ,QA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IACN,CAAC;QACD,IAAIC,MAAM,IAAI,aAAa,IAAIA,MAAM,IAAIA,MAAM,CAACC,WAAW,KAAK,CAAC,EAAE;UACjEC,KAAK,CAAC,CAAC;QACT;QACA,OAAOF,MAAM;MACf,CAAC,CAAC;IACJ,CAAC;;IAED;IACA;IACA,MAAMG,gBAAgB,GAAGC,UAAU,CACjC,MAAM;MACJN,MAAM,CAAC,CAAC;MACRO,UAAU,GAAGC,WAAW,CAACR,MAAM,EAAER,cAAc,CAAC;IAClD,CAAC,EACDA,cAAc,GAAIM,IAAI,GAAGN,cAC3B,CAAC;IACD,IAAIe,UAAsD;IAC1D,MAAMH,KAAK,GAAGA,CAAA,KAAM;MAClBK,YAAY,CAACJ,gBAAgB,CAAC;MAC9B,IAAIE,UAAU,EAAEG,aAAa,CAACH,UAAU,CAAC;IAC3C,CAAC;IACDP,MAAM,CAAC,CAAC;IACR,OAAOI,KAAK;EACd,CAAC,EAAE,CAACX,QAAQ,EAAEK,IAAI,EAAEN,cAAc,CAAC,CAAC;EAEpC,OAAOE,KAAK;AACd;;AAEA;;AAEA;AACA;AACA;AACA;AACA;;AAKA,SAASG,cAAcA,CAACH,KAAiB,EAA+B;EACtE,IAAI,CAACA,KAAK,EAAE,OAAOP,SAAS;EAC5B,IAAI,MAAM,IAAIO,KAAK,EAAE;IACnB,OAAO;MACL,GAAGA,KAAK;MACRS,WAAW,EAAEQ,IAAI,CAACC,GAAG,CAAC,CAAC,EAAED,IAAI,CAACE,KAAK,CAAC,CAACnB,KAAK,CAACI,IAAI,GAAGgB,IAAI,CAACC,GAAG,CAAC,CAAC,IAAI,IAAI,CAAC;IACvE,CAAC;EACH;EACA,OAAOrB,KAAK;AACd","ignoreList":[]}
1
+ {"version":3,"names":["useEffect","useRef","useState","nativeBrowser","NativeUpdatedValue","getSleepTimer","setSleepTimer","seconds","options","fadeDuration","setSleepTimerToEndOfTrack","clearSleepTimer","onSleepTimerChanged","emitterize","cb","useSleepTimerActive","eventCountAtRender","eventCount","isActive","setIsActive","current","addListener","timer","useSleepTimer","params","updateInterval","inactive","state","setState","timerState","addSecondsLeft","time","undefined","event","update","sleepTimer","result","secondsLeft","clear","initialTimeoutId","setTimeout","intervalId","setInterval","clearTimeout","clearInterval","Math","max","round","Date","now"],"sourceRoot":"../../../src","sources":["features/sleepTimer.ts"],"mappings":";;AAAA,SAASA,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AACnD,SAASC,aAAa,QAAQ,WAAW;AACzC,SAASC,kBAAkB,QAAQ,6BAA6B;;AAEhE;;AAEA;AACA;AACA;;AAMA;AACA;AACA;;AAMA;AACA;AACA;AACA;AACA;AACA;;AAGA;AACA;AACA;AACA;;AAGA;;AAEA;AACA;AACA;AACA,OAAO,SAASC,aAAaA,CAAA,EAAe;EAC1C,OAAOF,aAAa,CAACE,aAAa,CAAC,CAAC;AACtC;;AAEA;AACA;AACA;;AAaA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,aAAaA,CAC3BC,OAAe,EACfC,OAA2B,EACrB;EACNL,aAAa,CAACG,aAAa,CAACC,OAAO,EAAEC,OAAO,EAAEC,YAAY,CAAC;AAC7D;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,yBAAyBA,CAAA,EAAS;EAChDP,aAAa,CAACO,yBAAyB,CAAC,CAAC;AAC3C;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAASC,eAAeA,CAAA,EAAY;EACzC,OAAOR,aAAa,CAACQ,eAAe,CAAC,CAAC;AACxC;;AAEA;;AAEA;AACA;AACA;AACA;AACA,OAAO,MAAMC,mBAAmB,GAAGR,kBAAkB,CAACS,UAAU,CAC7DC,EAAE,IAAMX,aAAa,CAACS,mBAAmB,GAAGE,EAC/C,CAAC;;AAED;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,mBAAmBA,CAAA,EAAY;EAC7C,MAAMC,kBAAkB,GAAGf,MAAM,CAACW,mBAAmB,CA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K;MACRU,WAAW,EAAEQ,IAAI,CAACC,GAAG,CAAC,CAAC,EAAED,IAAI,CAACE,KAAK,CAAC,CAACpB,KAAK,CAACI,IAAI,GAAGiB,IAAI,CAACC,GAAG,CAAC,CAAC,IAAI,IAAI,CAAC;IACvE,CAAC;EACH;EACA,OAAOtB,KAAK;AACd","ignoreList":[]}
@@ -5,9 +5,9 @@
5
5
  * `onRemoteSeek`, …) and `onGate`. Subscribe with {@link addListener}; the
6
6
  * returned function unsubscribes. The emitter is not callable itself.
7
7
  *
8
- * Native starts delivering the event only once the first listener is added,
9
- * and nothing is cached: there is no `lastValue`. The other `on*` exports use
10
- * `NativeUpdatedValue`, which listens from module load.
8
+ * Native starts delivering the event only once the first listener is added.
9
+ * The other `on*` exports use `NativeUpdatedValue`, which listens from module
10
+ * load.
11
11
  *
12
12
  * @example
13
13
  * ```typescript
@@ -5,14 +5,10 @@
5
5
  * `onQueueChanged`, `onTrackMetadata`, …). Subscribe with {@link addListener};
6
6
  * the returned function unsubscribes. The emitter is not callable itself.
7
7
  *
8
- * It listens to native from module load and keeps the latest payload in
9
- * {@link lastValue}. The remote-control exports and `onGate` use
10
- * `LazyNativeEmitter`, which listens only once a listener is added.
11
- *
12
- * `lastValue` is the last payload native sent, not a fresh reading: it is
13
- * `undefined` before the first event, and for the queue and active track it
14
- * can be stale after an in-place change (a favorite toggle). Use the getter
15
- * (`getQueue`, `getActiveTrack`, …) when you need the current value.
8
+ * It listens to native from module load. The remote-control exports and
9
+ * `onGate` use `LazyNativeEmitter`, which listens only once a listener is
10
+ * added. It keeps no payload: use the getter (`getQueue`, `getActiveTrack`, …)
11
+ * for the current value.
16
12
  *
17
13
  * @example
18
14
  * ```typescript
@@ -29,16 +25,17 @@ export class NativeUpdatedValue {
29
25
  listeners = new Set();
30
26
 
31
27
  /**
32
- * The last payload native sent, or `undefined` before the first. Not a fresh
33
- * reading: use the matching getter (`getQueue`, …) for the current value.
28
+ * Events received so far, so a hook can tell whether one landed between its
29
+ * render and its subscription.
30
+ * @internal
34
31
  */
35
- lastValue = undefined;
32
+ eventCount = 0;
36
33
 
37
34
  /** @internal */
38
35
  constructor(setter) {
39
36
  // Install native callback immediately at module load
40
37
  setter(data => {
41
- this.lastValue = data;
38
+ this.eventCount++;
42
39
  for (const listener of this.listeners) {
43
40
  listener(data);
44
41
  }
@@ -60,7 +57,7 @@ export class NativeUpdatedValue {
60
57
  * Creates a native value subscription.
61
58
  *
62
59
  * @param setter - Function that sets the native callback property
63
- * @returns The subscription instance with lastValue and addListener
60
+ * @returns The subscription instance
64
61
  * @internal
65
62
  */
66
63
  static emitterize(setter) {
@@ -1 +1 @@
1
- {"version":3,"names":["NativeUpdatedValue","listeners","Set","lastValue","undefined","constructor","setter","data","listener","addListener","callback","add","delete","emitterize"],"sourceRoot":"../../../src","sources":["utils/NativeUpdatedValue.ts"],"mappings":";;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMA,kBAAkB,CAAI;EACzBC,SAAS,GAAG,IAAIC,GAAG,CAAc,CAAC;;EAE1C;AACF;AACA;AACA;EACEC,SAAS,GAAkBC,SAAS;;EAEpC;EACAC,WAAWA,CAACC,MAA6C,EAAE;IACzD;IACAA,MAAM,CAAEC,IAAO,IAAK;MAClB,IAAI,CAACJ,SAAS,GAAGI,IAAI;MACrB,KAAK,MAAMC,QAAQ,IAAI,IAAI,CAACP,SAAS,EAAE;QACrCO,QAAQ,CAACD,IAAI,CAAC;MAChB;IACF,CAAC,CAAC;EACJ;;EAEA;AACF;AACA;AACA;AACA;AACA;EACEE,WAAWA,CAACC,QAAqB,EAAc;IAC7C,IAAI,CAACT,SAAS,CAACU,GAAG,CAACD,QAAQ,CAAC;IAC5B,OAAO,MAAM,IAAI,CAACT,SAAS,CAACW,MAAM,CAACF,QAAQ,CAAC;EAC9C;;EAEA;AACF;AACA;AACA;AACA;AACA;AACA;EACE,OAAOG,UAAUA,CACfP,MAA6C,EACtB;IACvB,OAAO,IAAIN,kBAAkB,CAACM,MAAM,CAAC;EACvC;AACF","ignoreList":[]}
1
+ {"version":3,"names":["NativeUpdatedValue","listeners","Set","eventCount","constructor","setter","data","listener","addListener","callback","add","delete","emitterize"],"sourceRoot":"../../../src","sources":["utils/NativeUpdatedValue.ts"],"mappings":";;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMA,kBAAkB,CAAI;EACzBC,SAAS,GAAG,IAAIC,GAAG,CAAc,CAAC;;EAE1C;AACF;AACA;AACA;AACA;EACEC,UAAU,GAAG,CAAC;;EAEd;EACAC,WAAWA,CAACC,MAA6C,EAAE;IACzD;IACAA,MAAM,CAAEC,IAAO,IAAK;MAClB,IAAI,CAACH,UAAU,EAAE;MACjB,KAAK,MAAMI,QAAQ,IAAI,IAAI,CAACN,SAAS,EAAE;QACrCM,QAAQ,CAACD,IAAI,CAAC;MAChB;IACF,CAAC,CAAC;EACJ;;EAEA;AACF;AACA;AACA;AACA;AACA;EACEE,WAAWA,CAACC,QAAqB,EAAc;IAC7C,IAAI,CAACR,SAAS,CAACS,GAAG,CAACD,QAAQ,CAAC;IAC5B,OAAO,MAAM,IAAI,CAACR,SAAS,CAACU,MAAM,CAACF,QAAQ,CAAC;EAC9C;;EAEA;AACF;AACA;AACA;AACA;AACA;AACA;EACE,OAAOG,UAAUA,CACfP,MAA6C,EACtB;IACvB,OAAO,IAAIL,kBAAkB,CAACK,MAAM,CAAC;EACvC;AACF","ignoreList":[]}
@@ -1,39 +1,31 @@
1
1
  "use strict";
2
2
 
3
- import { useEffect, useState } from 'react';
3
+ import { useEffect, useRef, useState } from 'react';
4
4
  /**
5
5
  * Generic hook for values that are fetched from native and updated via callbacks.
6
6
  *
7
- * Reads the initial value from emitter.lastValue to avoid race conditions between
8
- * initial getter() call and subscription setup.
7
+ * Reads the getter on mount, and again on subscribing only if an event landed
8
+ * since, so a change between render and subscription is not missed.
9
9
  *
10
- * @param getter - Fallback synchronous function to get the current value if emitter has no lastValue yet
11
- * @param emitter - NativeUpdatedValue that stores lastValue and provides subscription
10
+ * @param getter - Synchronous function returning the current value
11
+ * @param emitter - NativeUpdatedValue that provides the subscription
12
12
  * @param eventKey - Optional key to extract from the event object passed to the callback
13
13
  * @returns The current value, updated when the callback fires
14
14
  */
15
15
  export function useNativeUpdatedValue(getter, emitter, eventKey) {
16
- const [value, setValue] = useState(() => {
17
- const {
18
- lastValue
19
- } = emitter;
20
- if (lastValue != null) {
21
- return eventKey !== undefined ? lastValue[eventKey] : lastValue;
22
- }
23
- return getter();
24
- });
16
+ const eventCountAtRender = useRef(emitter.eventCount);
17
+ const [value, setValue] = useState(getter);
25
18
  useEffect(() => {
26
- const {
27
- lastValue
28
- } = emitter;
29
- if (lastValue != null) {
30
- const newValue = eventKey !== undefined ? lastValue[eventKey] : lastValue;
31
- setValue(newValue);
32
- }
19
+ if (emitter.eventCount !== eventCountAtRender.current) setValue(getter);
20
+ // A re-run, for another emitter or eventKey, always reads afresh.
21
+ eventCountAtRender.current = NaN;
33
22
  return emitter.addListener(event => {
34
23
  const newValue = eventKey !== undefined ? event[eventKey] : event;
35
24
  setValue(newValue);
36
25
  });
26
+ // The getter is read once per subscription: an inline one, new each render,
27
+ // would otherwise overwrite every event with a re-read.
28
+ // eslint-disable-next-line react-hooks/exhaustive-deps
37
29
  }, [emitter, eventKey]);
38
30
  return value;
39
31
  }
@@ -1 +1 @@
1
- {"version":3,"names":["useEffect","useState","useNativeUpdatedValue","getter","emitter","eventKey","value","setValue","lastValue","undefined","newValue","addListener","event"],"sourceRoot":"../../../src","sources":["utils/useNativeUpdatedValue.ts"],"mappings":";;AAAA,SAASA,SAAS,EAAEC,QAAQ,QAAQ,OAAO;AAG3C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,qBAAqBA,CACnCC,MAAe,EACfC,OAA8B,EAC9BC,QAAkB,EACf;EACH,MAAM,CAACC,KAAK,EAAEC,QAAQ,CAAC,GAAGN,QAAQ,CAAC,MAAM;IACvC,MAAM;MAAEO;IAAU,CAAC,GAAGJ,OAAO;IAC7B,IAAII,SAAS,IAAI,IAAI,EAAE;MACrB,OAAQH,QAAQ,KAAKI,SAAS,GAAGD,SAAS,CAACH,QAAQ,CAAC,GAAGG,SAAS;IAClE;IACA,OAAOL,MAAM,CAAC,CAAC;EACjB,CAAC,CAAC;EAEFH,SAAS,CAAC,MAAM;IACd,MAAM;MAAEQ;IAAU,CAAC,GAAGJ,OAAO;IAC7B,IAAII,SAAS,IAAI,IAAI,EAAE;MACrB,MAAME,QAAQ,GAAGL,QAAQ,KAAKI,SAAS,GAAGD,SAAS,CAACH,QAAQ,CAAC,GAAGG,SAAS;MACzED,QAAQ,CAACG,QAAa,CAAC;IACzB;IACA,OAAON,OAAO,CAACO,WAAW,CAAEC,KAAK,IAAK;MACpC,MAAMF,QAAQ,GAAGL,QAAQ,KAAKI,SAAS,GAAGG,KAAK,CAACP,QAAQ,CAAC,GAAGO,KAAK;MACjEL,QAAQ,CAACG,QAAa,CAAC;IACzB,CAAC,CAAC;EACJ,CAAC,EAAE,CAACN,OAAO,EAAEC,QAAQ,CAAC,CAAC;EAEvB,OAAOC,KAAK;AACd","ignoreList":[]}
1
+ {"version":3,"names":["useEffect","useRef","useState","useNativeUpdatedValue","getter","emitter","eventKey","eventCountAtRender","eventCount","value","setValue","current","NaN","addListener","event","newValue","undefined"],"sourceRoot":"../../../src","sources":["utils/useNativeUpdatedValue.ts"],"mappings":";;AAAA,SAASA,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AAGnD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,qBAAqBA,CACnCC,MAAe,EACfC,OAA8B,EAC9BC,QAAkB,EACf;EACH,MAAMC,kBAAkB,GAAGN,MAAM,CAACI,OAAO,CAACG,UAAU,CAAC;EACrD,MAAM,CAACC,KAAK,EAAEC,QAAQ,CAAC,GAAGR,QAAQ,CAACE,MAAM,CAAC;EAE1CJ,SAAS,CAAC,MAAM;IACd,IAAIK,OAAO,CAACG,UAAU,KAAKD,kBAAkB,CAACI,OAAO,EAAED,QAAQ,CAACN,MAAM,CAAC;IACvE;IACAG,kBAAkB,CAACI,OAAO,GAAGC,GAAG;IAChC,OAAOP,OAAO,CAACQ,WAAW,CAAEC,KAAK,IAAK;MACpC,MAAMC,QAAQ,GAAGT,QAAQ,KAAKU,SAAS,GAAGF,KAAK,CAACR,QAAQ,CAAC,GAAGQ,KAAK;MACjEJ,QAAQ,CAACK,QAAa,CAAC;IACzB,CAAC,CAAC;IACF;IACA;IACA;EACF,CAAC,EAAE,CAACV,OAAO,EAAEC,QAAQ,CAAC,CAAC;EAEvB,OAAOG,KAAK;AACd","ignoreList":[]}
@@ -1,25 +1,30 @@
1
1
  "use strict";
2
2
 
3
- import { useEffect, useState } from 'react';
3
+ import { useEffect, useRef, useState } from 'react';
4
+ const eventCountOf = emitters => emitters.reduce((sum, emitter) => sum + emitter.eventCount, 0);
5
+
4
6
  /**
5
7
  * Hook for a native-fetched value that must stay fresh across SEVERAL event
6
8
  * sources — e.g. the active track, which changes on a queue transition
7
9
  * (`onActiveTrackChanged`) but is also mutated in place by a favorite toggle
8
10
  * (`onFavoriteChanged`).
9
11
  *
10
- * Unlike {@link useNativeUpdatedValue}, this never reads a cached event
11
- * payload: every trigger re-reads `getter()`, and the mount effect re-reads
12
- * once after the subscriptions attach (so an event firing between render and
13
- * effect cannot be missed). The getters are cheap synchronous Nitro calls.
12
+ * Every trigger re-reads `getter()`, and the mount effect re-reads it only if
13
+ * an event landed since the render read, so none is missed.
14
14
  *
15
15
  * @param getter - Synchronous native getter for the current value
16
16
  * @param emitters - Event sources that invalidate the value (a stable,
17
17
  * module-level array — identity changes resubscribe)
18
18
  */
19
19
  export function useNativeValueRefreshedBy(getter, emitters) {
20
+ const eventCountAtRender = useRef(eventCountOf(emitters));
20
21
  const [value, setValue] = useState(getter);
21
22
  useEffect(() => {
22
- setValue(getter());
23
+ if (eventCountOf(emitters) !== eventCountAtRender.current) {
24
+ setValue(getter());
25
+ }
26
+ // A re-run, for another getter or emitters, always reads afresh.
27
+ eventCountAtRender.current = NaN;
23
28
  const cleanups = emitters.map(emitter => emitter.addListener(() => setValue(getter())));
24
29
  return () => cleanups.forEach(cleanup => cleanup());
25
30
  // eslint-disable-next-line react-hooks/exhaustive-deps
@@ -1 +1 @@
1
- {"version":3,"names":["useEffect","useState","useNativeValueRefreshedBy","getter","emitters","value","setValue","cleanups","map","emitter","addListener","forEach","cleanup"],"sourceRoot":"../../../src","sources":["utils/useNativeValueRefreshedBy.ts"],"mappings":";;AAAA,SAASA,SAAS,EAAEC,QAAQ,QAAQ,OAAO;AAM3C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,yBAAyBA,CACvCC,MAAe,EACfC,QAAiC,EAC9B;EACH,MAAM,CAACC,KAAK,EAAEC,QAAQ,CAAC,GAAGL,QAAQ,CAACE,MAAM,CAAC;EAE1CH,SAAS,CAAC,MAAM;IACdM,QAAQ,CAACH,MAAM,CAAC,CAAC,CAAC;IAClB,MAAMI,QAAQ,GAAGH,QAAQ,CAACI,GAAG,CAAEC,OAAO,IACpCA,OAAO,CAACC,WAAW,CAAC,MAAMJ,QAAQ,CAACH,MAAM,CAAC,CAAC,CAAC,CAC9C,CAAC;IACD,OAAO,MAAMI,QAAQ,CAACI,OAAO,CAAEC,OAAO,IAAKA,OAAO,CAAC,CAAC,CAAC;IACrD;EACF,CAAC,EAAE,CAACT,MAAM,EAAE,GAAGC,QAAQ,CAAC,CAAC;EAEzB,OAAOC,KAAK;AACd","ignoreList":[]}
1
+ {"version":3,"names":["useEffect","useRef","useState","eventCountOf","emitters","reduce","sum","emitter","eventCount","useNativeValueRefreshedBy","getter","eventCountAtRender","value","setValue","current","NaN","cleanups","map","addListener","forEach","cleanup"],"sourceRoot":"../../../src","sources":["utils/useNativeValueRefreshedBy.ts"],"mappings":";;AAAA,SAASA,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AAOnD,MAAMC,YAAY,GAAIC,QAAiC,IACrDA,QAAQ,CAACC,MAAM,CAAC,CAACC,GAAG,EAAEC,OAAO,KAAKD,GAAG,GAAGC,OAAO,CAACC,UAAU,EAAE,CAAC,CAAC;;AAEhE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,yBAAyBA,CACvCC,MAAe,EACfN,QAAiC,EAC9B;EACH,MAAMO,kBAAkB,GAAGV,MAAM,CAACE,YAAY,CAACC,QAAQ,CAAC,CAAC;EACzD,MAAM,CAACQ,KAAK,EAAEC,QAAQ,CAAC,GAAGX,QAAQ,CAACQ,MAAM,CAAC;EAE1CV,SAAS,CAAC,MAAM;IACd,IAAIG,YAAY,CAACC,QAAQ,CAAC,KAAKO,kBAAkB,CAACG,OAAO,EAAE;MACzDD,QAAQ,CAACH,MAAM,CAAC,CAAC,CAAC;IACpB;IACA;IACAC,kBAAkB,CAACG,OAAO,GAAGC,GAAG;IAChC,MAAMC,QAAQ,GAAGZ,QAAQ,CAACa,GAAG,CAAEV,OAAO,IACpCA,OAAO,CAACW,WAAW,CAAC,MAAML,QAAQ,CAACH,MAAM,CAAC,CAAC,CAAC,CAC9C,CAAC;IACD,OAAO,MAAMM,QAAQ,CAACG,OAAO,CAAEC,OAAO,IAAKA,OAAO,CAAC,CAAC,CAAC;IACrD;EACF,CAAC,EAAE,CAACV,MAAM,EAAE,GAAGN,QAAQ,CAAC,CAAC;EAEzB,OAAOQ,KAAK;AACd","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"sleepTimer.d.ts","sourceRoot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;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,GACrC;IAAE,oBAAoB,EAAE,OAAO,CAAA;CAAE,CAAA"}
@@ -4,9 +4,9 @@ type Callback<T> = (arg: T) => void;
4
4
  * `onRemoteSeek`, …) and `onGate`. Subscribe with {@link addListener}; the
5
5
  * returned function unsubscribes. The emitter is not callable itself.
6
6
  *
7
- * Native starts delivering the event only once the first listener is added,
8
- * and nothing is cached: there is no `lastValue`. The other `on*` exports use
9
- * `NativeUpdatedValue`, which listens from module load.
7
+ * Native starts delivering the event only once the first listener is added.
8
+ * The other `on*` exports use `NativeUpdatedValue`, which listens from module
9
+ * load.
10
10
  *
11
11
  * @example
12
12
  * ```typescript
@@ -4,14 +4,10 @@ type Callback<T> = (arg: T) => void;
4
4
  * `onQueueChanged`, `onTrackMetadata`, …). Subscribe with {@link addListener};
5
5
  * the returned function unsubscribes. The emitter is not callable itself.
6
6
  *
7
- * It listens to native from module load and keeps the latest payload in
8
- * {@link lastValue}. The remote-control exports and `onGate` use
9
- * `LazyNativeEmitter`, which listens only once a listener is added.
10
- *
11
- * `lastValue` is the last payload native sent, not a fresh reading: it is
12
- * `undefined` before the first event, and for the queue and active track it
13
- * can be stale after an in-place change (a favorite toggle). Use the getter
14
- * (`getQueue`, `getActiveTrack`, …) when you need the current value.
7
+ * It listens to native from module load. The remote-control exports and
8
+ * `onGate` use `LazyNativeEmitter`, which listens only once a listener is
9
+ * added. It keeps no payload: use the getter (`getQueue`, `getActiveTrack`, …)
10
+ * for the current value.
15
11
  *
16
12
  * @example
17
13
  * ```typescript
@@ -26,11 +22,6 @@ type Callback<T> = (arg: T) => void;
26
22
  */
27
23
  export declare class NativeUpdatedValue<T> {
28
24
  private listeners;
29
- /**
30
- * The last payload native sent, or `undefined` before the first. Not a fresh
31
- * reading: use the matching getter (`getQueue`, …) for the current value.
32
- */
33
- lastValue: T | undefined;
34
25
  /**
35
26
  * Subscribes to value changes.
36
27
  *
@@ -1 +1 @@
1
- {"version":3,"file":"NativeUpdatedValue.d.ts","sourceRoot":"","sources":["../../../../src/utils/NativeUpdatedValue.ts"],"names":[],"mappings":"AAAA,KAAK,QAAQ,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,KAAK,IAAI,CAAA;AAEnC;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,qBAAa,kBAAkB,CAAC,CAAC;IAC/B,OAAO,CAAC,SAAS,CAAyB;IAE1C;;;OAGG;IACH,SAAS,EAAE,CAAC,GAAG,SAAS,CAAY;IAapC;;;;;OAKG;IACH,WAAW,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,MAAM,IAAI,CAG7C;CAcF"}
1
+ {"version":3,"file":"NativeUpdatedValue.d.ts","sourceRoot":"","sources":["../../../../src/utils/NativeUpdatedValue.ts"],"names":[],"mappings":"AAAA,KAAK,QAAQ,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,KAAK,IAAI,CAAA;AAEnC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBAAa,kBAAkB,CAAC,CAAC;IAC/B,OAAO,CAAC,SAAS,CAAyB;IAoB1C;;;;;OAKG;IACH,WAAW,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,MAAM,IAAI,CAG7C;CAcF"}
@@ -2,11 +2,11 @@ import { NativeUpdatedValue } from './NativeUpdatedValue';
2
2
  /**
3
3
  * Generic hook for values that are fetched from native and updated via callbacks.
4
4
  *
5
- * Reads the initial value from emitter.lastValue to avoid race conditions between
6
- * initial getter() call and subscription setup.
5
+ * Reads the getter on mount, and again on subscribing only if an event landed
6
+ * since, so a change between render and subscription is not missed.
7
7
  *
8
- * @param getter - Fallback synchronous function to get the current value if emitter has no lastValue yet
9
- * @param emitter - NativeUpdatedValue that stores lastValue and provides subscription
8
+ * @param getter - Synchronous function returning the current value
9
+ * @param emitter - NativeUpdatedValue that provides the subscription
10
10
  * @param eventKey - Optional key to extract from the event object passed to the callback
11
11
  * @returns The current value, updated when the callback fires
12
12
  */
@@ -1 +1 @@
1
- {"version":3,"file":"useNativeUpdatedValue.d.ts","sourceRoot":"","sources":["../../../../src/utils/useNativeUpdatedValue.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AAEzD;;;;;;;;;;GAUG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,EAC5C,MAAM,EAAE,MAAM,CAAC,EACf,OAAO,EAAE,kBAAkB,CAAC,CAAC,CAAC,EAC9B,QAAQ,CAAC,EAAE,MAAM,CAAC,GACjB,CAAC,CAsBH"}
1
+ {"version":3,"file":"useNativeUpdatedValue.d.ts","sourceRoot":"","sources":["../../../../src/utils/useNativeUpdatedValue.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AAEzD;;;;;;;;;;GAUG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,EAC5C,MAAM,EAAE,MAAM,CAAC,EACf,OAAO,EAAE,kBAAkB,CAAC,CAAC,CAAC,EAC9B,QAAQ,CAAC,EAAE,MAAM,CAAC,GACjB,CAAC,CAkBH"}
@@ -1,5 +1,6 @@
1
1
  type Subscribable = {
2
2
  addListener(callback: (event: unknown) => void): () => void;
3
+ eventCount: number;
3
4
  };
4
5
  /**
5
6
  * Hook for a native-fetched value that must stay fresh across SEVERAL event
@@ -7,10 +8,8 @@ type Subscribable = {
7
8
  * (`onActiveTrackChanged`) but is also mutated in place by a favorite toggle
8
9
  * (`onFavoriteChanged`).
9
10
  *
10
- * Unlike {@link useNativeUpdatedValue}, this never reads a cached event
11
- * payload: every trigger re-reads `getter()`, and the mount effect re-reads
12
- * once after the subscriptions attach (so an event firing between render and
13
- * effect cannot be missed). The getters are cheap synchronous Nitro calls.
11
+ * Every trigger re-reads `getter()`, and the mount effect re-reads it only if
12
+ * an event landed since the render read, so none is missed.
14
13
  *
15
14
  * @param getter - Synchronous native getter for the current value
16
15
  * @param emitters - Event sources that invalidate the value (a stable,
@@ -1 +1 @@
1
- {"version":3,"file":"useNativeValueRefreshedBy.d.ts","sourceRoot":"","sources":["../../../../src/utils/useNativeValueRefreshedBy.ts"],"names":[],"mappings":"AAEA,KAAK,YAAY,GAAG;IAClB,WAAW,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,GAAG,MAAM,IAAI,CAAA;CAC5D,CAAA;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,yBAAyB,CAAC,CAAC,EACzC,MAAM,EAAE,MAAM,CAAC,EACf,QAAQ,EAAE,SAAS,YAAY,EAAE,GAChC,CAAC,CAaH"}
1
+ {"version":3,"file":"useNativeValueRefreshedBy.d.ts","sourceRoot":"","sources":["../../../../src/utils/useNativeValueRefreshedBy.ts"],"names":[],"mappings":"AAEA,KAAK,YAAY,GAAG;IAClB,WAAW,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,GAAG,MAAM,IAAI,CAAA;IAC3D,UAAU,EAAE,MAAM,CAAA;CACnB,CAAA;AAKD;;;;;;;;;;;;GAYG;AACH,wBAAgB,yBAAyB,CAAC,CAAC,EACzC,MAAM,EAAE,MAAM,CAAC,EACf,QAAQ,EAAE,SAAS,YAAY,EAAE,GAChC,CAAC,CAkBH"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-audio-browser",
3
- "version": "0.2.0-next.61",
3
+ "version": "0.2.0-next.63",
4
4
  "description": "react-native-audio-browser is a react native package built with Nitro",
5
5
  "keywords": [
6
6
  "react-native",
package/src/CLAUDE.md CHANGED
@@ -39,8 +39,8 @@ error until it was unified.
39
39
  Two emitter classes, picked by what the event _is_:
40
40
 
41
41
  - `NativeUpdatedValue` — state with a current value (playback, options,
42
- progress). Subscribes to native at module load so no update is missed, and
43
- caches `lastValue` so hooks can read synchronously.
42
+ progress). Subscribes to native at module load so no update is missed; hooks
43
+ read the matching getter, never a cached payload.
44
44
  - `LazyNativeEmitter` — discrete events with no current value (remote controls,
45
45
  gate hits). Assigns the native callback on the first `addListener`, so an
46
46
  event nobody listens to costs nothing.