This repository was archived by the owner on Sep 17, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
Group
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.
/* if in src/ */
import { Group } from './models/Utils'Group extends Immutable.Record using the following pattern:
Class Group extends Immutable.Record({
id: null,
name: null,
children: Immutable.OrderedMap()
})-
Group.idexpects eithernullor an identifier. This identifier MUST be unique.
-
Group.nameexpects eithernullor a name in aStringformat. There isn't a uniqueness constraint on theGroup.nameamong 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.childrenexpects an Immutable.OrderedMap of either Group or Request objects. We recommend using theGroup.idorRequest.idfields if they are available as keys for the OrderedMap.
In addition to these fields, Group also provides a function that can help manipulate its data:
-
Group.mergeWithGroup(group)adds a Group in another based on thegroup.name. If a child with the same name asgroupalready exists in the base group, the child andgroupare merged together.
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])