diff --git a/src/lib/core/datetime/native-date-adapter.ts b/src/lib/core/datetime/native-date-adapter.ts index 4b9b9af4624..cd0a1082e43 100644 --- a/src/lib/core/datetime/native-date-adapter.ts +++ b/src/lib/core/datetime/native-date-adapter.ts @@ -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 = 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)); diff --git a/src/lib/core/public-api.ts b/src/lib/core/public-api.ts index 9e4fdd29cf8..688cf9199f0 100644 --- a/src/lib/core/public-api.ts +++ b/src/lib/core/public-api.ts @@ -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'; diff --git a/src/lib/core/util/object-extend.spec.ts b/src/lib/core/util/object-extend.spec.ts deleted file mode 100644 index 1cb0b329b08..00000000000 --- a/src/lib/core/util/object-extend.spec.ts +++ /dev/null @@ -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'); - }); -}); diff --git a/src/lib/core/util/object-extend.ts b/src/lib/core/util/object-extend.ts deleted file mode 100644 index aeb48f9fdd8..00000000000 --- a/src/lib/core/util/object-extend.ts +++ /dev/null @@ -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; -} diff --git a/src/lib/dialog/dialog.ts b/src/lib/dialog/dialog.ts index 1dc4cbd9b48..ab9c92fe46c 100644 --- a/src/lib/dialog/dialog.ts +++ b/src/lib/dialog/dialog.ts @@ -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('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}; } diff --git a/src/lib/snack-bar/snack-bar.ts b/src/lib/snack-bar/snack-bar.ts index f321d5026c8..3ac13aa8a11 100644 --- a/src/lib/snack-bar/snack-bar.ts +++ b/src/lib/snack-bar/snack-bar.ts @@ -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}; } diff --git a/tslint.json b/tslint.json index 6361be3d338..d9d8c2440fa 100644 --- a/tslint.json +++ b/tslint.json @@ -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"],