(target: T, source: Partial<T>)
| 15 | } |
| 16 | |
| 17 | export function assignImm<T>(target: T, source: Partial<T>): T { |
| 18 | let keys = Object.keys(source); |
| 19 | let changed = false; |
| 20 | target = target ?? {} as any; |
| 21 | for (let k of keys) { |
| 22 | let src = (source as any)[k]; |
| 23 | let dst = (target as any)[k]; |
| 24 | if ((src === dst) || |
| 25 | (src instanceof Date && dst instanceof Date && +src === +dst) || |
| 26 | (src instanceof Vec3 && dst instanceof Vec3 && src.distSq(dst) === 0.0) |
| 27 | ) { |
| 28 | continue; |
| 29 | } |
| 30 | changed = true; |
| 31 | } |
| 32 | return changed ? Object.assign({}, target, source) : target; |
| 33 | } |
| 34 | |
| 35 | export function assignImmFull<T>(target: T | null, source: T | null): T | null { |
| 36 | return source && target ? assignImm(target, source) : source; |
no test coverage detected