Skip to content

Commit

Permalink
fix(helper): rxjs6 fromEventPattern inconsistency
Browse files Browse the repository at this point in the history
  • Loading branch information
crimx committed Apr 27, 2018
1 parent 8a20f74 commit 7c1594d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions src/_helpers/browser-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ function storageCreateStream (this: StorageThisThree, key: string) {
handler => this.addListener(key, handler as StorageListenerCb),
handler => this.removeListener(key, handler as StorageListenerCb),
).pipe(
map(change => change[key])
map(args => Array.isArray(args) ? args[0][key] : args[key])
)
}

Expand Down Expand Up @@ -350,17 +350,17 @@ function messageRemoveListener (this: MessageThis, ...args): void {

function messageCreateStream<T = any> (messageType?: Message['type']): Observable<T>
function messageCreateStream (this: MessageThis, messageType = MsgType.Null) {
if (messageType !== MsgType.Null) {
return fromEventPattern(
const pattern$ = messageType !== MsgType.Null
? fromEventPattern(
handler => this.addListener(messageType, handler as onMessageEvent),
handler => this.removeListener(messageType, handler as onMessageEvent),
)
} else {
return fromEventPattern(
: fromEventPattern(
handler => this.addListener(handler as onMessageEvent),
handler => this.removeListener(handler as onMessageEvent),
)
}

return pattern$.pipe(map(args => Array.isArray(args) ? args[0] : args))
}

/**
Expand Down
2 changes: 1 addition & 1 deletion test/specs/_helpers/browser-api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ describe('Browser API Wapper', () => {
expect(nextStub).toHaveBeenCalledTimes(1)
expect(errorStub).toHaveBeenCalledTimes(0)
expect(completeStub).toHaveBeenCalledTimes(1)
expect(nextStub).toBeCalledWith({ type: 1, __pageId__: window.pageId })
expect(nextStub.mock.calls[0][0]).toEqual({ type: 1, __pageId__: window.pageId })
})
})
})
Expand Down

0 comments on commit 7c1594d

Please sign in to comment.