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

Function retrieveTransferredState

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

Source from the content-addressed store, hash-verified

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

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