Skip to main content

Posts

Showing posts with the label change

Promise -fication of JS calls.

Found a new pattern to use recently that is called Promise. I really like the way ES6/7 brings new thinking patterns into life nowdays. Here is Promise used instead of old pattern. It was to give JS method a callback function. This splitting code and making a lot of possibilities for error to come out in this place. One would write old times according to MDN : function greeting ( name ) { alert ( 'Hello ' + name ); } function processUserInput ( callback ) { var name = prompt ( 'Please enter your name.' ); callback ( name ); } processUserInput ( greeting ); And now it is made with Promise pattern like so: let promise = new Promise (( resolve , reject ) => { resolve ( prompt ( 'Please enter your name.' )); }); promise . then (( name ) => { alert ( 'Hello ' + name ); }); In general and briefly this now helps to avoid 'callback hell' with functions passed as arguments and write as...

CouchDB restoring deleted/updated documents and their data

We are using CouchDB for production and happy with it. It is much more lightweight rather then MongoDB yet powerful. (For our needs at least). But sometimes you have situations that some code deleted/spoiled your Couch Database data. We had some bugs leading to deleting indexes. However compaction have not been run and here is the decision. There are several ways for different situations. I'll try to cover them all. So for deleted CouchDB documents you need to: 1. Make sure your document with this id is Deleted. To do it you need to request CouchDB for this document. E.g. with this string: $db/$id Where  $db  is your CouchDB database name and  $id  is your deleted document id it should return something like this: { "error" : "not_found" , "reason" : "deleted" } 2. Get all the revisions of the deleted document. With this request: $db/$id?revs= true &open_revs=all Where $db is your CouchDB database name and $id is ...