reactronic
Version:
Reactronic - Transactional Reactive State Management
59 lines (58 loc) • 3.1 kB
JavaScript
import { Sealant } from "../util/Sealant.js";
import { MvccObject } from "./Mvcc.js";
export class MvccArray extends MvccObject {
constructor(isSignalling, array) {
super(isSignalling);
this.impl = array;
}
get length() { return this.impl.length; }
set length(n) { this.mutable.length = n; }
getItem(n) { return this.impl[n]; }
setItem(n, item) { this.mutable[n] = item; }
toString() { return this.impl.toString(); }
toLocaleString() { return this.impl.toLocaleString(); }
pop() { return this.mutable.pop(); }
push(...items) { return this.mutable.push(...items); }
concat(...items) { return this.impl.concat(...items); }
join(separator) { return this.impl.join(separator); }
reverse() { return this.mutable.reverse(); }
shift() { return this.mutable.shift(); }
slice(start, end) { return this.impl.slice(start, end); }
sort(compareFn) { this.mutable.sort(compareFn); return this; }
splice(start, deleteCount, ...items) { return this.mutable.splice(start, deleteCount, ...items); }
unshift(...items) { return this.mutable.unshift(...items); }
includes(searchElement, fromIndex) { return this.impl.includes(searchElement, fromIndex); }
indexOf(searchElement, fromIndex) { return this.impl.indexOf(searchElement, fromIndex); }
lastIndexOf(searchElement, fromIndex) { return this.impl.lastIndexOf(searchElement, fromIndex); }
every(predicate, thisArg) { return this.impl.every(predicate, thisArg); }
some(predicate, thisArg) { return this.impl.some(predicate, thisArg); }
forEach(callbackfn, thisArg) { return this.impl.forEach(callbackfn, thisArg); }
map(callbackfn, thisArg) { return this.impl.map(callbackfn, thisArg); }
filter(predicate, thisArg) { return this.impl.filter(predicate, thisArg); }
reduce(callbackfn, initialValue) { return initialValue !== undefined ? this.impl.reduce(callbackfn, initialValue) : this.impl.reduce(callbackfn); }
reduceRight(callbackfn, initialValue) { return initialValue !== undefined ? this.impl.reduceRight(callbackfn, initialValue) : this.impl.reduceRight(callbackfn); }
find(predicate, thisArg) { return this.impl.find(predicate, thisArg); }
findIndex(predicate, thisArg) { return this.impl.findIndex(predicate, thisArg); }
fill(value, start, end) { this.mutable.fill(value, start, end); return this; }
copyWithin(target, start, end) { this.mutable.copyWithin(target, start, end); return this; }
[Symbol.iterator]() { return this.impl[Symbol.iterator](); }
entries() { return this.impl.entries(); }
keys() { return this.impl.keys(); }
values() { return this.impl.values(); }
get mutable() {
const createCopy = this.impl[Sealant.CreateCopy];
if (createCopy)
return this.impl = createCopy.call(this.impl);
return this.impl;
}
}
export class TxArray extends MvccArray {
constructor(...args) {
super(false, new Array(...args));
}
}
export class SxArray extends MvccArray {
constructor(...args) {
super(true, new Array(...args));
}
}