Skip to content
JonathanMontane edited this page Apr 28, 2016 · 5 revisions

Group components serve as architectural elements that allow nesting. They contain three fields named id, name, and children. Although the Group.children can accept objects of any type, there are non-enforced restrictions on what should be used.

Import

/* if in src/ */
import { Group } from './models/Utils'

Interface

Group extends Immutable.Record using the following pattern:

Class Group extends Immutable.Record({
   id: null,
   name: null,
   children: Immutable.OrderedMap()
})

Fields

Group.id
  • Group.id expects either null or an identifier. This identifier MUST be unique.
Group.name
  • Group.name expects either null or a name in a String format. There isn't a uniqueness constraint on the Group.name among Groups, however we strongly encourage people to design their parsers in a way that ensures uniqueness of the name, as this facilitates debugging, and API-Flow was built using name as identifiers instead of ids for legacy reasons.
Group.children
  • Group.children expects an Immutable.OrderedMap of either Group or Request objects. We recommend using the Group.id or Request.id fields if they are available as keys for the OrderedMap.

Methods

In addition to these fields, Group also provides a function that can help manipulate its data:

mergeWithGroup
  • Group.mergeWithGroup(group) adds a Group in another based on the group.name. If a child with the same name as group already exists in the base group, the child and group are merged together.

Example

import groups from './samples/group-examples'
import requests from './samples/request-examples'

import { Group } from './models/Utils'

let group = new Group({
    id: '1c381885-87ac-4e4f-9fcc-b8482164e43e'
    name: 'digital'
    children: new Immutable.OrderedMap({
        '0915e653-d12c-4424-a014-9e8c2079b167': groups[0],
        'dbb761e5-4ad0-48e9-8c8c-ab3cd3c3f547': groups[1],
        'GET': requests[0],
        'POST': requests[1],
    })
})

group = group
    .set('id', '11478d6d-b0fa-4b7a-a072-a5a855e53c6f')
    .set('name', 'metrics')
    .set('children', new Immutable.OrderedMap({
        '0915e653-d12c-4424-a014-9e8c2079b167': groups[2],
        'dbb761e5-4ad0-48e9-8c8c-ab3cd3c3f547': groups[3],
    }))
    .setIn([ 'children', '0915e653-d12c-4424-a014-9e8c2079b167' ], groups[0])

group = group.mergeWithGroup(group[2])
Clone this wiki locally