Book Image

Offline First Web Development

By : Daniel Sauble
Book Image

Offline First Web Development

By: Daniel Sauble

Overview of this book

When building mobile apps, it’s easy to forget about the moments when your users lack a good Internet connection. Put your phone in airplane mode, open a few popular apps, and you’ll quickly see how they handle being offline. From Twitter to Pinterest to Apple Maps, some apps might handle being offline better—but very few do it well. A poor offline experience will result in frustrated users who will abandon your app, or worse, turn to your competitor’s apps Expert or novice, this book will teach you everything you need to know about designing and building a rigorous offline app experience. By putting the offline experience first, you’ll have a solid foundation to build upon, avoiding the unnecessary stress and frustration of trying to retrofit offline capabilities into your finished app. This basic principle, designing for the worst-case scenario, could save you countless hours of wasted effort.
Table of Contents (17 chapters)
Offline First Web Development
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Implementing the conflict resolution


At this point, PouchDB returns conflicts when they exist and assigns them to the Item model for use by our controllers and views. The next step is to expose this information to the users and let them resolve conflicts when they arise.

Adding the supporting methods

The last thing that we need to add to the Item store is a couple of supporting methods. As PouchDB returns a list of conflict revisions but not the data attached to each revision, we need to fetch this explicitly. People need to see what data is attached to each revision in order to select the right one.

Edit the Item store and add the following method:

getAllConflicts: function(me, store, id, revs, docs, callback) {
  if (!revs.length) {
    callback(docs);
    return;
  }
  store.get(id, { rev: revs.shift() }, function(error, doc) {
    docs.push(doc);
    me.getAllConflicts(me, store, id, revs, docs, callback);
  });
},

Normally, we would use allDocs to return a list of documents, but it only...