({ update, where, code } = {})
| 113 | store.sync = data; |
| 114 | }, |
| 115 | async UpdateScript({ update, where, code } = {}) { |
| 116 | if (!update) return; |
| 117 | if (updateThrottle |
| 118 | || (updateThrottle = store.batch) |
| 119 | && (updateThrottle = Promise.race([updateThrottle, makePause(500)]))) { |
| 120 | await updateThrottle; |
| 121 | updateThrottle = null; |
| 122 | } |
| 123 | const i1 = store.scripts.findIndex(item => item.props.id === where.id); |
| 124 | const i2 = store.removedScripts.findIndex(item => item.props.id === where.id); |
| 125 | // JS engines like V8 deoptimize when accessing an array element out of bounds |
| 126 | const oldScript = i1 >= 0 ? store.scripts[i1] : i2 >= 0 ? store.removedScripts[i2] : null; |
| 127 | const script = oldScript |
| 128 | || update.meta && store.canRenderScripts && {}; // a new script was just saved or installed |
| 129 | if (!script) return; // We're in editor that doesn't have data for all scripts |
| 130 | const removed = update.config?.removed; |
| 131 | const oldTags = oldScript ? getUniqTags(oldScript) : ''; |
| 132 | const [sizes] = await sendCmdDirectly('GetSizes', [where.id]); |
| 133 | Object.assign(script, update); |
| 134 | if (script.error && !update.error) script.error = null; |
| 135 | initScript(script, sizes, code); |
| 136 | if (removed != null) { |
| 137 | if (removed) { |
| 138 | // Note that we don't update store.scripts even if a script is removed, |
| 139 | // because we want to keep the removed script there to allow the user |
| 140 | // to undo an accidental removal. |
| 141 | // We will update store.scripts when the installed list is rerendered. |
| 142 | store.needRefresh = true; |
| 143 | } else { |
| 144 | // Restored from the recycle bin. |
| 145 | store.removedScripts = store.removedScripts.filter(rs => rs.props.id !== where.id); |
| 146 | } |
| 147 | } |
| 148 | // Update the new list |
| 149 | const i = script.config.removed ? i2 : i1; |
| 150 | const area = script.config.removed ? 'removedScripts' : SCRIPTS; |
| 151 | const list = [...store[area]]; |
| 152 | if (i < 0) { |
| 153 | script.message = ''; |
| 154 | list.push(script); |
| 155 | } |
| 156 | store[area] = list; |
| 157 | if (store.tags && (removed != null ? oldTags : oldTags !== getUniqTags(script))) { |
| 158 | updateTags(); |
| 159 | } |
| 160 | }, |
| 161 | RemoveScripts(ids) { |
| 162 | store.removedScripts = store.removedScripts.filter(script => !ids.includes(script.props.id)); |
| 163 | }, |
nothing calls this directly
no test coverage detected