Changeset View
Changeset View
Standalone View
Standalone View
components/component.class.js
module.exports = class Component { | module.exports = class Component { | ||||
constructor({ renderFn, propsControls }) { | constructor(s) { | ||||
if (typeof renderFn !== 'function') { | this.s = s; | ||||
throw new Error('renderFn must be a function'); | |||||
} | } | ||||
if (typeof propsControls !== 'object') { | async render(props) { | ||||
throw new Error('propsControls must be an object'); | return await this.renderFn(this.s, props); | ||||
} | |||||
for (let item in propsControls) { | |||||
if (typeof propsControls[item] !== 'string') { | |||||
throw new Error( | |||||
`${propsControls[item]} formControl is not a string` | |||||
); | |||||
} | |||||
} | |||||
this.renderFn = renderFn; | |||||
this.propsControls = propsControls; | |||||
} | |||||
async render(propsControls) { | |||||
return await this.renderFn(propsControls); | |||||
} | } | ||||
}; | }; |