| 305 | } |
| 306 | |
| 307 | private init() { |
| 308 | if (this.map === null) { |
| 309 | this.map = new Map<string, string[]>(); |
| 310 | } |
| 311 | if (this.cloneFrom !== null) { |
| 312 | this.cloneFrom.init(); |
| 313 | |
| 314 | for (const [key, values] of this.cloneFrom.map!.entries()) { |
| 315 | this.map!.set(key, values); |
| 316 | } |
| 317 | |
| 318 | this.updates!.forEach((update) => { |
| 319 | switch (update.op) { |
| 320 | case 'a': |
| 321 | case 's': |
| 322 | const base = update.op === 'a' ? (this.map!.get(update.param) || []).slice() : []; |
| 323 | base.push(valueToString(update.value!)); |
| 324 | this.map!.set(update.param, base); |
| 325 | break; |
| 326 | case 'd': |
| 327 | if (update.value !== undefined) { |
| 328 | const base = (this.map!.get(update.param) || []).slice(); |
| 329 | const idx = base.indexOf(valueToString(update.value)); |
| 330 | if (idx !== -1) { |
| 331 | base.splice(idx, 1); |
| 332 | } |
| 333 | if (base.length > 0) { |
| 334 | this.map!.set(update.param, base); |
| 335 | } else { |
| 336 | this.map!.delete(update.param); |
| 337 | } |
| 338 | } else { |
| 339 | this.map!.delete(update.param); |
| 340 | break; |
| 341 | } |
| 342 | } |
| 343 | }); |
| 344 | this.cloneFrom = this.updates = null; |
| 345 | } |
| 346 | } |
| 347 | } |