Skip to content

Feature request: ability to provide all query observable (not only its properties) #770

Closed
@tomasklima

Description

@tomasklima

In the current version of Angularfire2 we can provide a query with observable parameters. Database is requested every time one of these parameters have a new value. I think to provide all query object as observable would be a better approach.

In closed issue #603 I mentioned one of typical use cases: loading calendar events for given period (between two dates). Currently I have to code it as follows:

export class EventsCalendarComponent {
  private start$: Subject<string> = new Subject<string>();
  private end$: Subject<string> = new Subject<string>();

  constructor(private db: AngularFireDatabase) {
    db.list('/events', {
      query: {
        orderByChild: 'date',
        startAt: this.start$,
        endAt: this.end$
      }
    }).subscribe(events => {
      // update calendar component with events
    });
  }

  filterByPeriod(start: Moment, end: Moment) {
    this.start$.next(start.getTime());
    this.end$.next(end.getTime());
  }
}

Calling the method filterByPeriod causes two immediately consecutive requests are fired and the first of them is irrelevant and useless. For such case the ability to have all the query object observable would solve the problem and we code something this:

export class EventsCalendarComponent {
  private query$: Subject<Object> = new Subject<Object>();

  constructor(private db: AngularFireDatabase) {
    db.list('/events', {
      query: this.query$;
    }).subscribe(events => {
      // update fullcalendar component with events
    });
  }

  filterByPeriod(start: Moment, end: Moment) {
    this.query$.next({
      orderByChild: 'date',
      startAt: start.getTime(),
      endAt: end.getTime()
    });
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions