Skip to content

Commit 2feb4a7

Browse files
committed
Add changeset to the PR
1 parent 71561e4 commit 2feb4a7

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

.changeset/tough-rings-bake.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'firebase': minor
3+
'@firebase/messaging': minor
4+
---
5+
6+
Added support for `onMessage` so the internal callback can work with [Subscriber](https://rxjs.dev/api/index/class/Subscriber)

packages/messaging/src/controllers/window-controller.ts

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -190,20 +190,13 @@ export class WindowController implements FirebaseMessaging, FirebaseService {
190190

191191
const { type, payload } = (event.data as InternalMessage).firebaseMessaging;
192192

193-
if (
194-
this.onMessageCallback &&
195-
typeof this.onMessageCallback === 'function' &&
196-
type === MessageType.PUSH_RECEIVED
197-
) {
198-
this.onMessageCallback(payload);
199-
}
200-
201-
if (
202-
this.onMessageCallback &&
203-
typeof this.onMessageCallback !== 'function' &&
204-
type === MessageType.PUSH_RECEIVED
205-
) {
206-
this.onMessageCallback.next(payload);
193+
// onMessageCallback is either a function or observer/subscriber.
194+
if (this.onMessageCallback && type === MessageType.PUSH_RECEIVED) {
195+
if (typeof this.onMessageCallback === 'function') {
196+
this.onMessageCallback(payload);
197+
} else {
198+
this.onMessageCallback.next(payload);
199+
}
207200
}
208201

209202
const { data } = payload;

0 commit comments

Comments
 (0)