import Reflux from 'reflux';

import Firebase from 'firebase';
import Actions from '../actions/Actions';
import { firebaseUrl } from '../utils/constants';

let baseRef = new Firebase(firebaseUrl);
let usersRef = baseRef.child('users');

let data = {
    users: []
};

var UsersStore = Reflux.createStore({

  listenables: Actions,

  init() {
  },

  watchUsers: function() {
    usersRef
        .orderByKey()
        .limitToLast(10)
        .on('value', this.updateUsers);
  },

  updateUsers(userDataObj){
    let endAt = 10;

    // add posts to new array
    let newUsers = [];

    userDataObj.forEach(userData => {
        let user = userData.val();
        user.id = userData.key();
        newUsers.unshift(user);
    });

    // slice off extra post
    data.users = newUsers.slice(0, endAt);

    this.trigger(data);
  },

  topWatchingUsers() {
      usersRef.off();
  },

  getDefaultData() {
      return data;
  }
});

export default UsersStore;

@@ -535,20 +535,20 @@
  // add 
-post
+user
 s to new
@@ -716,16 +716,98 @@
 t(user);
+%0A%0A        // increment id for next addition%0A        this.autoIncrementId(user.id);
 %0A    %7D);
@@ -835,12 +835,12 @@
 tra 
-post
+user
 %0A   
@@ -912,16 +912,17 @@
   %7D,%0A%0A  
+s
 topWatch
@@ -968,52 +968,587 @@
 %0A%0A  
-getDefaultData() %7B%0A      return data;%0A  %7D%0A%7D)
+onRemoveUser(id)%7B%0A    data.users.map(function(user, index)%7B%0A      if(user.id === id)%0A        delete data.users%5Bindex%5D;%0A    %7D);%0A    this.trigger(data);%0A  %7D,%0A%0A  onAddUser(user)%7B%0A      user.id = this.getAutoIncrementedId();%0A      console.log(%22User name :%22, user.name, %22User Id : %22, user.id);%0A  %7D,%0A%0A  autoIncrementId(id)%7B%0A    this.id_auto_inc += (id %3E= this.id_auto_inc) ? 1 : 0;%0A    return this.id_auto_inc;%0A  %7D,%0A%0A  getAutoIncrementedId()%7B%0A      return this.id_auto_inc;%0A  %7D,%0A%0A  getDefaultData() %7B%0A      return data;%0A  %7D%0A%7D);%0A%0A// static id auto incremented%0AUsersStore.id_auto_inc = 1
 ;%0A%0Ae

Implement remove user function