UNPKG

652 BJavaScriptView Raw
1export function mergeProps(...items) {
2 const ret = {};
3 items.forEach(item => {
4 if (item) {
5 Object.keys(item).forEach(key => {
6 if (item[key] !== undefined) {
7 ret[key] = item[key];
8 }
9 });
10 }
11 });
12 return ret;
13}
14/**
15 * Merge props and return the first non-undefined value.
16 * The later has higher priority. e.g. (10, 1, 5) => 5 wins.
17 * This is useful with legacy props that have been deprecated.
18 */
19export function mergeProp(defaultProp, ...propList) {
20 for (let i = propList.length - 1; i >= 0; i -= 1) {
21 if (propList[i] !== undefined) {
22 return propList[i];
23 }
24 }
25 return defaultProp;
26}
\No newline at end of file