UNPKG

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

43 lines (31 loc) 895 B
import Bunyan from 'bunyan'; const log = Bunyan.createLogger({name: "_FieldMethodOMat"}); import { NONE, _FIELD_METHOD_O_MAT } from '../constants/types'; import { getterSetter as gs, toggler as tg } from './class-o-mat-field-functions'; class _FieldMethodOMat { static TYPE = _FIELD_METHOD_O_MAT; TYPE = _FIELD_METHOD_O_MAT; constructor(parent) { this._params = { parent, onGet: false, onSet: true, method: NONE } } method(method) { if (typeof method !== 'function') { throw new Error(`Invalid Reducer method for field: ${parent.key()}`) } return gs(this, 'method', method); } onGet(onGet=true) { this._params.onGet = onGet === true ? true : false; return this; } onSet(onSet=false) { this._params.onSet = onSet === false ? false : true; return this; } } export default _FieldMethodOMat;