Read array Objects from Firebase + Firepad + Ace Editor

477 views Asked by At

I am storing the data to the Firebase when the user starts typing in the ACE editor with the help of firepad.

The data is stored in the Firebase like an Array. Each character in array index.

I just typed "Hi Its" then "Hi Its Nithi" then inserted "Hi Its Me Nithi"

It's really hard to read the data with key, value, array, index with -ve value.

Is there any plugin to convert handle the index?

Data:

B11
o
    0: 7 
    1: -1
B12
o
    0: 7
    1: "N"
B13
o
    0: 8
    1: "ithi" 
B14
o
    0: 7
    1: "M"
    2: 5
B15
o
    0: 8 
    1: "e"
    2: 5

Am really tired by constructing a code like :

Which grow and getting more complex.

codeTimeFirebaseRef.on('value', function(snapshot) {
        var data = snapshot.val();
        var i = 1;
        var jsonData = {};
        var jsonDataArray = {};
        async.forEach(Object.keys(data), function(key) {
          var code = data[key];
          if (code.o.length === 1) {
            if (jsonDataArray.length > 1) {
              jsonData.answer = jsonDataArray;
              codes.push(jsonData);
              i++;
              jsonData = {};
              jsonDataArray = {};
            } else {
              jsonData.index = i;
              jsonData.time = code.t;
              if (typeof code.o[0] === 'string') {
                jsonDataArray = code.o[0];
              } else if (typeof code.o[0] === 'number') {
                jsonDataArray = jsonDataArray.substring(0, code.o[0]);
              }
            }
          } else {
            if (typeof code.o[1] === 'string') {
              jsonDataArray += '' + code.o[1];
            } else if (typeof code.o[1] === 'number') {
              jsonDataArray = jsonDataArray.substring(code.o[0], code.o[1]);
            }
          }

Please help to get through.

0

There are 0 answers