| 319 | } |
| 320 | |
| 321 | private init() { |
| 322 | if (this.map === null) { |
| 323 | this.map = new Map<string, string[]>(); |
| 324 | } |
| 325 | if (this.cloneFrom !== null) { |
| 326 | this.cloneFrom.init(); |
| 327 | |
| 328 | for (const [key, values] of this.cloneFrom.map!.entries()) { |
| 329 | this.map!.set(key, values); |
| 330 | } |
| 331 | |
| 332 | this.updates!.forEach((update) => { |
| 333 | switch (update.op) { |
| 334 | case 'a': |
| 335 | case 's': |
| 336 | const base = update.op === 'a' ? (this.map!.get(update.param) || []).slice() : []; |
| 337 | base.push(valueToString(update.value!)); |
| 338 | this.map!.set(update.param, base); |
| 339 | break; |
| 340 | case 'd': |
| 341 | if (update.value !== undefined) { |
| 342 | const base = (this.map!.get(update.param) || []).slice(); |
| 343 | const idx = base.indexOf(valueToString(update.value)); |
| 344 | if (idx !== -1) { |
| 345 | base.splice(idx, 1); |
| 346 | } |
| 347 | if (base.length > 0) { |
| 348 | this.map!.set(update.param, base); |
| 349 | } else { |
| 350 | this.map!.delete(update.param); |
| 351 | } |
| 352 | } else { |
| 353 | this.map!.delete(update.param); |
| 354 | break; |
| 355 | } |
| 356 | } |
| 357 | }); |
| 358 | this.cloneFrom = this.updates = null; |
| 359 | } |
| 360 | } |
| 361 | } |