Array of Type Switch

node v10.24.1
version: 1.0.0
endpointsharetweet
const { create, ArrayType, Any, StringType } = require('microstates'); class Text extends Any { constructor() { super() this.input = create(StringType) } } class Select extends Any { } class Stepper extends Any { } function FieldSwitch(field) { switch(field.type) { case 'text': return create(Text, field); case 'select': return create(Select, field); case 'stepper': return create(Stepper, field); } } let fields = create(ArrayType.of(FieldSwitch), [{ type: 'text' }, { type: 'select' }, { type: 'stepper' }])
[...fields]
[...fields].map(i => i.state)
[...[...fields][0].input.set('hello world')]
Loading…

no comments

    sign in to comment