Skip to content

Multiple subscriptions on a FirebaseListObservable #574

@maxmumford

Description

@maxmumford

Hi all,

When querying fb with a FirebaseListObservable like so:

let items = this.angularFire.database.list('/items', query{...}).subscribe(x => console.log(x));

the output will be something like:

[Object, Object, Object, Object]

However when attaching two subscribers, each subscriber is triggered each time an item is added to the results array. for example:

let items = this.angularFire.database.list('/items', query{...});
items.subscribe(x => console.log('Subscriber 1: ', x));
items.subscribe(y => console.log('Subscriber 2: ', y));

// output:
Subscriber 1: []
Subscriber 1: [Object]
Subscriber 1: [Object, Object]
Subscriber 1: [Object, Object, Object]
Subscriber 1: [Object, Object, Object, Object]
Subscriber 2: []
Subscriber 2: [Object]
Subscriber 2: [Object, Object]
Subscriber 2: [Object, Object, Object]
Subscriber 2: [Object, Object, Object, Object]

I would expect both subscribers to be called just once with the final array result. Is this an error in my implementation, or by design?

My goal here is to search a list and do something if no items are returned from the search, ie:

let items = this.angularFire.database.list('/items', query{...});
items.subscribe(x => console.log('Subscriber 1: ', x));
items.subscribe(x => {
    if(x.length == 0)
        // do something
});

I would create a plunker for this but it seems the af2 version used by plunker has a problem with facebook auth (but let's leave that for another issue ;) ):

http://plnkr.co/edit/4IbB5IvfkBYcj2iVAIM1?p=preview

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions