Pages

Tuesday, 1 September 2015

Firebase Collection

Documentation
An element wrapper for the Firebase API that provides a view into the provided Firebase location as an ordered collection.
By default, Firebase yields values as unsorted document objects, where each of the children are accessible via object keys. The <firebase-collection> element allows Firebase API orderBy, limitTo and other query-oriented methods to be specified declaratively. The element then produces and maintains an Array of ordered child items of the document that is convenient for iterating over in other elements such as <template is="dom-repeat">.
Example:
  <template is="dom-bind">
    <firebase-collection
      order-by-child="height"
      limit-to-first="3"
      location="https://dinosaur-facts.firebaseio.com/dinosaurs"
      data="{{dinosaurs}}"></firebase-collection>
    <template is="dom-repeat" items="[[dinosaurs]]" as="dinosaur">
      <h4>[[dinosaur.__firebaseKey__]]</h4>
      <span>Height: </span><span>[[dinosaur.height]]</span><span>m</span>
    </template>
  </template>
As you may have noticed above, the original key of each item is available as the__firebaseKey__ property on the item.
The element makes special accomodations for documents whose children are primitive values. A primitive value is wrapped in an object with the form:
{
  value: /* original primitive value */
  __firebaseKey__: /* key of primitive value in parent document */
}
Accessor methods such as add and remove are provided to enable convenient manipulation of the collection without direct knowledge of Firebase key values.
Properties
data
Arraydefault: [] readOnly notify
    An ordered array of data items produced by the current Firebase Query instance.
    endAt
    Stringdefault:
      Specify an end record for the set of records reflected in the collection.
      equalTo
      Stringdefault:
        Specify to create a query which includes children which match the specified value. The argument type depends on which orderBy() function was used in this query. Specify a value that matches the orderBy() type.
        limitToFirst
        Numberdefault:
          Specify a maximum number of records reflected on the client limited to the first certain number of children.
          limitToLast
          Numberdefault:
            Specify a maximum number of records reflected on the client limited to the last certain number of children.
            orderByChild
            Stringdefault:
              Specify a child key to order the set of records reflected on the client.
              orderByKey
              Booleandefault: false
                Specify to order by key the set of records reflected on the client.
                orderByPriority
                Booleandefault: false
                  Specify to order by priority the set of records reflected on the client.
                  orderByValue
                  Booleandefault: false
                    Specify to order by value the set of records reflected on the client.
                    orderValueType
                    Stringdefault: string
                      Specify to override the type used when deserializing the value of start-atend-at and equal-to attributes. By default, these values are always deserialized as String, but sometimes it is preferrable to deserialize these values as e.g., Number.
                      Accepted values for this attribute, and their corresponding deserialization types, are as follows:
                      • string => String (default)
                      • number => Number
                      • boolean => Boolean
                      query
                      Object notify
                        A pointer to the current Firebase Query instance being used to populatedata.
                        startAt
                        Stringdefault:
                          Specify a start record for the set of records reflected in the collection.
                          Methods
                          add(data) ➙ Object
                          1. data Object 
                            A value to add to the document.
                          2. Returns Object
                            A Firebase Query instance referring to the added item.
                          Add an item to the document referenced at location. A key associated with the item will be created by Firebase, and can be accessed via the Firebase Query instance returned by this method.
                          getByKey(key)
                          1. key String
                            The key associated with the item in the parent document.
                          Look up an item in the local data Array by key.
                          remove(data)
                          1. data Object 
                            An identical reference to an item in this.data.
                          Remove an item from the document referenced at location. The item is assumed to be an identical reference to an item already in the dataArray.
                          removeByKey(key)
                          1. key String
                            The key associated with the item in the document located at location.
                          Remove an item from the document associated with location by key.
                          Behaviors
                          Polymer.FirebaseQueryBehavior

                          1 comment:

                          1. Nice blog, Your blog is easily understandable and give complete information about SMO/SMM course in Delhi. Thanks for your great blog.keep it up I am waiting for your next blog

                            ReplyDelete