Wondering what’s next for npm?Check out our public roadmap! »

    ampfire-collection

    0.2.0 • Public • Published

    AmpFire-Collection

    A modified, CommonJS version of Firebase's BackboneFire for AmpersandJS Collections.

    Installation

    npm install ampfire-collection
    

    If you want it automatically added to your project's package.json use:

    npm install ampfire-collection --save
    

    Info

    Basic Usage

    First you should require the module as well as the ampersand-model module for creating our collection's model instances.

    var AmpfireCollection = require('ampfire-collection');
    var Model = require('ampersand-model');

    Then you can create an ampersand-model to pass to your collection

    var ExampleModel = Model.extend({
        props: {
          date: 'string',
          name: 'string',
          url: 'string',
          viewed: 'boolean',
          id: 'string'
        }
      });

    Next simply extend the AmpfireCollection passing it our newly created ExampleModel and the firebase url

      var RealtimeCollection = AmpfireCollection.extend({
        url: 'https://example-db.firebaseio.com/todos',
        model: ExampleModel,
        autoSync: true // true by default
      });
     
      // Instantiate the collection
      var realtimeCollection = new RealtimeCollection();
     
      realtimeCollection.on('sync', function(collection) {
        console.log('collection loaded', collection);
      });

    The rest of the API is the same as that of BackboneFire

    Dependencies

    • ampersand-rest-collection module
    • lodash functions
      • extend: lodash.object
      • keys: lodash.object
      • has: lodash.object
      • isObject: lodash.lang
      • isFunction: lodash.lang
      • isArray: lodash.lang
      • clone: lodash.lang
      • bind: lodash.function
      • defer: lodash.function
      • each: lodash.collection
      • find: lodash.collection,
      • difference: lodash.array
      • union: lodash.array

    Tests

    Coming soon...

    Demo

    Coming soon...

    Credits

    This is all just a modification of the amazing work the Firebase team did on BackboneFire. It uses the awesome AmpersandJS Framework from the guys over at &yet.

    Licence

    MIT

    Install

    npm i ampfire-collection

    DownloadsWeekly Downloads

    1

    Version

    0.2.0

    License

    MIT

    Last publish

    Collaborators

    • avatar