main
Last change
on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
639 bytes
|
Line | |
---|
1 | // @flow
|
---|
2 | import type { Modifier } from '../types';
|
---|
3 |
|
---|
4 | export default function mergeByName(
|
---|
5 | modifiers: Array<$Shape<Modifier<any, any>>>
|
---|
6 | ): Array<$Shape<Modifier<any, any>>> {
|
---|
7 | const merged = modifiers.reduce((merged, current) => {
|
---|
8 | const existing = merged[current.name];
|
---|
9 | merged[current.name] = existing
|
---|
10 | ? {
|
---|
11 | ...existing,
|
---|
12 | ...current,
|
---|
13 | options: { ...existing.options, ...current.options },
|
---|
14 | data: { ...existing.data, ...current.data },
|
---|
15 | }
|
---|
16 | : current;
|
---|
17 | return merged;
|
---|
18 | }, {});
|
---|
19 |
|
---|
20 | // IE11 does not support Object.values
|
---|
21 | return Object.keys(merged).map(key => merged[key]);
|
---|
22 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.