ractive-ez-table
Version:
Ractive Ez UI Table
68 lines (50 loc) • 1.41 kB
JavaScript
class ItemIterator {
constructor(items) {
this.index = 0;
this.items = items;
};
end() {
return this.index >= this.items.length;
};
next() {
return this.items[this.index++];
}
};
class GroupIterator {
constructor(groups) {
this.index = 0;
this.groups = groups;
this.currentIterator = this.nextIterator();
}
end() {
return (this.currentIterator == null)
|| (this.currentIterator.end() && this.index >= this.groups.length);
}
nextIterator() {
const group = this.groups[this.index++];
if (group == null) return null;
return group.subGroups
? new GroupIterator(group.subGroups)
: new ItemIterator(group.items);
}
next() {
if (this.currentIterator.end()) this.currentIterator = this.nextIterator();
return this.currentIterator.next();
}
}
class TableIterator {
constructor(table) {
const root = table.get("_root");
this.table = table;
this.iterator = root.subGroups
? new GroupIterator(root.subGroups)
: new ItemIterator(root.items);
}
end() {
return this.iterator.end();
}
next() {
return this.iterator.next();
}
}
export default TableIterator;