Skip to content

dicalj/collection-wrapper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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'
    },
  }
]

About

A basic library to help you create collection variants.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published