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

Method toJson

packages/core/src/transfer_state.ts:139–155  ·  view source on GitHub ↗

* Serialize the current state of the store to JSON.

()

Source from the content-addressed store, hash-verified

137 * Serialize the current state of the store to JSON.
138 */
139 toJson(): string {
140 // Call the onSerialize callbacks and put those values into the store.
141 for (const key in this.onSerializeCallbacks) {
142 if (Object.hasOwn(this.onSerializeCallbacks, key)) {
143 try {
144 this.store[key] = this.onSerializeCallbacks[key]();
145 } catch (e) {
146 console.warn('Exception in onSerialize callback: ', e);
147 }
148 }
149 }
150
151 // Escape script tag to avoid break out of <script> tag in serialized output.
152 // Encoding of `<` is the same behaviour as G3 script_builders.
153 // Encoding of `/` prevents crawlers from incorrectly indexing relative URLs in inline JSON.
154 return JSON.stringify(this.store).replace(/</g, '\\u003C').replace(/\//g, '\\u002F');
155 }
156}
157
158export function retrieveTransferredState(

Callers 4

serializeTransferStateFunction · 0.45

Calls 2

warnMethod · 0.65
replaceMethod · 0.45

Tested by

no test coverage detected