From b8fd21581673c07f3d6db22b805f9719e0f04d04 Mon Sep 17 00:00:00 2001 From: Ben Lesh Date: Wed, 7 Mar 2018 14:48:47 -0800 Subject: [PATCH] refactor(WebSocketSubject): reduce complexity around assign no longer has a fancy impl of assign that isn't used anywhere else. Part of my plan to kill the roots --- spec/util/assign-spec.ts | 49 ------------------- .../observable/dom/WebSocketSubject.ts | 7 ++- src/internal/util/assign.ts | 20 -------- 3 files changed, 5 insertions(+), 71 deletions(-) delete mode 100644 spec/util/assign-spec.ts delete mode 100644 src/internal/util/assign.ts diff --git a/spec/util/assign-spec.ts b/spec/util/assign-spec.ts deleted file mode 100644 index 833bd9ab89..0000000000 --- a/spec/util/assign-spec.ts +++ /dev/null @@ -1,49 +0,0 @@ -import { expect } from 'chai'; -import { assign, getAssign, assignImpl } from '../../src/internal/util/assign'; - -describe('assign', () => { - it('should exist', () => { - expect(assign).to.be.a('function'); - }); - - if ((Object as any).assign) { - it('should use Object.assign if available', () => { - expect(assign).to.equal(((Object as any).assign)); - }); - } - - it('should assign n objects to a target', () => { - const target = { what: 'what' }; - const source1 = { wut: 'socks' }; - const source2 = { and : 'sandals' }; - const result = assign(target, source1, source2); - - expect(result).to.equal(target); - expect(result).to.deep.equal({ what: 'what', wut: 'socks', and: 'sandals' }); - }); -}); - -describe('assignImpl', () => { - it('should assign n objects to a target', () => { - const target = { what: 'what' }; - const source1 = { wut: 'socks' }; - const source2 = { and : 'sandals' }; - const result = assignImpl(target, source1, source2); - - expect(result).to.equal(target); - expect(result).to.deep.equal({ what: 'what', wut: 'socks', and: 'sandals' }); - }); -}); - -describe('getAssign', () => { - it('should return assignImpl if Object.assign does not exist on root', () => { - const result = getAssign({ Object: {} }); - expect(result).to.equal(assignImpl); - }); - - it('should return Object.assign if it exists', () => { - const FAKE = () => { /* lol */ }; - const result = getAssign({ Object: { assign: FAKE } }); - expect(result).to.equal(FAKE); - }); -}); diff --git a/src/internal/observable/dom/WebSocketSubject.ts b/src/internal/observable/dom/WebSocketSubject.ts index 78ae1ba6df..f540499fa1 100644 --- a/src/internal/observable/dom/WebSocketSubject.ts +++ b/src/internal/observable/dom/WebSocketSubject.ts @@ -8,7 +8,6 @@ import { ReplaySubject } from '../../ReplaySubject'; import { Observer, NextObserver } from '../../types'; import { tryCatch } from '../..//util/tryCatch'; import { errorObject } from '../..//util/errorObject'; -import { assign } from '../..//util/assign'; export interface WebSocketSubjectConfig { url: string; @@ -96,7 +95,11 @@ export class WebSocketSubject extends AnonymousSubject { this.url = urlConfigOrSource; } else { // WARNING: config object could override important members here. - assign(this, urlConfigOrSource); + for (let key in urlConfigOrSource) { + if (urlConfigOrSource.hasOwnProperty(key)) { + this[key] = urlConfigOrSource[key]; + } + } } if (!this.WebSocketCtor) { throw new Error('no WebSocket constructor can be found'); diff --git a/src/internal/util/assign.ts b/src/internal/util/assign.ts deleted file mode 100644 index fca30251cf..0000000000 --- a/src/internal/util/assign.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { root } from './root'; - -export function assignImpl(target: Object, ...sources: Object[]) { - const len = sources.length; - for (let i = 0; i < len; i++) { - const source = sources[i]; - for (let k in source) { - if (source.hasOwnProperty(k)) { - target[k] = source[k]; - } - } - } - return target; -} - -export function getAssign(root: any) { - return root.Object.assign || assignImpl; -} - -export const assign = getAssign(root); \ No newline at end of file