fix: replace extendObject utility w/ object spread (#7372)

This commit is contained in:
Jeremy Elbourn
2017-11-20 10:19:37 -08:00
committed by GitHub
parent c725249330
commit ea54edb7ef
7 changed files with 13 additions and 100 deletions
+1 -3
View File
@@ -7,10 +7,8 @@
*/
import {Inject, Injectable, Optional} from '@angular/core';
import {extendObject} from '../util/object-extend';
import {DateAdapter, MAT_DATE_LOCALE} from './date-adapter';
// TODO(mmalerba): Remove when we no longer support safari 9.
/** Whether the browser supports the Intl API. */
const SUPPORTS_INTL_API = typeof Intl != 'undefined';
@@ -186,7 +184,7 @@ export class NativeDateAdapter extends DateAdapter<Date> {
date = new Date(Date.UTC(
date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(),
date.getMinutes(), date.getSeconds(), date.getMilliseconds()));
displayFormat = extendObject({}, displayFormat, {timeZone: 'utc'});
displayFormat = {...displayFormat, timeZone: 'utc'};
}
let dtf = new Intl.DateTimeFormat(this.locale, displayFormat);
return this._stripDirectionalityCharacters(dtf.format(date));
-2
View File
@@ -18,8 +18,6 @@ export * from './placeholder/placeholder-options';
export * from './ripple/index';
export * from './selection/index';
export * from './style/index';
export * from './util/object-extend';
// TODO: don't have this
export * from './testing/month-constants';
-50
View File
@@ -1,50 +0,0 @@
import {extendObject} from './object-extend';
describe('extendObject', () => {
it('should extend an object', () => {
let extended = extendObject({}, {x: 123});
expect(extended).toEqual({x: 123});
});
it('should overwrite existing properties', () => {
let extended = extendObject({x: 456}, {x: 123});
expect(extended).toEqual({x: 123});
});
it('should add additional properties', () => {
let extended = extendObject({x: 456}, {y: 123});
expect(extended).toEqual({x: 456, y: 123});
});
it('should extend from multiple sources', () => {
let extended = extendObject({}, {x: 123}, {y: 456});
expect(extended).toEqual({x: 123, y: 456});
});
it('should overwrite properties from the later source', () => {
let extended = extendObject({}, {x: 123}, {x: 456});
expect(extended).toEqual({x: 456});
});
it('should treat null and undefined sources as empty objects', () => {
let extended = extendObject({}, null, {x: 123}, undefined, {y: 456});
expect(extended).toEqual({x: 123, y: 456});
});
it('should throw an error when the dest object is null', () => {
expect(() => extendObject(null, {x: 123}))
.toThrowError('Cannot convert undefined or null to object');
});
it('should throw an error when the dest object is undefined', () => {
expect(() => extendObject(undefined, {x: 123}))
.toThrowError('Cannot convert undefined or null to object');
});
});
-32
View File
@@ -1,32 +0,0 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
/**
* Extends an object with the *enumerable* and *own* properties of one or more source objects,
* similar to Object.assign.
*
* @param dest The object which will have properties copied to it.
* @param sources The source objects from which properties will be copied.
*/
export function extendObject(dest: any, ...sources: any[]): any {
if (dest == null) {
throw TypeError('Cannot convert undefined or null to object');
}
for (let source of sources) {
if (source != null) {
for (let key in source) {
if (source.hasOwnProperty(key)) {
dest[key] = source[key];
}
}
}
}
return dest;
}
+6 -7
View File
@@ -6,17 +6,16 @@
* found in the LICENSE file at https://angular.io/license
*/
import {Directionality} from '@angular/cdk/bidi';
import {ESCAPE} from '@angular/cdk/keycodes';
import {
BlockScrollStrategy,
Overlay,
OverlayRef,
OverlayConfig,
OverlayRef,
ScrollStrategy,
} from '@angular/cdk/overlay';
import {ComponentPortal, ComponentType, PortalInjector, TemplatePortal} from '@angular/cdk/portal';
import {filter} from 'rxjs/operators/filter';
import {startWith} from 'rxjs/operators/startWith';
import {Location} from '@angular/common';
import {
ComponentRef,
@@ -28,15 +27,15 @@ import {
SkipSelf,
TemplateRef,
} from '@angular/core';
import {extendObject} from '@angular/material/core';
import {Directionality} from '@angular/cdk/bidi';
import {Observable} from 'rxjs/Observable';
import {defer} from 'rxjs/observable/defer';
import {of as observableOf} from 'rxjs/observable/of';
import {filter} from 'rxjs/operators/filter';
import {startWith} from 'rxjs/operators/startWith';
import {Subject} from 'rxjs/Subject';
import {MatDialogConfig} from './dialog-config';
import {MatDialogContainer} from './dialog-container';
import {MatDialogRef} from './dialog-ref';
import {of as observableOf} from 'rxjs/observable/of';
export const MAT_DIALOG_DATA = new InjectionToken<any>('MatDialogData');
@@ -313,5 +312,5 @@ export class MatDialog {
* @returns The new configuration object.
*/
function _applyConfigDefaults(config?: MatDialogConfig): MatDialogConfig {
return extendObject(new MatDialogConfig(), config);
return {...new MatDialogConfig(), ...config};
}
+4 -5
View File
@@ -7,17 +7,16 @@
*/
import {LiveAnnouncer} from '@angular/cdk/a11y';
import {BreakpointObserver, Breakpoints} from '@angular/cdk/layout';
import {Overlay, OverlayConfig, OverlayRef} from '@angular/cdk/overlay';
import {ComponentPortal, ComponentType, PortalInjector} from '@angular/cdk/portal';
import {ComponentRef, Injectable, Injector, Optional, SkipSelf} from '@angular/core';
import {extendObject} from '@angular/material/core';
import {first} from 'rxjs/operators/first';
import {takeUntil} from 'rxjs/operators/takeUntil';
import {SimpleSnackBar} from './simple-snack-bar';
import {MAT_SNACK_BAR_DATA, MatSnackBarConfig} from './snack-bar-config';
import {MatSnackBarContainer} from './snack-bar-container';
import {MatSnackBarRef} from './snack-bar-ref';
import {BreakpointObserver, Breakpoints} from '@angular/cdk/layout';
import {takeUntil} from 'rxjs/operators/takeUntil';
import {first} from 'rxjs/operators/first';
/**
@@ -224,5 +223,5 @@ export class MatSnackBar {
* @returns The new configuration object with defaults applied.
*/
function _applyConfigDefaults(config?: MatSnackBarConfig): MatSnackBarConfig {
return extendObject(new MatSnackBarConfig(), config);
return {...new MatSnackBarConfig(), ...config};
}
+2 -1
View File
@@ -75,7 +75,8 @@
["fit"],
["fdescribe"],
["xit"],
["xdescribe"]
["xdescribe"],
{"name": "Object.assign", "message": "Use the spread operator instead."}
],
// Disallows importing the whole RxJS library. Submodules can be still imported.
"import-blacklist": [true, "rxjs", "rxjs/operators"],