| 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 | this.cloneFrom.keys().forEach((key) => this.map!.set(key, this.cloneFrom!.map!.get(key)!)); |
| 328 | this.updates!.forEach((update) => { |
| 329 | switch (update.op) { |
| 330 | case 'a': |
| 331 | case 's': |
| 332 | const base = (update.op === 'a' ? this.map!.get(update.param) : undefined) || []; |
| 333 | base.push(valueToString(update.value!)); |
| 334 | this.map!.set(update.param, base); |
| 335 | break; |
| 336 | case 'd': |
| 337 | if (update.value !== undefined) { |
| 338 | let base = this.map!.get(update.param) || []; |
| 339 | const idx = base.indexOf(valueToString(update.value)); |
| 340 | if (idx !== -1) { |
| 341 | base.splice(idx, 1); |
| 342 | } |
| 343 | if (base.length > 0) { |
| 344 | this.map!.set(update.param, base); |
| 345 | } else { |
| 346 | this.map!.delete(update.param); |
| 347 | } |
| 348 | } else { |
| 349 | this.map!.delete(update.param); |
| 350 | break; |
| 351 | } |
| 352 | } |
| 353 | }); |
| 354 | this.cloneFrom = this.updates = null; |
| 355 | } |
| 356 | } |
| 357 | } |