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