Skip to content

Commit

Permalink
better support for object parameters (#62)
Browse files Browse the repository at this point in the history
If a SimpleModalComponent has defaults set on it, which are then partially overwritten, or added two, this alteration will allow this.

Previously the object would be completely overwritten by the incoming parameters.

Potentially worth extending further for deep copy, rather than one-level...

eg.
  config: Partial<ModalParams> = {
    enableBackgroundClicks: true,
    confirmationButton: true,
  };
can now be partially overwridden, or extended by creators
  • Loading branch information
KilleR authored and kevcjones committed Nov 4, 2019
1 parent 9f25c0e commit 91f7f4b
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/simple-modal/simple-modal.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ export abstract class SimpleModalComponent<T, T1> implements OnDestroy {
const keys = Object.keys(data);
for (let i = 0, length = keys.length; i < length; i++) {
const key = keys[i];
this[key] = data[key];
if (typeof data[key] === 'object' && typeof this[key] === 'object') {
Object.assign(this[key], data[key]);
} else {
this[key] = data[key];
}
}
}

Expand Down

0 comments on commit 91f7f4b

Please sign in to comment.