-
-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add options prop to Chart component (#2063)
* feat: add options prop to Chart component * fix: improve docs Co-authored-by: Tahimi <tahimileon@gmail.com>
- Loading branch information
1 parent
09326ff
commit 5981410
Showing
5 changed files
with
195 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import merge from '../merge'; | ||
|
||
describe('merge', () => { | ||
it('should merge the objects recursively', () => { | ||
const obj1 = { | ||
key1: 'value1', | ||
key2: { | ||
subKey1: true, | ||
}, | ||
}; | ||
const obj2 = { | ||
key2: { | ||
subKey2: 25, | ||
}, | ||
key3: 'value3', | ||
}; | ||
const resultObj = { | ||
key1: 'value1', | ||
key2: { | ||
subKey1: true, | ||
subKey2: 25, | ||
}, | ||
key3: 'value3', | ||
}; | ||
expect(merge(obj1, obj2)).toEqual(resultObj); | ||
}); | ||
|
||
it('should overwrite existing keys', () => { | ||
const obj1 = { | ||
key: 'value', | ||
}; | ||
const obj2 = { | ||
key: true, | ||
}; | ||
expect(merge(obj1, obj2)).toEqual(obj2); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const merge = (...args) => { | ||
// create a new object | ||
const target = {}; | ||
|
||
// deep merge the object into the target object | ||
const merger = obj => { | ||
const keys = Object.keys(obj); | ||
keys.forEach(prop => { | ||
if (Object.prototype.toString.call(obj[prop]) === '[object Object]') { | ||
// if the property is a nested object | ||
target[prop] = merge(target[prop], obj[prop]); | ||
} else { | ||
// for regular property | ||
target[prop] = obj[prop]; | ||
} | ||
}); | ||
}; | ||
|
||
// iterate through all objects and | ||
// deep merge them with target | ||
args.forEach(obj => { | ||
if (obj) { | ||
merger(obj); | ||
} | ||
}); | ||
|
||
return target; | ||
}; | ||
|
||
export default merge; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters