* Serialize the current state of the store to JSON.
()
| 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 | |
| 158 | export function retrieveTransferredState( |
no test coverage detected