Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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;
}
mirrorDidPressDown(charge: ChargeView, view: MirrorView): void {
const id = charge.id;
const x = Math.round(charge.originX.state! * 10000) / 10000;
const y = Math.round(charge.originY.state! * 10000) / 10000;
const phaseCount = charge._phases.length;
const phases = Record.create(phaseCount);
for (let i = 1; i < phaseCount; i += 1) {
const phase = Math.round(charge._phases[i] * 100) / 100;
phases.item(phase);
}
const color = charge.chargeColor.state!.toString();
const command = Record.create(5)
.slot("id", id)
.slot("x", x)
.slot("y", y)
.slot("phases", phases)
.slot("color", color);
this.nodeRef.command("ripple", command);
}
mirrorDidPressHold(charge: ChargeView, view: MirrorView): void {
const id = charge.id;
const x = Math.round(charge.centerX.state! * 10000) / 10000;
const y = Math.round(charge.centerY.state! * 10000) / 10000;
const r = charge.chargeRadius.state! / 2;
const color = charge.chargeColor.state!.toString();
const command = Record.create(6)
.attr("hold")
.slot("id", id)
.slot("x", x)
.slot("y", y)
.slot("r", r)
.slot("color", color);
this.nodeRef.command("charge", command);
}
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;
}
shift(): Value {
if (this._state.length > 0) {
this.listWillRemove(0);
const oldEntry = this._state.getEntry(0)!;
this._state.remove(0);
this.listDidRemove(0, oldEntry[1]);
const header = Record.create(2).slot("key", oldEntry[0]).slot("index", 0);
this.command(Record.create(1).attr("remove", header));
return oldEntry[1];
} else {
return Value.absent();
}
}
remove(index: number, 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);
}
this.listWillRemove(index);
const oldEntry = this._state.getEntry(index)!;
this._state.remove(index);
this.listDidRemove(index, oldEntry[1]);
const header = Record.create(2).slot("key", oldEntry[0]).slot("index", index);
this.command(Record.create(1).attr("remove", header));
return this;
}
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;
}
pop(): Value {
const index = this._state.length - 1;
if (index >= 0) {
this.listWillRemove(index);
const oldEntry = this._state.getEntry(index)!;
this._state.remove(index);
this.listDidRemove(index, oldEntry[1]);
const header = Record.create(2).slot("key", oldEntry[0]).slot("index", index);
this.command(Record.create(1).attr("remove", header));
return oldEntry[1];
} else {
return Value.absent();
}
}
mirrorDidPressDown(charge: ChargeView, view: MirrorView): void {
const id = charge.id;
const x = Math.round(charge.originX.state! * 10000) / 10000;
const y = Math.round(charge.originY.state! * 10000) / 10000;
const phaseCount = charge._phases.length;
const phases = Record.create(phaseCount);
for (let i = 1; i < phaseCount; i += 1) {
const phase = Math.round(charge._phases[i] * 100) / 100;
phases.item(phase);
}
const color = charge.chargeColor.state!.toString();
const command = Record.create(5)
.slot("id", id)
.slot("x", x)
.slot("y", y)
.slot("phases", phases)
.slot("color", color);
this.nodeRef.command("ripple", command);
}
if (fromIndex < 0) {
throw new RangeError("" + key);
}
}
if (fromIndex < 0 || fromIndex >= this._state.length) {
throw new RangeError("" + fromIndex);
}
if (toIndex < 0 || toIndex >= this._state.length) {
throw new RangeError("" + toIndex);
}
if (fromIndex !== toIndex) {
const entry = this._state.getEntry(fromIndex)!;
this.listWillMove(fromIndex, toIndex, entry[1]);
this._state.remove(fromIndex).insert(toIndex, entry[1], entry[0]);
this.listDidMove(fromIndex, toIndex, entry[1]);
const header = Record.create(2).slot("key", entry[0]).slot("from", fromIndex).slot("to", toIndex);
this.command(Record.create(1).attr("move", header));
}
return this;
}