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