MCPcopy Create free account
hub / github.com/angular/angular / retrieveTransferredState

Function retrieveTransferredState

packages/core/src/transfer_state.ts:160–182  ·  view source on GitHub ↗
(
  doc: Document,
  appId: string,
)

Source from the content-addressed store, hash-verified

158}
159
160export function retrieveTransferredState(
161 doc: Document,
162 appId: string,
163): Record<string, unknown | undefined> {
164 // Locate the script tag with the JSON data transferred from the server.
165 // The id of the script tag is set to the Angular appId + 'state'.
166 const script = doc.getElementById(appId + '-state');
167 if (script?.tagName === 'SCRIPT' && script.textContent) {
168 try {
169 // Avoid using any here as it triggers lint errors in google3 (any is not allowed).
170 // Decoding of `<` is done of the box by browsers and node.js, same behaviour as G3
171 // script_builders.
172 return Object.assign(
173 createDictionary<unknown | undefined>(),
174 JSON.parse(script.textContent) as {},
175 );
176 } catch (e) {
177 console.warn('Exception while restoring TransferState for app ' + appId, e);
178 }
179 }
180
181 return createDictionary();
182}

Callers 2

getTransferStateFunction · 0.90
TransferStateClass · 0.85

Calls 3

createDictionaryFunction · 0.85
parseMethod · 0.65
warnMethod · 0.65

Tested by

no test coverage detected