Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
this.listWillRemove(start);
const oldEntry = this._state.getEntry(start)!;
deleted.push(oldEntry[1]);
this._state.remove(start);
this.listDidRemove(start, oldEntry[1]);
const header = Record.create(2).slot("key", oldEntry[0]).slot("index", start);
this.command(Record.create(1).attr("remove", header));
}
for (let i = 0; i < newValues.length; i += 1) {
const index = start + i;
const newValue = this.listWillUpdate(index, newValues[i]);
this._state.insert(index, newValue);
const newEntry = this._state.getEntry(index)!;
this.listDidUpdate(index, newValue, Value.absent());
const header = Record.create(2).slot("key", newEntry[0]).slot("index", index);
this.command(Attr.of("update", header).concat(newValue));
}
return deleted;
}
insert(index: number, newValue: Value, key?: Value): this {
if (index < 0 || index > this._state.length) {
throw new RangeError("" + index);
}
newValue = this.listWillUpdate(index, newValue);
this._state.insert(index, newValue, key);
const newEntry = this._state.getEntry(index)!;
this.listDidUpdate(index, newValue, Value.absent());
const header = Record.create(2).slot("key", newEntry[0]).slot("index", index);
this.command(Attr.of("update", header).concat(newValue));
return this;
}
push(...newValues: Value[]): number {
for (let i = 0; i < newValues.length; i += 1) {
const index = this._state.length + i;
const newValue = this.listWillUpdate(index, newValues[i]);
this._state.insert(index, newValue);
const newEntry = this._state.getEntry(index)!;
this.listDidUpdate(index, newValue, Value.absent());
const header = Record.create(2).slot("key", newEntry[0]).slot("index", index);
this.command(Attr.of("update", header).concat(newValue));
}
return this._state.length;
}
unshift(...newValues: Value[]): number {
for (let i = newValues.length - 1; i >= 0; i -= 1) {
const newValue = this.listWillUpdate(0, newValues[i]);
this._state.insert(0, newValue);
const newEntry = this._state.getEntry(0)!;
this.listDidUpdate(0, newValue, Value.absent());
const header = Record.create(2).slot("key", newEntry[0]).slot("index", 0);
this.command(Attr.of("update", header).concat(newValue));
}
return this._state.length;
}
set(index: number, newValue: Value, key?: Value): this {
if (key !== void 0) {
index = this._state.lookup(key, index);
if (index < 0) {
throw new RangeError("" + key);
}
}
if (index < 0 || index >= this._state.length) {
throw new RangeError("" + index);
}
newValue = this.listWillUpdate(index, newValue);
const oldEntry = this._state.getEntry(index)!;
this._state.set(index, newValue);
this.listDidUpdate(index, newValue, oldEntry[1]);
const header = Record.create(2).slot("key", oldEntry[0]).slot("index", index);
this.command(Attr.of("update", header).concat(newValue));
return this;
}