-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
43 lines (33 loc) · 975 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Generated by CoffeeScript 2.3.2
// ![PlayFrame](https://avatars3.githubusercontent.com/u/47147479)
// # Evolve
// ###### 0.16 kB Deep calling assign
// ## Installation
// ```sh
// npm install --save @playframe/evolve
// ```
// ## Usage
// ```js
// import evolve from '@playframe/evolve'
// const props = {onclick: (event)=> fetch()}
// const clickLogger = { onclick: (handler)=>(e)=>
// console.log(e)
// handler && handler(e);
// }
// const loggedClicksProps = evolve(props, clickLogger);
// ```
// ## Annotated Source
// Caching `Array.isArray` for perf
var evolve, isArray;
({isArray} = Array);
// Exporting a deep assign that passes old values to functions
module.exports = evolve = (base, upgrade) => {
var evolved, k, type, v;
evolved = {...base};
for (k in upgrade) {
v = upgrade[k];
type = typeof v;
evolved[k] = type === 'function' ? v(base[k]) : type === 'object' && !isArray(v) ? evolve(base[k], v) : v;
}
return evolved;
};