@chipmobilesdk/rn-core 0.0.0 → 0.2.0
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/CHANGELOG.md +115 -0
- package/lib/commonjs/diagnostics/index.js +81 -0
- package/lib/commonjs/diagnostics/index.js.map +1 -0
- package/lib/commonjs/errors/index.js +86 -0
- package/lib/commonjs/errors/index.js.map +1 -0
- package/lib/commonjs/index.js +305 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/intl/index.js +98 -0
- package/lib/commonjs/intl/index.js.map +1 -0
- package/lib/commonjs/kv/index.js +83 -0
- package/lib/commonjs/kv/index.js.map +1 -0
- package/lib/commonjs/lazy/index.js +63 -0
- package/lib/commonjs/lazy/index.js.map +1 -0
- package/lib/commonjs/listeners/index.js +110 -0
- package/lib/commonjs/listeners/index.js.map +1 -0
- package/lib/commonjs/messages/index.js +53 -0
- package/lib/commonjs/messages/index.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/react/index.js +93 -0
- package/lib/commonjs/react/index.js.map +1 -0
- package/lib/commonjs/redact/index.js +128 -0
- package/lib/commonjs/redact/index.js.map +1 -0
- package/lib/commonjs/runtime/index.js +77 -0
- package/lib/commonjs/runtime/index.js.map +1 -0
- package/lib/commonjs/runtime/lifecycle.js +105 -0
- package/lib/commonjs/runtime/lifecycle.js.map +1 -0
- package/lib/commonjs/scheduler/index.js +216 -0
- package/lib/commonjs/scheduler/index.js.map +1 -0
- package/lib/commonjs/store/index.js +39 -0
- package/lib/commonjs/store/index.js.map +1 -0
- package/lib/commonjs/testing/conformance.js +79 -0
- package/lib/commonjs/testing/conformance.js.map +1 -0
- package/lib/commonjs/testing/index.js +58 -0
- package/lib/commonjs/testing/index.js.map +1 -0
- package/lib/commonjs/testing/lifecycle.js +37 -0
- package/lib/commonjs/testing/lifecycle.js.map +1 -0
- package/lib/commonjs/testing/redaction.js +118 -0
- package/lib/commonjs/testing/redaction.js.map +1 -0
- package/lib/commonjs/testing/scheduler.js +51 -0
- package/lib/commonjs/testing/scheduler.js.map +1 -0
- package/lib/module/diagnostics/index.js +75 -0
- package/lib/module/diagnostics/index.js.map +1 -0
- package/lib/module/errors/index.js +78 -0
- package/lib/module/errors/index.js.map +1 -0
- package/lib/module/index.js +24 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/intl/index.js +91 -0
- package/lib/module/intl/index.js.map +1 -0
- package/lib/module/kv/index.js +76 -0
- package/lib/module/kv/index.js.map +1 -0
- package/lib/module/lazy/index.js +59 -0
- package/lib/module/lazy/index.js.map +1 -0
- package/lib/module/listeners/index.js +104 -0
- package/lib/module/listeners/index.js.map +1 -0
- package/lib/module/messages/index.js +48 -0
- package/lib/module/messages/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/react/index.js +86 -0
- package/lib/module/react/index.js.map +1 -0
- package/lib/module/redact/index.js +118 -0
- package/lib/module/redact/index.js.map +1 -0
- package/lib/module/runtime/index.js +52 -0
- package/lib/module/runtime/index.js.map +1 -0
- package/lib/module/runtime/lifecycle.js +99 -0
- package/lib/module/runtime/lifecycle.js.map +1 -0
- package/lib/module/scheduler/index.js +203 -0
- package/lib/module/scheduler/index.js.map +1 -0
- package/lib/module/store/index.js +33 -0
- package/lib/module/store/index.js.map +1 -0
- package/lib/module/testing/conformance.js +72 -0
- package/lib/module/testing/conformance.js.map +1 -0
- package/lib/module/testing/index.js +12 -0
- package/lib/module/testing/index.js.map +1 -0
- package/lib/module/testing/lifecycle.js +32 -0
- package/lib/module/testing/lifecycle.js.map +1 -0
- package/lib/module/testing/redaction.js +113 -0
- package/lib/module/testing/redaction.js.map +1 -0
- package/lib/module/testing/scheduler.js +47 -0
- package/lib/module/testing/scheduler.js.map +1 -0
- package/lib/typescript/commonjs/diagnostics/index.d.ts +49 -0
- package/lib/typescript/commonjs/diagnostics/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/errors/index.d.ts +59 -0
- package/lib/typescript/commonjs/errors/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/index.d.ts +22 -0
- package/lib/typescript/commonjs/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/intl/index.d.ts +25 -0
- package/lib/typescript/commonjs/intl/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/kv/index.d.ts +38 -0
- package/lib/typescript/commonjs/kv/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/lazy/index.d.ts +36 -0
- package/lib/typescript/commonjs/lazy/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/listeners/index.d.ts +61 -0
- package/lib/typescript/commonjs/listeners/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/messages/index.d.ts +39 -0
- package/lib/typescript/commonjs/messages/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/package.json +1 -0
- package/lib/typescript/commonjs/react/index.d.ts +38 -0
- package/lib/typescript/commonjs/react/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/redact/index.d.ts +47 -0
- package/lib/typescript/commonjs/redact/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/runtime/index.d.ts +21 -0
- package/lib/typescript/commonjs/runtime/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/runtime/lifecycle.d.ts +34 -0
- package/lib/typescript/commonjs/runtime/lifecycle.d.ts.map +1 -0
- package/lib/typescript/commonjs/scheduler/index.d.ts +108 -0
- package/lib/typescript/commonjs/scheduler/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/store/index.d.ts +18 -0
- package/lib/typescript/commonjs/store/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/testing/conformance.d.ts +35 -0
- package/lib/typescript/commonjs/testing/conformance.d.ts.map +1 -0
- package/lib/typescript/commonjs/testing/index.d.ts +10 -0
- package/lib/typescript/commonjs/testing/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/testing/lifecycle.d.ts +15 -0
- package/lib/typescript/commonjs/testing/lifecycle.d.ts.map +1 -0
- package/lib/typescript/commonjs/testing/redaction.d.ts +35 -0
- package/lib/typescript/commonjs/testing/redaction.d.ts.map +1 -0
- package/lib/typescript/commonjs/testing/scheduler.d.ts +15 -0
- package/lib/typescript/commonjs/testing/scheduler.d.ts.map +1 -0
- package/lib/typescript/module/diagnostics/index.d.ts +49 -0
- package/lib/typescript/module/diagnostics/index.d.ts.map +1 -0
- package/lib/typescript/module/errors/index.d.ts +59 -0
- package/lib/typescript/module/errors/index.d.ts.map +1 -0
- package/lib/typescript/module/index.d.ts +22 -0
- package/lib/typescript/module/index.d.ts.map +1 -0
- package/lib/typescript/module/intl/index.d.ts +25 -0
- package/lib/typescript/module/intl/index.d.ts.map +1 -0
- package/lib/typescript/module/kv/index.d.ts +38 -0
- package/lib/typescript/module/kv/index.d.ts.map +1 -0
- package/lib/typescript/module/lazy/index.d.ts +36 -0
- package/lib/typescript/module/lazy/index.d.ts.map +1 -0
- package/lib/typescript/module/listeners/index.d.ts +61 -0
- package/lib/typescript/module/listeners/index.d.ts.map +1 -0
- package/lib/typescript/module/messages/index.d.ts +39 -0
- package/lib/typescript/module/messages/index.d.ts.map +1 -0
- package/lib/typescript/module/package.json +1 -0
- package/lib/typescript/module/react/index.d.ts +38 -0
- package/lib/typescript/module/react/index.d.ts.map +1 -0
- package/lib/typescript/module/redact/index.d.ts +47 -0
- package/lib/typescript/module/redact/index.d.ts.map +1 -0
- package/lib/typescript/module/runtime/index.d.ts +21 -0
- package/lib/typescript/module/runtime/index.d.ts.map +1 -0
- package/lib/typescript/module/runtime/lifecycle.d.ts +34 -0
- package/lib/typescript/module/runtime/lifecycle.d.ts.map +1 -0
- package/lib/typescript/module/scheduler/index.d.ts +108 -0
- package/lib/typescript/module/scheduler/index.d.ts.map +1 -0
- package/lib/typescript/module/store/index.d.ts +18 -0
- package/lib/typescript/module/store/index.d.ts.map +1 -0
- package/lib/typescript/module/testing/conformance.d.ts +35 -0
- package/lib/typescript/module/testing/conformance.d.ts.map +1 -0
- package/lib/typescript/module/testing/index.d.ts +10 -0
- package/lib/typescript/module/testing/index.d.ts.map +1 -0
- package/lib/typescript/module/testing/lifecycle.d.ts +15 -0
- package/lib/typescript/module/testing/lifecycle.d.ts.map +1 -0
- package/lib/typescript/module/testing/redaction.d.ts +35 -0
- package/lib/typescript/module/testing/redaction.d.ts.map +1 -0
- package/lib/typescript/module/testing/scheduler.d.ts +15 -0
- package/lib/typescript/module/testing/scheduler.d.ts.map +1 -0
- package/package.json +154 -46
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Listener sets and event emitters (CORE-03, CORE-08, CORE-12).
|
|
5
|
+
*
|
|
6
|
+
* Every package used to keep its own `Set<listener>` and loop over it. Three of
|
|
7
|
+
* them let a throwing subscriber escape into the code that was notifying, which
|
|
8
|
+
* left a state machine half-updated. Here, once:
|
|
9
|
+
*
|
|
10
|
+
* - `notify` iterates a snapshot: a listener added during a round waits for the
|
|
11
|
+
* next one, and a listener removed during a round is not called, so a consumer
|
|
12
|
+
* that unsubscribed (an unmounted component) is never reached;
|
|
13
|
+
* - each listener runs in its own try/catch, so one throwing subscriber neither
|
|
14
|
+
* stops the others nor reaches the caller;
|
|
15
|
+
* - a listener's error is reported, never swallowed: to `onListenerError` when
|
|
16
|
+
* given, otherwise rethrown on a fresh task, where the app's global error
|
|
17
|
+
* handler and crash reporter see it;
|
|
18
|
+
* - unsubscribing twice is a no-op.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/** Rethrows on a fresh task: outside every caller, inside the app's error handler. */
|
|
22
|
+
export function reportAsynchronously(error) {
|
|
23
|
+
setTimeout(() => {
|
|
24
|
+
throw error;
|
|
25
|
+
}, 0);
|
|
26
|
+
}
|
|
27
|
+
export function createListenerSet(options = {}) {
|
|
28
|
+
const listeners = new Set();
|
|
29
|
+
const report = options.onListenerError ?? reportAsynchronously;
|
|
30
|
+
let reporting = false;
|
|
31
|
+
function fail(error) {
|
|
32
|
+
if (reporting) return;
|
|
33
|
+
reporting = true;
|
|
34
|
+
try {
|
|
35
|
+
report(error);
|
|
36
|
+
} catch (reportError) {
|
|
37
|
+
reportAsynchronously(reportError);
|
|
38
|
+
} finally {
|
|
39
|
+
reporting = false;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
add(listener) {
|
|
44
|
+
listeners.add(listener);
|
|
45
|
+
let active = true;
|
|
46
|
+
return () => {
|
|
47
|
+
if (!active) return;
|
|
48
|
+
active = false;
|
|
49
|
+
listeners.delete(listener);
|
|
50
|
+
};
|
|
51
|
+
},
|
|
52
|
+
notify(...args) {
|
|
53
|
+
for (const listener of [...listeners]) {
|
|
54
|
+
if (!listeners.has(listener)) continue;
|
|
55
|
+
try {
|
|
56
|
+
listener(...args);
|
|
57
|
+
} catch (error) {
|
|
58
|
+
fail(error);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
get size() {
|
|
63
|
+
return listeners.size;
|
|
64
|
+
},
|
|
65
|
+
clear() {
|
|
66
|
+
listeners.clear();
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
export function createEmitter(options = {}) {
|
|
71
|
+
const listeners = createListenerSet(options);
|
|
72
|
+
const seen = new Map();
|
|
73
|
+
const dedupe = options.dedupe;
|
|
74
|
+
let disposed = false;
|
|
75
|
+
return {
|
|
76
|
+
emit(event) {
|
|
77
|
+
if (disposed) return false;
|
|
78
|
+
const key = dedupe?.key(event);
|
|
79
|
+
if (key !== undefined && dedupe) {
|
|
80
|
+
if (seen.has(key)) return false;
|
|
81
|
+
seen.set(key, true);
|
|
82
|
+
if (seen.size > dedupe.capacity) {
|
|
83
|
+
const oldest = seen.keys().next().value;
|
|
84
|
+
if (oldest !== undefined) seen.delete(oldest);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
listeners.notify(event);
|
|
88
|
+
return true;
|
|
89
|
+
},
|
|
90
|
+
subscribe: listener => listeners.add(listener),
|
|
91
|
+
forget(matches) {
|
|
92
|
+
for (const key of [...seen.keys()]) {
|
|
93
|
+
if (matches(key)) seen.delete(key);
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
dispose() {
|
|
97
|
+
disposed = true;
|
|
98
|
+
listeners.clear();
|
|
99
|
+
seen.clear();
|
|
100
|
+
},
|
|
101
|
+
listenerCount: () => listeners.size
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["reportAsynchronously","error","setTimeout","createListenerSet","options","listeners","Set","report","onListenerError","reporting","fail","reportError","add","listener","active","delete","notify","args","has","size","clear","createEmitter","seen","Map","dedupe","disposed","emit","event","key","undefined","set","capacity","oldest","keys","next","value","subscribe","forget","matches","dispose","listenerCount"],"sourceRoot":"../../../src","sources":["listeners/index.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAaA;AACA,OAAO,SAASA,oBAAoBA,CAACC,KAAc,EAAQ;EAC1DC,UAAU,CAAC,MAAM;IAChB,MAAMD,KAAK;EACZ,CAAC,EAAE,CAAC,CAAC;AACN;AAWA,OAAO,SAASE,iBAAiBA,CAChCC,OAA6B,GAAG,CAAC,CAAC,EACd;EACpB,MAAMC,SAAS,GAAG,IAAIC,GAAG,CAA0B,CAAC;EACpD,MAAMC,MAAM,GAAGH,OAAO,CAACI,eAAe,IAAIR,oBAAoB;EAC9D,IAAIS,SAAS,GAAG,KAAK;EAErB,SAASC,IAAIA,CAACT,KAAc,EAAQ;IACnC,IAAIQ,SAAS,EAAE;IACfA,SAAS,GAAG,IAAI;IAChB,IAAI;MACHF,MAAM,CAACN,KAAK,CAAC;IACd,CAAC,CAAC,OAAOU,WAAW,EAAE;MACrBX,oBAAoB,CAACW,WAAW,CAAC;IAClC,CAAC,SAAS;MACTF,SAAS,GAAG,KAAK;IAClB;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EAAE,OAAO,KAAK;QAC/BN,IAAI,CAACQ,GAAG,CAACF,GAAG,EAAE,IAAI,CAAC;QACnB,IAAIN,IAAI,CAACH,IAAI,GAAGK,MAAM,CAACO,QAAQ,EAAE;UAChC,MAAMC,MAAM,GAAGV,IAAI,CAACW,IAAI,CAAC,CAAC,CAACC,IAAI,CAAC,CAAC,CAACC,KAAK;UACvC,IAAIH,MAAM,KAAKH,SAAS,EAAEP,IAAI,CAACP,MAAM,CAACiB,MAAM,CAAC;QAC9C;MACD;MACA3B,SAAS,CAACW,MAAM,CAACW,KAAK,CAAC;MACvB,OAAO,IAAI;IACZ,CAAC;IACDS,SAAS,EAAEvB,QAAQ,IAAIR,SAAS,CAACO,GAAG,CAACC,QAAQ,CAAC;IAC9CwB,MAAMA,CAACC,OAAO,EAAE;MACf,KAAK,MAAMV,GAAG,IAAI,CAAC,GAAGN,IAAI,CAACW,IAAI,CAAC,CAAC,CAAC,EAAE;QACnC,IAAIK,OAAO,CAACV,GAAG,CAAC,EAAEN,IAAI,CAACP,MAAM,CAACa,GAAG,CAAC;MACnC;IACD,CAAC;IACDW,OAAOA,CAAA,EAAG;MACTd,QAAQ,GAAG,IAAI;MACfpB,SAAS,CAACe,KAAK,CAAC,CAAC;MACjBE,IAAI,CAACF,KAAK,CAAC,CAAC;IACb,CAAC;IACDoB,aAAa,EAAEA,CAAA,KAAMnC,SAAS,CAACc;EAChC,CAAC;AACF","ignoreList":[]}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Message catalogs (CORE-15, I18N-13, AUTH-16, AI-15).
|
|
5
|
+
*
|
|
6
|
+
* rn-ai, rn-auth and rn-payment each kept their copy keys in a different shape.
|
|
7
|
+
* One shape now: a catalog of default texts split by audience. `user` copy may
|
|
8
|
+
* reach an end user; `developer` copy describes a configuration fault and must
|
|
9
|
+
* never be shown to one. A catalog is plain data (`key -> default text`), so rn-i18n
|
|
10
|
+
* can register any package's catalog in one call and translate it like app copy.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/** Message key to default text. `{name}` marks a variable. */
|
|
14
|
+
|
|
15
|
+
/** Any object whose every key maps to a string; interfaces qualify, unlike an index signature. */
|
|
16
|
+
|
|
17
|
+
/** Fills `{name}` placeholders; a placeholder with no value is left as written. */
|
|
18
|
+
export function formatMessage(template, vars) {
|
|
19
|
+
if (!vars) return template;
|
|
20
|
+
return template.replace(/\{(\w+)\}/g, (placeholder, name) => Object.prototype.hasOwnProperty.call(vars, name) ? String(vars[name]) : placeholder);
|
|
21
|
+
}
|
|
22
|
+
export function defineMessages(catalog) {
|
|
23
|
+
const user = catalog.user;
|
|
24
|
+
const developer = catalog.developer ?? {};
|
|
25
|
+
const defaults = Object.freeze({
|
|
26
|
+
...user,
|
|
27
|
+
...developer
|
|
28
|
+
});
|
|
29
|
+
const developerKeys = new Set(Object.keys(developer));
|
|
30
|
+
return {
|
|
31
|
+
defaults,
|
|
32
|
+
user: Object.freeze({
|
|
33
|
+
...user
|
|
34
|
+
}),
|
|
35
|
+
developer: Object.freeze({
|
|
36
|
+
...developer
|
|
37
|
+
}),
|
|
38
|
+
userKeys: Object.freeze(Object.keys(user)),
|
|
39
|
+
developerKeys: Object.freeze(Object.keys(developer)),
|
|
40
|
+
resolve: overrides => ({
|
|
41
|
+
...defaults,
|
|
42
|
+
...overrides
|
|
43
|
+
}),
|
|
44
|
+
audienceOf: key => developerKeys.has(key) ? 'developer' : 'user',
|
|
45
|
+
format: (key, vars) => formatMessage(defaults[key] ?? String(key), vars)
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["formatMessage","template","vars","replace","placeholder","name","Object","prototype","hasOwnProperty","call","String","defineMessages","catalog","user","developer","defaults","freeze","developerKeys","Set","keys","userKeys","resolve","overrides","audienceOf","key","has","format"],"sourceRoot":"../../../src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EC,GAAG,IAAKP,aAAa,CAACQ,GAAG,CAACD,GAAa,CAAC,GAAG,WAAW,GAAG,MAAO;IAC5EE,MAAM,EAAEA,CAACF,GAAG,EAAEtB,IAAI,KACjBF,aAAa,CAAEe,QAAQ,CAA4BS,GAAG,CAAW,IAAId,MAAM,CAACc,GAAG,CAAC,EAAEtB,IAAI;EACxF,CAAC;AACF","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* React glue every package shares (CORE-07, PERF-04).
|
|
5
|
+
*
|
|
6
|
+
* Packages used to mirror their state into `useState` from a `useEffect`
|
|
7
|
+
* subscription: one render late, a tearing risk under concurrent rendering, and
|
|
8
|
+
* every consumer re-rendered on every change. Here, one way:
|
|
9
|
+
* `useSyncExternalStore` over a store whose snapshot keeps its identity until it
|
|
10
|
+
* actually changes, with a selector so a component re-renders only when the part
|
|
11
|
+
* it reads changes.
|
|
12
|
+
*
|
|
13
|
+
* `react` is an optional peer of rn-core, needed only for this entrypoint.
|
|
14
|
+
*/
|
|
15
|
+
import { createContext, createElement, useCallback, useContext, useRef, useSyncExternalStore } from 'react';
|
|
16
|
+
function identity(value) {
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Reads an external store. With `select`, the component re-renders only when the
|
|
22
|
+
* selected value changes by `isEqual` (default `Object.is`), however often the
|
|
23
|
+
* store itself changes.
|
|
24
|
+
*/
|
|
25
|
+
export function useExternalStore(subscribe, getSnapshot, select = identity, isEqual = Object.is) {
|
|
26
|
+
const memo = useRef(null);
|
|
27
|
+
const getSelected = useCallback(() => {
|
|
28
|
+
const snapshot = getSnapshot();
|
|
29
|
+
const previous = memo.current;
|
|
30
|
+
if (previous && Object.is(previous.snapshot, snapshot)) return previous.selected;
|
|
31
|
+
const selected = select(snapshot);
|
|
32
|
+
if (previous && isEqual(previous.selected, selected)) {
|
|
33
|
+
memo.current = {
|
|
34
|
+
snapshot,
|
|
35
|
+
selected: previous.selected
|
|
36
|
+
};
|
|
37
|
+
return previous.selected;
|
|
38
|
+
}
|
|
39
|
+
memo.current = {
|
|
40
|
+
snapshot,
|
|
41
|
+
selected
|
|
42
|
+
};
|
|
43
|
+
return selected;
|
|
44
|
+
}, [getSnapshot, select, isEqual]);
|
|
45
|
+
return useSyncExternalStore(subscribe, getSelected, getSelected);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* A callback whose identity never changes but which always calls the latest
|
|
50
|
+
* `fn`, for listeners an app passes inline that must not re-run an effect.
|
|
51
|
+
*/
|
|
52
|
+
export function useLatestCallback(fn) {
|
|
53
|
+
const latest = useRef(fn);
|
|
54
|
+
latest.current = fn;
|
|
55
|
+
return useCallback((...args) => latest.current(...args), []);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* A context with a Provider and a hook that throws a clear error outside it,
|
|
60
|
+
* instead of returning `undefined` for a missing provider.
|
|
61
|
+
*/
|
|
62
|
+
export function createSdkContext(name) {
|
|
63
|
+
const Context = /*#__PURE__*/createContext(null);
|
|
64
|
+
Context.displayName = name;
|
|
65
|
+
function Provider({
|
|
66
|
+
value,
|
|
67
|
+
children
|
|
68
|
+
}) {
|
|
69
|
+
return /*#__PURE__*/createElement(Context.Provider, {
|
|
70
|
+
value
|
|
71
|
+
}, children);
|
|
72
|
+
}
|
|
73
|
+
function use() {
|
|
74
|
+
const value = useContext(Context);
|
|
75
|
+
if (value === null) {
|
|
76
|
+
throw new Error(`${name} is not available: wrap the tree in its <${name}Provider>.`);
|
|
77
|
+
}
|
|
78
|
+
return value;
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
Context,
|
|
82
|
+
Provider,
|
|
83
|
+
use
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createContext","createElement","useCallback","useContext","useRef","useSyncExternalStore","identity","value","useExternalStore","subscribe","getSnapshot","select","isEqual","Object","is","memo","getSelected","snapshot","previous","current","selected","useLatestCallback","fn","latest","args","createSdkContext","name","Context","displayName","Provider","children","use","Error"],"sourceRoot":"../../../src","sources":["react/index.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SACCA,aAAa,EACbC,aAAa,EACbC,WAAW,EACXC,UAAU,EACVC,MAAM,EACNC,oBAAoB,QAEd,OAAO;AAId,SAASC,QAAQA,CAAIC,KAAQ,EAAK;EACjC,OAAOA,KAAK;AACb;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,gBAAgBA,CAC/BC,SAAgD,EAChDC,WAA2B,EAC3BC,MAAwC,GAAGL,QAA4C,EACvFM,OAA8C,GAAGC,MAAM,CAACC,EAAE,EAC/C;EACX,MAAMC,IAAI,GAAGX,MAAM,CAAoD,IAAI,CAAC;EAC5E,MAAMY,WAAW,GAAGd,WAAW,CAAC,MAAM;IACrC,MAAMe,QAAQ,GAAGP,WAAW,CAAC,CAAC;IAC9B,MAAMQ,QAAQ,GAAGH,IAAI,CAACI,OAAO;IAC7B,IAAID,QAAQ,IAAIL,MAAM,CAACC,EAAE,CAACI,QAAQ,CAACD,QAAQ,EAAEA,QAAQ,CAAC,EAAE,OAAOC,QAAQ,CAACE,QAAQ;IAChF,MAAMA,QAAQ,GAAGT,MAAM,CAACM,QAAQ,CAAC;IACjC,IAAIC,QAAQ,IAAIN,OAAO,CAACM,QAAQ,CAACE,QAAQ,EAAEA,QAAQ,CAAC,EAAE;MACrDL,IAAI,CAACI,OAAO,GAAG;QAAEF,QAAQ;QAAEG,QAAQ,EAAEF,QAAQ,CAACE;MAAS,CAAC;MACxD,OAAOF,QAAQ,CAACE,QAAQ;IACzB;IACAL,IAAI,CAACI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every package (CORE-02).
|
|
5
|
+
*
|
|
6
|
+
* Packages differ in policy, not in mechanism, so the mechanism lives here once:
|
|
7
|
+
*
|
|
8
|
+
* - `identifier` text keeps only a leading engine constant (`SQLITE_BUSY`,
|
|
9
|
+
* `E_USER_CANCELLED`) and drops everything else. It is the default, and the
|
|
10
|
+
* only safe choice for text that may carry user data in free prose.
|
|
11
|
+
* - `patterns` text keeps prose but replaces anything shaped like a secret or an
|
|
12
|
+
* identifier: URLs, JWTs, e-mail addresses, UUIDs, long base64 runs, plus a
|
|
13
|
+
* package's own patterns.
|
|
14
|
+
* - `detail` keeps an allowlist of keys with primitive values.
|
|
15
|
+
* - `context` replaces the values of content keys by their shape (`[string:12]`)
|
|
16
|
+
* and pattern-redacts every other string.
|
|
17
|
+
*
|
|
18
|
+
* Every package's redaction runs through `redactionConformance`
|
|
19
|
+
* (`@chipmobilesdk/rn-core/testing`), so a policy that lets a token through fails
|
|
20
|
+
* that package's tests.
|
|
21
|
+
*/
|
|
22
|
+
import { isSdkError } from "../errors/index.js";
|
|
23
|
+
export const REDACTED = '[redacted]';
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Shapes that are a secret or an identifier wherever they appear. Order matters:
|
|
27
|
+
* a URL is replaced whole before its parts could match anything narrower.
|
|
28
|
+
*/
|
|
29
|
+
export const COMMON_PATTERNS = Object.freeze([/** Anything URL-like; query strings carry tokens and identifiers. */
|
|
30
|
+
/[a-zA-Z][a-zA-Z0-9+.-]*:\/\/[^\s"'<>]+/g, /** JWTs: three base64url segments separated by dots. */
|
|
31
|
+
/[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}/g, /** E-mail addresses. */
|
|
32
|
+
/[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}/g, /** UUIDs, including advertising ids. */
|
|
33
|
+
/[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}/g, /** Base64-ish runs long enough to be an encoded payload or an opaque token. */
|
|
34
|
+
/[A-Za-z0-9+/=_-]{40,}/g]);
|
|
35
|
+
|
|
36
|
+
/** File paths: file URIs are URLs already; this adds POSIX and Windows paths. */
|
|
37
|
+
export const PATH_PATTERN = /(?:[a-zA-Z]:[\\/][^\s"']+)|(?:\/[^\s"']*\/[^\s"']*)/g;
|
|
38
|
+
const IDENTIFIER_TOKEN = /^([A-Z][A-Z0-9_]{2,})\b/;
|
|
39
|
+
|
|
40
|
+
/** Replaces every match of every pattern with `[redacted]`. */
|
|
41
|
+
export function redactPatterns(text, patterns = COMMON_PATTERNS) {
|
|
42
|
+
return patterns.reduce((out, pattern) => out.replace(pattern, REDACTED), text);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Reduces text this package did not write to a leading engine identifier, or to
|
|
47
|
+
* `[redacted]`. No shape test separates prose describing a failure from prose
|
|
48
|
+
* describing a person, so prose never survives.
|
|
49
|
+
*/
|
|
50
|
+
export function leadingIdentifier(text) {
|
|
51
|
+
if (!text) return '';
|
|
52
|
+
const token = IDENTIFIER_TOKEN.exec(text.split('\n')[0]?.trim() ?? '');
|
|
53
|
+
return token?.[1] ?? REDACTED;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** A value's shape without its content: `[string:12]`, `[array:3]`, `[object:2]`. */
|
|
57
|
+
export function describeShape(value) {
|
|
58
|
+
if (value === null) return '[null]';
|
|
59
|
+
if (value === undefined) return '[undefined]';
|
|
60
|
+
if (typeof value === 'string') return `[string:${value.length}]`;
|
|
61
|
+
if (Array.isArray(value)) return `[array:${value.length}]`;
|
|
62
|
+
if (typeof value === 'object') return `[object:${Object.keys(value).length}]`;
|
|
63
|
+
return REDACTED;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Keeps only allowlisted keys, and only their primitive values. */
|
|
67
|
+
export function pickAllowed(detail, allow) {
|
|
68
|
+
if (!detail) return undefined;
|
|
69
|
+
const safe = {};
|
|
70
|
+
for (const [key, value] of Object.entries(detail)) {
|
|
71
|
+
if (allow.has(key) && (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean')) {
|
|
72
|
+
safe[key] = value;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return safe;
|
|
76
|
+
}
|
|
77
|
+
export function createRedactor(policy = {}) {
|
|
78
|
+
const mode = policy.text ?? 'identifier';
|
|
79
|
+
const patterns = [...COMMON_PATTERNS, ...(policy.patterns ?? [])];
|
|
80
|
+
const dropKeys = new Set(policy.dropKeys ?? []);
|
|
81
|
+
const allow = new Set(policy.allowDetailKeys ?? []);
|
|
82
|
+
const shapeKeys = new Set(policy.shapeKeys ?? []);
|
|
83
|
+
const textDepth = policy.maxDepth ?? 2;
|
|
84
|
+
const contextDepth = policy.maxDepth ?? 6;
|
|
85
|
+
const string = value => mode === 'identifier' ? leadingIdentifier(value) : redactPatterns(value, patterns);
|
|
86
|
+
function text(value, depth = 0) {
|
|
87
|
+
if (value === null || value === undefined) return '';
|
|
88
|
+
if (typeof value === 'string') return string(value);
|
|
89
|
+
if (typeof value === 'number' || typeof value === 'boolean') return String(value);
|
|
90
|
+
if (isSdkError(value)) return value.code;
|
|
91
|
+
if (value instanceof Error) {
|
|
92
|
+
return mode === 'identifier' ? value.name : string(value.message);
|
|
93
|
+
}
|
|
94
|
+
if (mode === 'identifier' || depth >= textDepth) return REDACTED;
|
|
95
|
+
if (Array.isArray(value)) return value.map(item => text(item, depth + 1)).join(', ');
|
|
96
|
+
if (typeof value === 'object') {
|
|
97
|
+
return Object.entries(value).map(([key, entry]) => `${key}=${dropKeys.has(key) ? REDACTED : text(entry, depth + 1)}`).join(' ');
|
|
98
|
+
}
|
|
99
|
+
return REDACTED;
|
|
100
|
+
}
|
|
101
|
+
function walk(value, depth) {
|
|
102
|
+
if (typeof value === 'string') return redactPatterns(value, patterns);
|
|
103
|
+
if (value instanceof Error) return text(value);
|
|
104
|
+
if (value === null || typeof value !== 'object' || depth > contextDepth) return value;
|
|
105
|
+
if (Array.isArray(value)) return value.map(item => walk(item, depth + 1));
|
|
106
|
+
const out = {};
|
|
107
|
+
for (const [key, inner] of Object.entries(value)) {
|
|
108
|
+
out[key] = shapeKeys.has(key) ? describeShape(inner) : dropKeys.has(key) ? REDACTED : walk(inner, depth + 1);
|
|
109
|
+
}
|
|
110
|
+
return out;
|
|
111
|
+
}
|
|
112
|
+
return {
|
|
113
|
+
text: value => text(value),
|
|
114
|
+
detail: detail => pickAllowed(detail, allow),
|
|
115
|
+
context: context => context === undefined ? undefined : walk(context, 0)
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["isSdkError","REDACTED","COMMON_PATTERNS","Object","freeze","PATH_PATTERN","IDENTIFIER_TOKEN","redactPatterns","text","patterns","reduce","out","pattern","replace","leadingIdentifier","token","exec","split","trim","describeShape","value","undefined","length","Array","isArray","keys","pickAllowed","detail","allow","safe","key","entries","has","createRedactor","policy","mode","dropKeys","Set","allowDetailKeys","shapeKeys","textDepth","maxDepth","contextDepth","string","depth","String","code","Error","name","message","map","item","join","entry","walk","inner","context"],"sourceRoot":"../../../src","sources":["redact/index.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,UAAU,QAAQ,oBAAW;AAEtC,OAAO,MAAMC,QAAQ,GAAG,YAAY;;AAEpC;AACA;AACA;AACA;AACA,OAAO,MAAMC,eAAkC,GAAGC,MAAM,CAACC,MAAM,CAAC,CAC/D;AACA,yCAAyC,EACzC;AACA,0DAA0D,EAC1D;AACA,iDAAiD,EACjD;AACA,8EAA8E,EAC9E;AACA,wBAAwB,CACxB,CAAC;;AAEF;AACA,OAAO,MAAMC,YAAY,GAAG,sDAAsD;AAElF,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;IAC9C,IAAIA,KAAK,KAAK,IAAI,IAAI,OAAOA,KAAK,KAAK,QAAQ,IAAIwB,KAAK,GAAGF,YAAY,EAAE,OAAOtB,KAAK;IACrF,IAAIG,KAAK,CAACC,OAAO,CAACJ,KAAK,CAAC,EAAE,OAAOA,KAAK,CAAC8B,GAAG,CAACC,IAAI,IAAIG,IAAI,CAACH,IAAI,EAAEP,KAAK,GAAG,CAAC,CAAC,CAAC;IACzE,MAAMjC,GAA4B,GAAG,CAAC,CAAC;IACvC,KAAK,MAAM,CAACmB,GAAG,EAAEyB,KAAK,CAAC,IAAIpD,MAAM,CAAC4B,OAAO,CAACX,KAAgC,CAAC,EAAE;MAC5ET,GAAG,CAACmB,GAAG,CAAC,GAAGS,SAAS,CAACP,GAAG,CAACF,GAAG,CAAC,GAC1BX,aAAa,CAACoC,KAAK,CAAC,GACpBnB,QAAQ,CAACJ,GAAG,CAACF,GAAG,CAAC,GAChB7B,QAAQ,GACRqD,IAAI,CAACC,KAAK,EAAEX,KAAK,GAAG,CAAC,CAAC;IAC3B;IACA,OAAOjC,GAAG;EACX;EAEA,OAAO;IACNH,IAAI,EAAEY,KAAK,IAAIZ,IAAI,CAACY,KAAK,CAAC;IAC1BO,MAAM,EAAEA,MAAM,IAAID,WAAW,CAACC,MAAM,EAAEC,KAAK,CAAC;IAC5C4B,OAAO,EAAEA,OAAO,IACfA,OAAO,KAAKnC,SAAS,GAAGA,SAAS,GAAIiC,IAAI,CAACE,OAAO,EAAE,CAAC;EACtD,CAAC;AACF","ignoreList":[]}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Where the code is running (CORE-09, IOS-11).
|
|
5
|
+
*
|
|
6
|
+
* Five packages detected the platform five ways, with contradicting fallbacks
|
|
7
|
+
* (rn-payment assumed Android, rn-auth assumed iOS). One source now: it reads
|
|
8
|
+
* React Native's `Platform` lazily, so this module also loads under plain Node,
|
|
9
|
+
* where it reports `unsupported`.
|
|
10
|
+
*/
|
|
11
|
+
import { lazyPeer } from "../lazy/index.js";
|
|
12
|
+
|
|
13
|
+
/** What a build is for. A package may refuse production configuration elsewhere. */
|
|
14
|
+
|
|
15
|
+
const reactNative = lazyPeer('react-native', () => require('react-native'));
|
|
16
|
+
let platformOverride;
|
|
17
|
+
|
|
18
|
+
/** The OS the app runs on, or `unsupported` (web, Node, a platform with no adapter). */
|
|
19
|
+
export function currentPlatform() {
|
|
20
|
+
if (platformOverride) return platformOverride;
|
|
21
|
+
const result = reactNative.get();
|
|
22
|
+
const os = result.ok ? result.module.Platform?.OS : undefined;
|
|
23
|
+
return os === 'android' || os === 'ios' ? os : 'unsupported';
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Test seam: pins `currentPlatform()`; `undefined` goes back to the real one. */
|
|
27
|
+
export function setPlatformOverride(platform) {
|
|
28
|
+
platformOverride = platform;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Picks a value for the current platform, falling back to `default`. */
|
|
32
|
+
export function byPlatform(values) {
|
|
33
|
+
const platform = currentPlatform();
|
|
34
|
+
if (platform === 'android' && values.android !== undefined) return values.android;
|
|
35
|
+
if (platform === 'ios' && values.ios !== undefined) return values.ios;
|
|
36
|
+
return values.default;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Whether this is a development build: React Native's `__DEV__`, or, where that
|
|
41
|
+
* global does not exist (plain Node, some test runners), `NODE_ENV` not being
|
|
42
|
+
* `production`.
|
|
43
|
+
*/
|
|
44
|
+
export function isDevBuild() {
|
|
45
|
+
if (typeof __DEV__ !== 'undefined') return __DEV__ === true;
|
|
46
|
+
const {
|
|
47
|
+
process
|
|
48
|
+
} = globalThis;
|
|
49
|
+
return process?.env?.NODE_ENV !== 'production';
|
|
50
|
+
}
|
|
51
|
+
export { appLifecycle, createAppLifecycle, onForeground } from "./lifecycle.js";
|
|
52
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["lazyPeer","reactNative","require","platformOverride","currentPlatform","result","get","os","ok","module","Platform","OS","undefined","setPlatformOverride","platform","byPlatform","values","android","ios","default","isDevBuild","__DEV__","process","globalThis","env","NODE_ENV","appLifecycle","createAppLifecycle","onForeground"],"sourceRoot":"../../../src","sources":["runtime/index.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,QAAQ,QAAQ,kBAAS;;AAIlC;;AAOA,MAAMC,WAAW,GAAGD,QAAQ,CAC3B,cAAc,EACd,MAAME,OAAO,CAAC,cAAc,CAC7B,CAAC;AAED,IAAIC,gBAA6C;;AAEjD;AACA,OAAO,SAASC,eAAeA,CAAA,EAAoB;EAClD,IAAID,gBAAgB,EAAE,OAAOA,gBAAgB;EAC7C,MAAME,MAAM,GAAGJ,WAAW,CAACK,GAAG,CAAC,CAAC;EAChC,MAAMC,EAAE,GAAGF,MAAM,CAACG,EAAE,GAAGH,MAAM,CAACI,MAAM,CAACC,QAAQ,EAAEC,EAAE,GAAGC,SAAS;EAC7D,OAAOL,EAAE,KAAK,SAAS,IAAIA,EAAE,KAAK,KAAK,GAAGA,EAAE,GAAG,aAAa;AAC7D;;AAEA;AACA,OAAO,SAASM,mBAAmBA,CAACC,QAAqC,EAAQ;EAChFX,gBAAgB,GAAGW,QAAQ;AAC5B;;AAEA;AACA,OAAO,SAASC,UAAUA,CAAIC,MAI7B,EAAK;EACL,MAAMF,QAAQ,GAAGV,eAAe,CAAC,CAAC;EAClC,IAAIU,QAAQ,KAAK,SAAS,IAAIE,MAAM,CAACC,OAAO,KAAKL,SAAS,EAAE,OAAOI,MAAM,CAACC,OAAO;EACjF,IAAIH,QAAQ,KAAK,KAAK,IAAIE,MAAM,CAACE,GAAG,KAAKN,SAAS,EAAE,OAAOI,MAAM,CAACE,GAAG;EACrE,OAAOF,MAAM,CAACG,OAAO;AACtB;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,UAAUA,CAAA,EAAY;EACrC,IAAI,OAAOC,OAAO,KAAK,WAAW,EAAE,OAAOA,OAAO,KAAK,IAAI;EAC3D,MAAM;IAAEC;EAAQ,CAAC,GAAGC,UAAwE;EAC5F,OAAOD,OAAO,EAAEE,GAAG,EAAEC,QAAQ,KAAK,YAAY;AAC/C;AAEA,SACCC,YAAY,EACZC,kBAAkB,EAClBC,YAAY,QAIN,gBAAa","ignoreList":[]}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The app's lifecycle as one port (PERF-07, CORE-14).
|
|
5
|
+
*
|
|
6
|
+
* rn-camera, rn-payment, rn-ads and rn-notification each subscribed to React
|
|
7
|
+
* Native's `AppState` on their own, with their own idea of what `inactive` means.
|
|
8
|
+
* `appLifecycle()` is one shared, reference-counted subscription: the native
|
|
9
|
+
* listener exists only while somebody listens, and every package sees the same
|
|
10
|
+
* transitions in the same order.
|
|
11
|
+
*
|
|
12
|
+
* `react-native` is required on first subscribe, never at import, so this module
|
|
13
|
+
* loads under plain Node too, where the app counts as always `active`.
|
|
14
|
+
*/
|
|
15
|
+
import { lazyPeer } from "../lazy/index.js";
|
|
16
|
+
import { createListenerSet } from "../listeners/index.js";
|
|
17
|
+
|
|
18
|
+
/** The slice of React Native's `AppState` the port reads. */
|
|
19
|
+
|
|
20
|
+
const reactNative = lazyPeer('react-native', () => require('react-native'));
|
|
21
|
+
function defaultSource() {
|
|
22
|
+
const result = reactNative.get();
|
|
23
|
+
return result.ok ? result.module.AppState : undefined;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* `unknown` (iOS before the first report) and anything newer than this SDK count
|
|
28
|
+
* as `active`: an app that is running code it cannot place is most likely in front.
|
|
29
|
+
*/
|
|
30
|
+
function normalize(raw) {
|
|
31
|
+
return raw === 'background' || raw === 'inactive' ? raw : 'active';
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* A lifecycle port over `source`, React Native's `AppState` by default. Packages use
|
|
36
|
+
* the shared `appLifecycle()`; this is for tests and for an app with its own source.
|
|
37
|
+
*/
|
|
38
|
+
export function createAppLifecycle(source = defaultSource) {
|
|
39
|
+
const listeners = createListenerSet();
|
|
40
|
+
let subscription;
|
|
41
|
+
let last = 'active';
|
|
42
|
+
const read = () => normalize(source()?.currentState);
|
|
43
|
+
return {
|
|
44
|
+
current() {
|
|
45
|
+
return subscription ? last : read();
|
|
46
|
+
},
|
|
47
|
+
subscribe(listener) {
|
|
48
|
+
const remove = listeners.add(listener);
|
|
49
|
+
if (!subscription) {
|
|
50
|
+
const appState = source();
|
|
51
|
+
last = normalize(appState?.currentState);
|
|
52
|
+
subscription = appState?.addEventListener('change', raw => {
|
|
53
|
+
const next = normalize(raw);
|
|
54
|
+
if (next === last) return;
|
|
55
|
+
const previous = last;
|
|
56
|
+
last = next;
|
|
57
|
+
listeners.notify(next, previous);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
let attached = true;
|
|
61
|
+
return () => {
|
|
62
|
+
if (!attached) return;
|
|
63
|
+
attached = false;
|
|
64
|
+
remove();
|
|
65
|
+
if (listeners.size === 0 && subscription) {
|
|
66
|
+
subscription.remove();
|
|
67
|
+
subscription = undefined;
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
},
|
|
71
|
+
get listenerCount() {
|
|
72
|
+
return listeners.size;
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
let shared;
|
|
77
|
+
|
|
78
|
+
/** The app's lifecycle, shared by every package so there is one native subscription. */
|
|
79
|
+
export function appLifecycle() {
|
|
80
|
+
shared ??= createAppLifecycle();
|
|
81
|
+
return shared;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Calls `listener` each time the app comes back from the background. A trip through
|
|
86
|
+
* `inactive` alone (iOS Control Center, an incoming-call banner) is not a return.
|
|
87
|
+
*/
|
|
88
|
+
export function onForeground(listener, port = appLifecycle()) {
|
|
89
|
+
let away = port.current() === 'background';
|
|
90
|
+
return port.subscribe(state => {
|
|
91
|
+
if (state === 'background') {
|
|
92
|
+
away = true;
|
|
93
|
+
} else if (state === 'active' && away) {
|
|
94
|
+
away = false;
|
|
95
|
+
listener();
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=lifecycle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["lazyPeer","createListenerSet","reactNative","require","defaultSource","result","get","ok","module","AppState","undefined","normalize","raw","createAppLifecycle","source","listeners","subscription","last","read","currentState","current","subscribe","listener","remove","add","appState","addEventListener","next","previous","notify","attached","size","listenerCount","shared","appLifecycle","onForeground","port","away","state"],"sourceRoot":"../../../src","sources":["runtime/lifecycle.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,QAAQ,QAAQ,kBAAS;AAClC,SAASC,iBAAiB,QAA0B,uBAAc;;AAiBlE;;AAUA,MAAMC,WAAW,GAAGF,QAAQ,CAC3B,cAAc,EACd,MAAMG,OAAO,CAAC,cAAc,CAC7B,CAAC;AAED,SAASC,aAAaA,CAAA,EAA+B;EACpD,MAAMC,MAAM,GAAGH,WAAW,CAACI,GAAG,CAAC,CAAC;EAChC,OAAOD,MAAM,CAACE,EAAE,GAAGF,MAAM,CAACG,MAAM,CAACC,QAAQ,GAAGC,SAAS;AACtD;;AAEA;AACA;AACA;AACA;AACA,SAASC,SAASA,CAACC,GAA8B,EAAqB;EACrE,OAAOA,GAAG,KAAK,YAAY,IAAIA,GAAG,KAAK,UAAU,GAAGA,GAAG,GAAG,QAAQ;AACnE;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAASC,kBAAkBA,CACjCC,MAAwC,GAAGV,aAAa,EACrC;EACnB,MAAMW,SAAS,GAA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