Options
All
  • Public
  • Public/Protected
  • All
Menu

Class FirebaseArray<T>

Defines a class that provides capabilities to synchronize ordered lists for a Firebase Object.

Example:

import {FirebaseService} from 'ng2-firebase/core';

// Get the Array
var arr = new FirebaseService(
   new Firebase('https://YOUR-FIREBASE-URL.firebaseio-demo.com')
).asArray();

// Use Array

Angular 2 Example:

// some.component.ts
import { Component, OnInit, provide } from 'angular2/core';
import { FirebaseArray, FirebaseService, FirebaseServiceFactory } from 'ng2-firebase/core';
import { Observable } from 'rxjs/Rx';

@@Component({
   // FirebaseServiceFactory is not Implemented yet...
   selector: 'some-component',

   // Make sure to include the async pipe so that the most recent value
   // is resolved from the data observable.
   template:
     'I have {{users.length}} users!' +
     '<div *ngFor="#user of (users.observable | async)">' +
     '   {{user.name}}' +
     '</div>' +
     '<h2>Users over 18:</h2>' +
     '<div *ngFor="#user of (over18 | async)>' +
     ' {{user.name}}' +
     '</div>' +,

   // Declare the providers that should be used for the service.
   providers: [
     provide(
         FirebaseArray,
         {
             useValue: new FirebaseService(
                 new Firebase('https://YOUR-FIREBASE-URL.firebaseio-demo.com')
             ).asArray()
         }
     )
   ]
})
export class SomeComponent implements OnInit {
  private users: FirebaseArray;
  private over18: Observable<User>;

  constructor(users: FirebaseArray) {
     this.users = users;
  }

  findOver18(): Observable<User> {
     this.over18 = this.users.filter(u => u.age > 18);
  }

  ngOnInit() {
     findOver18();
  }
}

Type parameters

  • T

Hierarchy

  • FirebaseArray

Index

Constructors

constructor

Properties

Private _arr

_arr: any[]

Private _initialized

_initialized: boolean = false
type

{boolean}

Private _list

_list: ArrayValue[]

Private _service

_service: FirebaseService<T[]>

Private _subject

_subject: Subject<ArrayValue[]>

copyArray

copyArray: boolean = true

Whether inner array should be copied when notifying observers. Defaults to true.

type

{boolean}

Accessors

array

  • get array(): T[]

length

  • get length(): Observable<number>
  • Gets an observable for the length of the array.

    Returns Observable<number>

observable

  • get observable(): Observable<T[]>
  • Gets an observable that notifies whenever the underlying array is updated.

    Returns Observable<T[]>

service

Methods

Private _applyChildAdded

  • _applyChildAdded(pos: number, value: ArrayValue): void

Private _applyChildChanged

  • _applyChildChanged(pos: number, newValue: any, newKey: string): void
  • Applies the child_moved event handler logic to the given array.

    Parameters

    • pos: number
    • newValue: any
    • newKey: string

    Returns void

Private _applyChildMoved

  • _applyChildMoved(pos: number, newPos: number): void
  • Applies the child_moved event handler logic to the given array.

    Parameters

    • pos: number
    • newPos: number

    Returns void

Private _applyChildRemoved

  • _applyChildRemoved(pos: number): void
  • Applies the child_removed event handler logic to the arrays.

    Parameters

    • pos: number

    Returns void

Private _childAdded

  • _childAdded(val: any, key: string, snap: FirebaseDataSnapshot, prevChild: any): void
  • Parameters

    • val: any
    • key: string
    • snap: FirebaseDataSnapshot
    • prevChild: any

    Returns void

Private _childChanged

  • _childChanged(val: any, key: string): void

Private _childMoved

  • _childMoved(val: any, key: string, snap: FirebaseDataSnapshot, prevChildKey: any): void
  • Parameters

    • val: any
    • key: string
    • snap: FirebaseDataSnapshot
    • prevChildKey: any

    Returns void

Private _childRemoved

  • _childRemoved(val: any, key: string): void

Private _emit

  • _emit(): void

Private _init

  • _init(): void

