Collection Wrapper
A basic library to help you create collection(collect.js) variants, for example form fields or table columns. Establish behavior and manipulate collections in dedicated classes. Keeping your code clean and comprehensible.
Install
yarn add collection-wrapper
Usage
Define a 'ExampleFields' class, and get the defined 'toCreate' variant:
import { Fields } from 'collection-wrapper'
export default class ExampleFields extends Fields {
fields() {
return [
{
name: 'name',
type: 'text-field',
prop: {
label: 'Name'
},
},
{
name: 'last_name',
type: 'text-field',
prop: {
label: 'Last name'
},
},
]
}
static toCreate() {
return this.reduce('name', ['name'])
}
}
Use the defined 'ExampleFields' class with the 'toCreate' variant:
import ExampleFields from './example.fields.js'
var fields = ExampleFields.toCreate()
The result of 'toCreate' variant is:
[
{
name: 'name',
type: 'text-field',
prop: {
label: 'Name'
},
}
]