MCPcopy Index your code
hub / github.com/angular/angular / serializeTransferState

Function serializeTransferState

devtools/src/app/transfer-state.ts:15–154  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

13 * This function serializes the transfer state into the DOM.
14 */
15export function serializeTransferState(): void {
16 const doc = inject(DOCUMENT);
17 const appId = inject(APP_ID);
18 const transferState = inject(TransferState);
19 const httpClient = inject(HttpClient);
20
21 // Object
22 transferState.set(makeStateKey<any>('obj'), {
23 appName: 'DevTools',
24 appVersion: '0.0.1',
25 appDescription: 'Angular DevTools',
26 });
27
28 // Array of primitives
29 transferState.set(makeStateKey<any>('arr'), [1, 2, 3, 4, 5]);
30
31 // Primitives — exercise each badge color and primitive renderer
32 transferState.set(makeStateKey<any>('flag'), true);
33 transferState.set(makeStateKey<any>('count'), 42);
34 transferState.set(makeStateKey<any>('largeNumber'), 1234567890);
35 transferState.set(makeStateKey<any>('greeting'), 'Hello, world!');
36 transferState.set(makeStateKey<any>('nothing'), null);
37
38 // Empty containers — exercise "{}" / "[]" preview
39 transferState.set(makeStateKey<any>('emptyObj'), {});
40 transferState.set(makeStateKey<any>('emptyArr'), []);
41
42 // Unicode — exercises UTF-8 byte size (multi-byte characters)
43 transferState.set(makeStateKey<any>('unicode'), '안녕하세요 🅰️ Angular ✨');
44
45 // Long string — exercises wrapping and size (~500 B → kilobyte threshold nearby)
46 transferState.set(
47 makeStateKey<any>('longString'),
48 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. ' +
49 'Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. ' +
50 'Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ' +
51 'ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit ' +
52 'esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non ' +
53 'proident, sunt in culpa qui officia deserunt mollit anim id est laborum.',
54 );
55
56 // Mixed array — primitives, null, and a nested object
57 transferState.set(makeStateKey<any>('mixedArr'), [1, 'two', true, null, {three: 3}, [4, 5, 6]]);
58
59 // Deeply nested object — exercises tree expansion levels
60 transferState.set(makeStateKey<any>('deepNested'), {
61 level1: {
62 level2: {
63 level3: {
64 level4: {
65 level5: {
66 message: 'You found me!',
67 path: ['level1', 'level2', 'level3', 'level4', 'level5'],
68 },
69 },
70 },
71 },
72 },

Callers 1

app.config.tsFile · 0.90

Calls 7

injectFunction · 0.90
makeStateKeyFunction · 0.90
setMethod · 0.65
createElementMethod · 0.65
setAttributeMethod · 0.65
appendChildMethod · 0.65
toJsonMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…