return content

So the documentation says and it’s working fine, the console prints out the content. But, it seems that i can’t get the content out of this function.

Just a basic example:

var test = Observable({'foo': 'bar'});               //start with one element
storage.write('foobar', 'something');                //write something into file'foobar').then(function(content) {      //read out something
    test.add({'foo2': content});                     //add something as second element
console.log(test.length);                            //count elements

I expected this to return 2 cause i start with one element, then add another one and should end up with 2, but it always prints out 1. That can only mean, that test is not available or can’t be modified inside the function for some reason.

Is there any chance to read a file and work with the content outside of the function?

Since these methods is async, they are not done with write/read before you print out the length. You can either do it sync or async like this:

var test = Observable({'foo': 'bar'});

// Blocking
storage.writeSync('foobar', 'something');
var content = storage.readSync('foobar');
test.add({'foo2': content});

// Async
storage.write('foobar', 'something').then(function() {'foobar').then(function(content) {
    test.add({'foo3': content});

Thanks man! That really helps a lot. Very appreciated.