Skip to content

Instantly share code, notes, and snippets.

@dimovdaniel
Created January 23, 2018 00:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dimovdaniel/0ba453a691e784a01c021495712bc679 to your computer and use it in GitHub Desktop.
Save dimovdaniel/0ba453a691e784a01c021495712bc679 to your computer and use it in GitHub Desktop.
sleep(miliseconds) {
var currentTime = new Date().getTime();
while (currentTime + miliseconds >= new Date().getTime()) {
}
}
/**
* Step 3
* Connect to firebase to get the current item we need
*/
getDataFromFirebase(firebasePath){
this.sleep(1000)
var ref=firebase.app.database().ref(firebasePath);
var _this=this;
// Callback pattern
ref.on('value', function(snapshotRoot) {
var isJustArray=Common.getClass(snapshotRoot.val())=="Array";
if(isJustArray){
//Since Nov 2017, quering an array directly always returns 10 rows.
//Anyway, wnen we do query an array direclty, we need to get all the items, so we know the array real length
//So, we will go the old fashion way, quering firebase directly
console.log("Fix for limited paging on arrays")
ref.once('value').then(function(snapshot) {
console.log("Received compleete array with length of "+snapshot.val().length);
_this.processRecords(snapshot.val())
});
}else{
_this.processRecords(snapshotRoot.val())
}
});
}
@dimovdaniel
Copy link
Author

Replace the getDataFromFirebase function in "src/Containers/Fireadmin.js" around line 200.
Important: don't forget to add sleep function.

@themakerman
Copy link

my code looks different than yours. i am using the new version. please help me out.

getDataFromFirebase(firebasePath){
     //The paging options
     var options = Config.adminConfig.paging||{
      pageSize: 20,
      finite: true,
      retainLastPage: false
    };
    var ref=firebase.app.database().ref(firebasePath);
    var paginator = new FirebasePaginator(ref,options);
    var _this=this;

    // Callback pattern
    paginator.on('value', function() {
      console.log(paginator.collection.length);
      var isJustArray=Common.getClass(paginator.collection)=="Array";
      if(isJustArray){

        //Since Nov 2017, quering an array directly always returns 10 rows.
        //Anyway, wnen we do query an array direclty, we need to get all the items, so we know the array real length
        //So, we will go the old fashion way, quering firebase directly
        console.log("Fix for limited paging on arrays")
        ref.once('value').then(function(snapshot) {
          console.log("Received compleete array with length of "+snapshot.val().length);
          _this.processRecords(snapshot.val())
        });

      }else{
        _this.processRecords(paginator.collection)
      }

    });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment