Hacker News new | past | comments | ask | show | jobs | submit login

I'm personally really a fan of this syntax mostly because I like how it reads when you chain them together.

    db.replicate
      .from('http://example.com/mydb1')
      .to('http://example.com/mydb2')
      .on('complete', function() {
          
      })
      .on('error', function() {
         
      })
      .then(function() {
        
      });



What happens when you do:

  db.replicate
      .from('http://example.com/mydb1')
or

  db.replicate
      .from('http://example.com/mydb1')
      .from('http://example.com/mydb2')
      .to('http://example.com/mydb3')
or

  db.replicate
      .from('http://example.com/mydb1')
      .to('http://example.com/mydb2')
      .to('http://example.com/mydb3')
? serious question


1: replicates from mydb1 into the pouchdb object represented by 'db'

2 & 3: I'm pretty sure chaining replications doesn't work in that way, although thats a pretty interesting thought.

If you have to chain replications and achieve the structure in 2, you'd have to define the pouch objects as:

db = new PouchDB('localDB');

mydb1 = new PouchDB('http://example.com/mydb1');

etc ..

and then do:

mydb2.replicate.to('mydb3',{live:true});

mydb2.replicate.to('mydb1',{live:true});

mydb1.replicate.to('db',{live:true});

the 'live' flag, as you'd imagine, makes the replication live/continuous, as opposed to one-time.


It's not clear which 'arguments' are required when it's done this way. What's stopping you from calling 'from' without 'to'?


I think it would just not do anything. I like this type of syntax but only when the required parameters are done up front. Then all chainable are optional / modifiers / events. This is how jQuery works and how I modeled msngr.js.

Unless Pouch has anything required missing I think it's fine though maybe a little unintuitive (like can you do multiple froms? Multiple tos? Etc)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: