class-o-mat
Version:
ALPHA VERSION ONLY: class-o-mats will help to create getter-setter functionality with validations that can be attached to a container class for easier coding. Some basic validations are included. class-o-mats also has the ability to store params as bloc
62 lines (45 loc) • 1.08 kB
JavaScript
import Bunyan from 'bunyan';
const log = Bunyan.createLogger({name: "Collection"});
import { COLLECTION, NONE } from '../constants/types';
class Collection {
TYPE = COLLECTION;
constructor(parent, key, ___key, value=NONE) {
this._params = {
key,
___key,
parent,
value: parent[___key]()
}
}
$() {
return this._params.parent;
}
values() {
return this._params.parent.params()[this._params.___key];
}
add(_value) {
const { ___key, parent } = this._params;
let value = parent[___key]();
value = this._add(value, _value);
return this;
}
add$(_value) {
this.add(_value);
return this._params.parent;
}
clear() {
this._params.parent.params()[this._params.___key] = [];
}
next() {
const { ___key, parent } = this._params;
let value = parent[___key]();
const values = this._next(value);
parent._params[___key] = values.value;
return values.nextValue;
}
next$() {
this.next();
return this._params.parent();
}
}
export default Collection;