Private _subscribeToEvent

  • _subscribeToEvent(observable: Observable<any[]>, reciever: Function): void
  • Parameters

    • observable: Observable<any[]>
    • reciever: Function

    Returns void

Private _wrap

  • _wrap(func: Function): (Anonymous function)

add

  • add(data: T): Promise<boolean>
  • Adds the given data to the end of this array. Returns a promise that represents the async operation.

    Parameters

    • data: T

      The data that should be added to the data structure.

    Returns Promise<boolean>

filter

  • filter(callback: function, thisArg?: any): Observable<any[]>
  • Filters each of the elements in the observed arrays based on whether they match the provided comparison function.

    Parameters

    • callback: function
        • (val: T, index: number, arr: T[]): boolean
        • Parameters

          • val: T
          • index: number
          • arr: T[]

          Returns boolean

    • Optional thisArg: any

    Returns Observable<any[]>

find

  • find(callback: function, thisArg?: any): Observable<any>
  • Returns an observable that resolves whenever a new value is found in the underlying array. If the value was removed, or was originally not present in the array, undefined is returned.

    Parameters

    • callback: function

      The function that is used to determine if a value is "found".

        • (val: T, index: number, arr: T[]): boolean
        • Parameters

          • val: T
          • index: number
          • arr: T[]

          Returns boolean

    • Optional thisArg: any

      The object that the callback should be called on.

    Returns Observable<any>

findIndex

  • findIndex(callback: function, thisArg?: any): Observable<number>
  • Returns an observable that resolves with the index of the item whenever a new value is found in the underlying array. If the value was removed, or was originally not present in the array, -1 is returned.

    Parameters

    • callback: function

      The function that is used to determine if a value is "found".

        • (val: T, index: number, arr: T[]): boolean
        • Parameters

          • val: T
          • index: number
          • arr: T[]

          Returns boolean

    • Optional thisArg: any

      The object that the callback should be called on.

    Returns Observable<number>

indexOf

  • indexOf(val: T): Observable<number>
  • Gets an observable that resolves whenever the index of the given value is found.

    Parameters

    • val: T

    Returns Observable<number>

indexOfKey

  • indexOfKey(key: string | number): Observable<number>
  • Gets an observable that resolves with the index of the given key is found.

    Parameters

    • key: string | number

    Returns Observable<number>

map

  • map<U>(callback: function, thisArg?: any): Observable<U[]>
  • Maps each observed array to a new array that is made up of the results of calling the given callback function.

    Type parameters

    • U

    Parameters

    • callback: function
        • (val: T, index: number, arr: T[]): U
        • Parameters

          • val: T
          • index: number
          • arr: T[]

          Returns U

    • Optional thisArg: any

    Returns Observable<U[]>

remove

  • remove(index: string | number): Promise<boolean>
  • Removes the child at the given index(a.k.a. key) from this array.

    Parameters

    • index: string | number

      The key of the child that should be removed from the data structure.

    Returns Promise<boolean>

set

  • set(index: string | number, data: T): Promise<boolean>
  • Sets the data stored at the given index (a.k.a. key).

    Parameters

    • index: string | number

      The key of the child whose data should be replaced.

    • data: T

      The data that the child should be replaced with.

    Returns Promise<boolean>

subscribe

  • subscribe(onNext?: function, onError?: function, onComplete?: function): Subscription
  • Registers handlers for notification when this array is updated.

    Parameters

    • Optional onNext: function
        • (value: T[]): void
        • Parameters

          • value: T[]

          Returns void

    • Optional onError: function
        • (error: any): void
        • Parameters

          • error: any

          Returns void

    • Optional onComplete: function
        • (): void
        • Returns void

    Returns Subscription

Static Private _getPositionAfter

  • _getPositionAfter(prevChildKey: string, list: ArrayValue[]): number

Static Private _getPositionFor

  • _getPositionFor(key: string, list: ArrayValue[]): number

Static Private _mapArrayValues

Static Private _moveValue

  • _moveValue(arr: any[], pos: number, newPos: number): void
  • Moves the value in the given array at the given position to the given new position.

    Parameters

    • arr: any[]
    • pos: number
    • newPos: number

    Returns void

Generated using TypeDoc