@flighthq/lifecycle 0.5.1-next.1295.2b6bfa3 → 0.5.1-next.1345.0995dc5
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 +2 -2
- package/dist/contract.d.ts +1 -1
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +1 -1
- package/dist/contract.js.map +1 -1
- package/dist/lifecycle.d.ts +0 -2
- package/dist/lifecycle.d.ts.map +1 -1
- package/dist/lifecycle.js +0 -105
- package/dist/lifecycle.js.map +1 -1
- package/package.json +4 -4
- package/src/lifecycle.test.ts +0 -90
package/README.md
CHANGED
|
@@ -13,5 +13,5 @@ Import the supported application-facing API from `@flighthq/lifecycle`. The `@fl
|
|
|
13
13
|
This package is part of the locked-version Flight SDK graph. Applications may instead install and import `@flighthq/sdk` when package-level tree shaking is sufficient.
|
|
14
14
|
|
|
15
15
|
- [Flight project](https://github.com/flighthq/flight)
|
|
16
|
-
- [Source for @flighthq/lifecycle@0.5.1-next.
|
|
17
|
-
- [License](https://github.com/flighthq/flight/blob/
|
|
16
|
+
- [Source for @flighthq/lifecycle@0.5.1-next.1345.0995dc5](https://github.com/flighthq/flight/tree/0995dc5f840e6b57c3e85ecd2123aa798cf60b29/packages/lifecycle)
|
|
17
|
+
- [License](https://github.com/flighthq/flight/blob/0995dc5f840e6b57c3e85ecd2123aa798cf60b29/LICENSE.md)
|
package/dist/contract.d.ts
CHANGED
package/dist/contract.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,sBAAsB,EAAE,
|
|
1
|
+
{"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/contract.js
CHANGED
package/dist/contract.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contract.js","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,sBAAsB,EAAE,
|
|
1
|
+
{"version":3,"file":"contract.js","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/lifecycle.d.ts
CHANGED
|
@@ -2,7 +2,6 @@ import type { BackendOperationExplanation, LifecycleOperation, EntityConstructio
|
|
|
2
2
|
import type { AppLaunchKind, HostLifecycleProvider, AppLifecycle, AppLifecycleState } from '@flighthq/types/contract';
|
|
3
3
|
export declare function attachAppLifecycle(hostLifecycle: Readonly<HostLifecycleProvider>, app: AppLifecycle): void;
|
|
4
4
|
export declare function createAppLifecycle(): AppLifecycle;
|
|
5
|
-
export declare function createWebLifecycleBackend(): HostLifecycleProvider;
|
|
6
5
|
export declare function detachAppLifecycle(app: AppLifecycle): void;
|
|
7
6
|
export declare function disposeAppLifecycle(app: AppLifecycle): void;
|
|
8
7
|
export declare function explainLifecycleOperation(hostLifecycle: Readonly<HostLifecycleProvider>, operation: LifecycleOperation): BackendOperationExplanation;
|
|
@@ -10,7 +9,6 @@ export declare function getAppLaunchKind(hostLifecycle: Readonly<HostLifecyclePr
|
|
|
10
9
|
export declare function getAppLifecycleState(hostLifecycle: Readonly<HostLifecycleProvider>): AppLifecycleState;
|
|
11
10
|
export declare function hasLifecycleOperation(hostLifecycle: Readonly<HostLifecycleProvider>, operation: LifecycleOperation): boolean;
|
|
12
11
|
export declare function initializeAppLifecycle(out: EntityConstruction<AppLifecycle>): void;
|
|
13
|
-
export declare function initializeWebLifecycleBackend(out: EntityConstruction<HostLifecycleProvider>): void;
|
|
14
12
|
export declare function isAppActive(hostLifecycle: Readonly<HostLifecycleProvider>): boolean;
|
|
15
13
|
export declare function isAppBackground(hostLifecycle: Readonly<HostLifecycleProvider>): boolean;
|
|
16
14
|
export declare function isAppInactive(hostLifecycle: Readonly<HostLifecycleProvider>): boolean;
|
package/dist/lifecycle.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lifecycle.d.ts","sourceRoot":"","sources":["../src/lifecycle.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,2BAA2B,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AACpH,OAAO,KAAK,EACV,aAAa,EACb,qBAAqB,EACrB,YAAY,EACZ,iBAAiB,EAElB,MAAM,0BAA0B,CAAC;AAYlC,wBAAgB,kBAAkB,CAAC,aAAa,EAAE,QAAQ,CAAC,qBAAqB,CAAC,EAAE,GAAG,EAAE,YAAY,GAAG,IAAI,CAqC1G;AAED,wBAAgB,kBAAkB,IAAI,YAAY,CAIjD;
|
|
1
|
+
{"version":3,"file":"lifecycle.d.ts","sourceRoot":"","sources":["../src/lifecycle.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,2BAA2B,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AACpH,OAAO,KAAK,EACV,aAAa,EACb,qBAAqB,EACrB,YAAY,EACZ,iBAAiB,EAElB,MAAM,0BAA0B,CAAC;AAYlC,wBAAgB,kBAAkB,CAAC,aAAa,EAAE,QAAQ,CAAC,qBAAqB,CAAC,EAAE,GAAG,EAAE,YAAY,GAAG,IAAI,CAqC1G;AAED,wBAAgB,kBAAkB,IAAI,YAAY,CAIjD;AAGD,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,YAAY,GAAG,IAAI,CAM1D;AAID,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,YAAY,GAAG,IAAI,CAG3D;AAID,wBAAgB,yBAAyB,CACvC,aAAa,EAAE,QAAQ,CAAC,qBAAqB,CAAC,EAC9C,SAAS,EAAE,kBAAkB,GAC5B,2BAA2B,CAG7B;AAMD,wBAAgB,gBAAgB,CAAC,aAAa,EAAE,QAAQ,CAAC,qBAAqB,CAAC,GAAG,aAAa,CAG9F;AAGD,wBAAgB,oBAAoB,CAAC,aAAa,EAAE,QAAQ,CAAC,qBAAqB,CAAC,GAAG,iBAAiB,CAEtG;AAGD,wBAAgB,qBAAqB,CACnC,aAAa,EAAE,QAAQ,CAAC,qBAAqB,CAAC,EAC9C,SAAS,EAAE,kBAAkB,GAC5B,OAAO,CAET;AAGD,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,kBAAkB,CAAC,YAAY,CAAC,GAAG,IAAI,CAQlF;AAGD,wBAAgB,WAAW,CAAC,aAAa,EAAE,QAAQ,CAAC,qBAAqB,CAAC,GAAG,OAAO,CAEnF;AAGD,wBAAgB,eAAe,CAAC,aAAa,EAAE,QAAQ,CAAC,qBAAqB,CAAC,GAAG,OAAO,CAEvF;AAID,wBAAgB,aAAa,CAAC,aAAa,EAAE,QAAQ,CAAC,qBAAqB,CAAC,GAAG,OAAO,CAErF;AAOD,wBAAgB,cAAc,CAAC,GAAG,EAAE,YAAY,GAAG,OAAO,CAGzD"}
|
package/dist/lifecycle.js
CHANGED
|
@@ -51,11 +51,6 @@ export function createAppLifecycle() {
|
|
|
51
51
|
initializeAppLifecycle(out);
|
|
52
52
|
return finishEntity(out);
|
|
53
53
|
}
|
|
54
|
-
export function createWebLifecycleBackend() {
|
|
55
|
-
const out = allocateEntity();
|
|
56
|
-
initializeWebLifecycleBackend(out);
|
|
57
|
-
return finishEntity(out);
|
|
58
|
-
}
|
|
59
54
|
// Stops delivery to `app` and forgets its subscription. Safe to call when not attached.
|
|
60
55
|
export function detachAppLifecycle(app) {
|
|
61
56
|
const unsubscribe = _subscriptions.get(app);
|
|
@@ -102,106 +97,6 @@ export function initializeAppLifecycle(out) {
|
|
|
102
97
|
out.onSaveState = createSignal();
|
|
103
98
|
out.onRestoreState = createSignal();
|
|
104
99
|
}
|
|
105
|
-
// Builds the default Web provider over document visibility, window focus/blur, and pagehide/pageshow
|
|
106
|
-
// events. Produces three states:
|
|
107
|
-
// 'active' — document visible and window focused
|
|
108
|
-
// 'inactive' — document visible but window not focused (app switcher, control-center, other window)
|
|
109
|
-
// 'background' — document.hidden (tab hidden or page unloading)
|
|
110
|
-
// Degrades to state 'active' and a no-op subscription where document/window are absent (SSR/jsdom).
|
|
111
|
-
//
|
|
112
|
-
// getLaunchKind() approximates cold vs. warm using PerformanceNavigationTiming.type:
|
|
113
|
-
// 'back_forward' → 'warm' — page was restored from the bfcache (JS heap was frozen and thawed;
|
|
114
|
-
// the closest web equivalent of a process warm-resume)
|
|
115
|
-
// all others → 'cold' — 'navigate', 'reload', 'prerender' are each a fresh page lifecycle
|
|
116
|
-
// Falls back to 'cold' when the Performance Navigation Timing API is unavailable (SSR/jsdom).
|
|
117
|
-
//
|
|
118
|
-
// subscribeMemoryWarning() wires the experimental 'memory-pressure' window event (Chrome origin
|
|
119
|
-
// trial / behind flags). The event detail carries a 'critical' pressure string; this provider maps
|
|
120
|
-
// it to 'critical' and fires 'normal' on the subsequent resolution event when present. Falls back to
|
|
121
|
-
// no-op unsubscribe when the event is not supported (no standard API is widely deployed as of 2026).
|
|
122
|
-
export function initializeWebLifecycleBackend(out) {
|
|
123
|
-
let _windowFocused = typeof document !== 'undefined';
|
|
124
|
-
out.getState = () => {
|
|
125
|
-
if (typeof document === 'undefined')
|
|
126
|
-
return 'active';
|
|
127
|
-
if (document.hidden)
|
|
128
|
-
return 'background';
|
|
129
|
-
return _windowFocused ? 'active' : 'inactive';
|
|
130
|
-
};
|
|
131
|
-
out.subscribe = (listener) => {
|
|
132
|
-
if (typeof document === 'undefined' || typeof window === 'undefined')
|
|
133
|
-
return () => { };
|
|
134
|
-
// Initialize focus state at subscribe time.
|
|
135
|
-
_windowFocused = document.hasFocus();
|
|
136
|
-
const onFocus = () => {
|
|
137
|
-
_windowFocused = true;
|
|
138
|
-
listener();
|
|
139
|
-
};
|
|
140
|
-
const onBlur = () => {
|
|
141
|
-
_windowFocused = false;
|
|
142
|
-
listener();
|
|
143
|
-
};
|
|
144
|
-
document.addEventListener('visibilitychange', listener);
|
|
145
|
-
window.addEventListener('pagehide', listener);
|
|
146
|
-
window.addEventListener('pageshow', listener);
|
|
147
|
-
window.addEventListener('focus', onFocus);
|
|
148
|
-
window.addEventListener('blur', onBlur);
|
|
149
|
-
return () => {
|
|
150
|
-
document.removeEventListener('visibilitychange', listener);
|
|
151
|
-
window.removeEventListener('pagehide', listener);
|
|
152
|
-
window.removeEventListener('pageshow', listener);
|
|
153
|
-
window.removeEventListener('focus', onFocus);
|
|
154
|
-
window.removeEventListener('blur', onBlur);
|
|
155
|
-
};
|
|
156
|
-
};
|
|
157
|
-
out.getLaunchKind = () => {
|
|
158
|
-
// PerformanceNavigationTiming.type === 'back_forward' indicates the page was restored from the
|
|
159
|
-
// browser's back/forward cache (bfcache). The JS heap was frozen and thawed without a fresh
|
|
160
|
-
// process start — the closest analog to a mobile warm-resume. All other navigation types
|
|
161
|
-
// ('navigate', 'reload', 'prerender') are a fresh page lifecycle, i.e. cold.
|
|
162
|
-
if (typeof performance === 'undefined')
|
|
163
|
-
return 'cold';
|
|
164
|
-
const entries = performance.getEntriesByType('navigation');
|
|
165
|
-
if (entries.length > 0 && entries[0].type === 'back_forward')
|
|
166
|
-
return 'warm';
|
|
167
|
-
return 'cold';
|
|
168
|
-
};
|
|
169
|
-
out.subscribeMemoryWarning = (listener) => {
|
|
170
|
-
// The 'memory-pressure' window event is an experimental Chrome API (origin trial / behind
|
|
171
|
-
// flags as of 2026). The event carries a detail object with a 'pressure' string. This provider
|
|
172
|
-
// maps 'critical' pressure to AppMemoryPressure 'critical'; a pressure-resolved / 'moderate'
|
|
173
|
-
// event maps to 'moderate'. Falls back to no-op unsubscribe when the event is not supported
|
|
174
|
-
// (no cross-browser API for memory pressure is widely deployed yet).
|
|
175
|
-
if (typeof window === 'undefined')
|
|
176
|
-
return () => { };
|
|
177
|
-
// Feature-detect: attempt to register and immediately remove a passive listener to check
|
|
178
|
-
// whether the event is supported. If addEventListener silently ignores the event type there
|
|
179
|
-
// is nothing we can do — we just return no-op without pretending to be subscribed.
|
|
180
|
-
const onPressure = (e) => {
|
|
181
|
-
const detail = e.detail;
|
|
182
|
-
const pressure = detail?.pressure;
|
|
183
|
-
if (pressure === 'critical') {
|
|
184
|
-
listener('critical');
|
|
185
|
-
}
|
|
186
|
-
else if (pressure === 'moderate') {
|
|
187
|
-
listener('moderate');
|
|
188
|
-
}
|
|
189
|
-
else {
|
|
190
|
-
// Unknown pressure level — treat as moderate rather than silently dropping.
|
|
191
|
-
listener('moderate');
|
|
192
|
-
}
|
|
193
|
-
};
|
|
194
|
-
const onPressureRelieved = () => {
|
|
195
|
-
listener('normal');
|
|
196
|
-
};
|
|
197
|
-
window.addEventListener('memory-pressure', onPressure);
|
|
198
|
-
window.addEventListener('memory-pressure-relieved', onPressureRelieved);
|
|
199
|
-
return () => {
|
|
200
|
-
window.removeEventListener('memory-pressure', onPressure);
|
|
201
|
-
window.removeEventListener('memory-pressure-relieved', onPressureRelieved);
|
|
202
|
-
};
|
|
203
|
-
};
|
|
204
|
-
}
|
|
205
100
|
// Returns true when the application is in the 'active' state (visible and focused).
|
|
206
101
|
export function isAppActive(hostLifecycle) {
|
|
207
102
|
return hostLifecycle.getState() === 'active';
|
package/dist/lifecycle.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lifecycle.js","sourceRoot":"","sources":["../src/lifecycle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzE,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAUtE,qGAAqG;AACrG,kGAAkG;AAClG,8FAA8F;AAC9F,qGAAqG;AACrG,qFAAqF;AACrF,EAAE;AACF,8FAA8F;AAC9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thq/lifecycle",
|
|
3
|
-
"version": "0.5.1-next.
|
|
3
|
+
"version": "0.5.1-next.1345.0995dc5",
|
|
4
4
|
"author": "Joshua Granick and other contributors",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -38,9 +38,9 @@
|
|
|
38
38
|
"clean:dist": "tsx ../../scripts/clean-package-dist.ts"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@flighthq/entity": "0.5.1-next.
|
|
42
|
-
"@flighthq/signals": "0.5.1-next.
|
|
43
|
-
"@flighthq/types": "0.5.1-next.
|
|
41
|
+
"@flighthq/entity": "0.5.1-next.1345.0995dc5",
|
|
42
|
+
"@flighthq/signals": "0.5.1-next.1345.0995dc5",
|
|
43
|
+
"@flighthq/types": "0.5.1-next.1345.0995dc5"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"typescript": "^5.3.0"
|
package/src/lifecycle.test.ts
CHANGED
|
@@ -12,7 +12,6 @@ import type {
|
|
|
12
12
|
import {
|
|
13
13
|
attachAppLifecycle,
|
|
14
14
|
createAppLifecycle,
|
|
15
|
-
createWebLifecycleBackend,
|
|
16
15
|
detachAppLifecycle,
|
|
17
16
|
disposeAppLifecycle,
|
|
18
17
|
explainLifecycleOperation,
|
|
@@ -20,7 +19,6 @@ import {
|
|
|
20
19
|
getAppLifecycleState,
|
|
21
20
|
hasLifecycleOperation,
|
|
22
21
|
initializeAppLifecycle,
|
|
23
|
-
initializeWebLifecycleBackend,
|
|
24
22
|
isAppActive,
|
|
25
23
|
isAppBackground,
|
|
26
24
|
isAppInactive,
|
|
@@ -321,88 +319,6 @@ describe('createAppLifecycle', () => {
|
|
|
321
319
|
});
|
|
322
320
|
});
|
|
323
321
|
|
|
324
|
-
describe('createWebLifecycleBackend', () => {
|
|
325
|
-
it("getLaunchKind returns 'cold' when no performance navigation entries", () => {
|
|
326
|
-
vi.spyOn(performance, 'getEntriesByType').mockReturnValue([]);
|
|
327
|
-
const backend = createWebLifecycleBackend();
|
|
328
|
-
expect(backend.getLaunchKind?.()).toBe('cold');
|
|
329
|
-
vi.restoreAllMocks();
|
|
330
|
-
});
|
|
331
|
-
|
|
332
|
-
it("getLaunchKind returns 'warm' for back_forward navigation type", () => {
|
|
333
|
-
vi.spyOn(performance, 'getEntriesByType').mockReturnValue([
|
|
334
|
-
{ type: 'back_forward' } as PerformanceNavigationTiming,
|
|
335
|
-
]);
|
|
336
|
-
const backend = createWebLifecycleBackend();
|
|
337
|
-
expect(backend.getLaunchKind?.()).toBe('warm');
|
|
338
|
-
vi.restoreAllMocks();
|
|
339
|
-
});
|
|
340
|
-
|
|
341
|
-
it("getLaunchKind returns 'cold' for reload navigation type", () => {
|
|
342
|
-
vi.spyOn(performance, 'getEntriesByType').mockReturnValue([{ type: 'reload' } as PerformanceNavigationTiming]);
|
|
343
|
-
const backend = createWebLifecycleBackend();
|
|
344
|
-
expect(backend.getLaunchKind?.()).toBe('cold');
|
|
345
|
-
vi.restoreAllMocks();
|
|
346
|
-
});
|
|
347
|
-
|
|
348
|
-
it("getLaunchKind returns 'cold' for navigate navigation type", () => {
|
|
349
|
-
vi.spyOn(performance, 'getEntriesByType').mockReturnValue([{ type: 'navigate' } as PerformanceNavigationTiming]);
|
|
350
|
-
const backend = createWebLifecycleBackend();
|
|
351
|
-
expect(backend.getLaunchKind?.()).toBe('cold');
|
|
352
|
-
vi.restoreAllMocks();
|
|
353
|
-
});
|
|
354
|
-
|
|
355
|
-
it('reads a state without throwing', () => {
|
|
356
|
-
expect(typeof createWebLifecycleBackend().getState()).toBe('string');
|
|
357
|
-
});
|
|
358
|
-
|
|
359
|
-
it('subscribeMemoryWarning fires critical when memory-pressure event fires', () => {
|
|
360
|
-
const backend = createWebLifecycleBackend();
|
|
361
|
-
const levels: AppMemoryPressure[] = [];
|
|
362
|
-
const unsubscribe = backend.subscribeMemoryWarning?.((level) => levels.push(level));
|
|
363
|
-
// Simulate a memory-pressure event with 'critical' pressure detail.
|
|
364
|
-
const event = new CustomEvent('memory-pressure', { detail: { pressure: 'critical' } });
|
|
365
|
-
window.dispatchEvent(event);
|
|
366
|
-
expect(levels).toEqual(['critical']);
|
|
367
|
-
unsubscribe?.();
|
|
368
|
-
});
|
|
369
|
-
|
|
370
|
-
it('subscribeMemoryWarning fires moderate when memory-pressure event fires with moderate pressure', () => {
|
|
371
|
-
const backend = createWebLifecycleBackend();
|
|
372
|
-
const levels: AppMemoryPressure[] = [];
|
|
373
|
-
const unsubscribe = backend.subscribeMemoryWarning?.((level) => levels.push(level));
|
|
374
|
-
const event = new CustomEvent('memory-pressure', { detail: { pressure: 'moderate' } });
|
|
375
|
-
window.dispatchEvent(event);
|
|
376
|
-
expect(levels).toEqual(['moderate']);
|
|
377
|
-
unsubscribe?.();
|
|
378
|
-
});
|
|
379
|
-
|
|
380
|
-
it('subscribeMemoryWarning fires normal when memory-pressure-relieved event fires', () => {
|
|
381
|
-
const backend = createWebLifecycleBackend();
|
|
382
|
-
const levels: AppMemoryPressure[] = [];
|
|
383
|
-
const unsubscribe = backend.subscribeMemoryWarning?.((level) => levels.push(level));
|
|
384
|
-
const event = new CustomEvent('memory-pressure-relieved');
|
|
385
|
-
window.dispatchEvent(event);
|
|
386
|
-
expect(levels).toEqual(['normal']);
|
|
387
|
-
unsubscribe?.();
|
|
388
|
-
});
|
|
389
|
-
|
|
390
|
-
it('subscribeMemoryWarning stops delivering after unsubscribe', () => {
|
|
391
|
-
const backend = createWebLifecycleBackend();
|
|
392
|
-
const levels: AppMemoryPressure[] = [];
|
|
393
|
-
const unsubscribe = backend.subscribeMemoryWarning?.((level) => levels.push(level));
|
|
394
|
-
unsubscribe?.();
|
|
395
|
-
const event = new CustomEvent('memory-pressure', { detail: { pressure: 'critical' } });
|
|
396
|
-
window.dispatchEvent(event);
|
|
397
|
-
expect(levels).toHaveLength(0);
|
|
398
|
-
});
|
|
399
|
-
|
|
400
|
-
it('subscribes and unsubscribes without throwing', () => {
|
|
401
|
-
const unsubscribe = createWebLifecycleBackend().subscribe(() => {});
|
|
402
|
-
expect(() => unsubscribe()).not.toThrow();
|
|
403
|
-
});
|
|
404
|
-
});
|
|
405
|
-
|
|
406
322
|
describe('detachAppLifecycle', () => {
|
|
407
323
|
it('stops further delivery', () => {
|
|
408
324
|
const backend = fakeBackend();
|
|
@@ -544,12 +460,6 @@ describe('initializeAppLifecycle', () => {
|
|
|
544
460
|
});
|
|
545
461
|
});
|
|
546
462
|
|
|
547
|
-
describe('initializeWebLifecycleBackend', () => {
|
|
548
|
-
it('is the construction initializer of createWebLifecycleBackend', () => {
|
|
549
|
-
expect(typeof initializeWebLifecycleBackend).toBe('function');
|
|
550
|
-
});
|
|
551
|
-
});
|
|
552
|
-
|
|
553
463
|
// Per-operation availability for LifecycleBackend. The operations below are the ones the interface declares
|
|
554
464
|
// OPTIONAL, so a host that omits them is compliant rather than broken — that is the absence-of-an-export
|
|
555
465
|
// ruling, and this is the query that makes it observable.
|