SlideShare ist ein Scribd-Unternehmen logo
1 von 21
Downloaden Sie, um offline zu lesen
Mobile & Offline Data Synchronization
in AngularJS
http://bit.ly/zen-ng-pouchdb
Daniel Zen
@zendigital
My Background
● Longtime JavaScript programmer
● Former XP Consultant for Google & Pivotal
● Started using AngularJS 2 years ago
● Started AngularJS-NYC Meetup May 2012
● Reformed Zen Digital consultancy 2013
○ Web & mobile application development
○ Focus on using latest technologies & solutions
Outline for this talk:
● Requirements for AngularJS data models
● Standard Online Techniques
○ CRUD,RESTful APIs
○ $http, $resource
● Offline issues
● local storage options
● Sample Application walk through
○ Ionic
○ PouchDb
Requirements for data models in
AngularJS:
Requirements for models in AngularJS:
ABSOLUTELY NOTHING
● AngularJS is model agnostic
● Any variable or object can serve as a model
● No unique ID required
● No built-in persistence model for objects
● ng-model binds javascript variables to UI not
to backend
What does this mean for data persistence
● There is no standard, yet
○ See AngularJS 2.0 Data Persistence Design Doc
● Various open source storage options
○ SQL
■ MySQL
■ PostgreSQL
○ NoSQL
■ MongoDB
■ CouchDB
Common Persistence Practices
● CRUD - Create, read, update and delete
Each letter in the acronym can map to a standard
SQL statement and HTTP method:
Operation` SQL HTTP
Create INSERT PUT / POST
Read (Retrieve) SELECT GET
Update (Modify) UPDATE PUT / PATCH
Delete (Destroy) DELETE DELETE
Typically we employ RESTful APIs
● RESTful APIs - Representational state transfer
The name “Representational State Transfer” is intended to
evoke an image of how a well-designed Web application
behaves: a network of Web pages forms a virtual state machine,
allowing a user to progress through the application by selecting
a link or submitting a short data-entry form, with each action
resulting in a transition to the next state of the application by
transferring a representation of that state to the user. - Roy
Fielding
● HTTP 1.1 based on REST
Common REST Practices
Resource POST
create
GET
read
PUT
update
DELETE
delete
/accounts Create a new
account
List accounts Bulk update
accounts
Delete all
accounts
/accounts/123 Error Show account
123
If exists update
account 123
If not error
Delete account
123
/customers Create a new
customer
List customers Bulk update
customers
Delete all
customers
/customers/456 Error Show customer
456
If exists update
customer 456
If not error
Delete
customer 456
$http Service
● The AngularJS XmlHttpRequest API follows the
Promise interface ($q service)
○ Returns a promise object with the standard then method
and two http specific methods: success and error.
$http({method: 'GET', url: '/someUrl'}).
success(function(data, status, headers, config) {
// this callback will be called asynchronously
// when the response is available
}).
error(function(data, status, headers, config) {
// called asynchronously if an error occurs
// or server returns response with an error
status.
});
$resource - a higher level abstraction
● service in module ngResource
● factory lets you interact with server-side data
● returns resource with methods for CRUD
operations: get, save, query, remove, delete
● operations can be invoked by the following:
● no need to interact with the low level $http
● HTTP GET "class" actions: Resource.action([parameters], [success], [error])
● non-GET "class" actions: Resource.action([parameters], postData, [success], [error])
● non-GET instance actions: instance.$action([parameters], [success], [error])
$resource - a higher level abstraction
● You can also access the raw $http promise via
the $promise property on the object returned
● More reference: Angular communication $http & $resource
var User = $resource('/users/:userId',
{userId:'@id'});
User.get({userId:123})
.$promise.then(function(user) {
$scope.user = user;
})
But what about offline?
● Web apps no longer dependent on servers
● Solution: richer clients (using AngularJS ;)
● Google Docs is a good example
● For offline first experience:
○ You need to store the data in the front end
○ You need it to sync to the server’s data store.
● In browser databases available:
○ derby.js, Lawnchair, Sench touch
● requirement: online synchronization
What have we come to expect
● Email should work offline
○ Local copy of recent emails
○ Can read or delete
○ Can write new emails, and will send when online
● Google Docs keeps pushing threshold
○ In Chrome we can view and edit while offline
○ mobile version now has offline edit capability
● Conflict resolution
○ Intelligently merge documents with multiple edits
Connectivity Lifecycle
Failures can happen on: client push, or client pull/ server push
● Communicate or hide connectivity state
○ Chat app
● Enable client-side creation and editing features
○ Todo app
● Disable, modify, or hide features that won’t
work
○ Facebook status, Twitter Tweets
● Notify user about possibly conflicting data
● Conflict resolution tools (merge)
How to deal with being offline
● “You are offline”
○ “Unable to connect to the Internet”
○ We need to stop treating offline as an error condition
● Try not to block features completely
○ If you can’t update, show old data (with message)
○ Let user create data locally to be sent later
● Dealing with new incoming data. Options:
○ Show it as the most recent
○ Show it in chronological order
So what are local storage storage?
● Roll your own!
○ Use localstorage, indexDb, or WebSql directly
● Open source local storage databases that sync
○ PouchDB (JavaScript database that syncs!)
○ Hoodie (Another JS db that syncs. In preview mode)
○ remotestorage.io (IETF Proposed Standard)
● Proprietary solution?
○ Firebase (AngularFire)
■ Firebase transparently reconnects to server
■ But doesn’t persist to local storage
Firebase
● Pros
○ AngularJS library (AngularFire)
○ 3-way binding with $bind
○ Free Developer (Hacker) plan
○ Paid solution with premium support
○ Hosted solution
○ Can deploy static hosted apps
● Cons
○ Proprietary solution
○ Hosted solution (can’t run local or on own servers)
○ No local storage solution
PouchDB
● Pros:
○ Open Source
○ Lightweight Cross Browser JavaScript implementation
○ Syncs with open source CouchDB protocol servers
■ PouchDB-Server - a HTTP on top of PouchDB
■ Cloudant - A cluster aware fork of CouchDB
■ Couchbase Sync Gateway
● Cons:
○ No Standard AngularJS library (yet)
■ angular-pouchdb looks promising
Sample Application: ionic-pouchdb-todo
● Source code will be available at:
○ http://github.com/danielzen/ionic-pouchdb-todo (soon)
● Uses ionic hybrid mobile app framework
● Pre-requisites:
○ Node
○ CouchDb
Resources
● Data Persistence in Angular 2.0
● Designing Offline - Alex Feyerke
● Building offline applications with AngularJS and PouchDB
● Sync multiple AngularJS apps without server via PouchDB
● TodoMVC (AngularJS) + Hood.ie = 60 minutes to awesome
A copy of these slides is available at:
http://bit.ly/zen-ng-pouchdb

Weitere ähnliche Inhalte

Was ist angesagt?

Mongodb - NoSql Database
Mongodb - NoSql DatabaseMongodb - NoSql Database
Mongodb - NoSql DatabasePrashant Gupta
 
Mongo DB: Fundamentals & Basics/ An Overview of MongoDB/ Mongo DB tutorials
Mongo DB: Fundamentals & Basics/ An Overview of MongoDB/ Mongo DB tutorialsMongo DB: Fundamentals & Basics/ An Overview of MongoDB/ Mongo DB tutorials
Mongo DB: Fundamentals & Basics/ An Overview of MongoDB/ Mongo DB tutorialsSpringPeople
 
Introduction to NoSQL Database
Introduction to NoSQL DatabaseIntroduction to NoSQL Database
Introduction to NoSQL DatabaseMohammad Alghanem
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDBMike Dirolf
 
Mongodb basics and architecture
Mongodb basics and architectureMongodb basics and architecture
Mongodb basics and architectureBishal Khanal
 
Updating materialized views and caches using kafka
Updating materialized views and caches using kafkaUpdating materialized views and caches using kafka
Updating materialized views and caches using kafkaZach Cox
 
ELK - Stack - Munich .net UG
ELK - Stack - Munich .net UGELK - Stack - Munich .net UG
ELK - Stack - Munich .net UGSteve Behrendt
 
Basics of MongoDB
Basics of MongoDB Basics of MongoDB
Basics of MongoDB Habilelabs
 
MongoDB for Beginners
MongoDB for BeginnersMongoDB for Beginners
MongoDB for BeginnersEnoch Joshua
 
MongoDB basics & Introduction
MongoDB basics & IntroductionMongoDB basics & Introduction
MongoDB basics & IntroductionJerwin Roy
 
Webtech Conference: NoSQL and Web scalability
Webtech Conference: NoSQL and Web scalabilityWebtech Conference: NoSQL and Web scalability
Webtech Conference: NoSQL and Web scalabilityLuca Bonmassar
 
Intro To Mongo Db
Intro To Mongo DbIntro To Mongo Db
Intro To Mongo Dbchriskite
 
Lecture 40 1
Lecture 40 1Lecture 40 1
Lecture 40 1patib5
 
JS App Architecture
JS App ArchitectureJS App Architecture
JS App ArchitectureCorey Butler
 
Azure doc db (slideshare)
Azure doc db (slideshare)Azure doc db (slideshare)
Azure doc db (slideshare)David Green
 

Was ist angesagt? (20)

Mongo db
Mongo dbMongo db
Mongo db
 
Mongodb - NoSql Database
Mongodb - NoSql DatabaseMongodb - NoSql Database
Mongodb - NoSql Database
 
Mongo DB: Fundamentals & Basics/ An Overview of MongoDB/ Mongo DB tutorials
Mongo DB: Fundamentals & Basics/ An Overview of MongoDB/ Mongo DB tutorialsMongo DB: Fundamentals & Basics/ An Overview of MongoDB/ Mongo DB tutorials
Mongo DB: Fundamentals & Basics/ An Overview of MongoDB/ Mongo DB tutorials
 
Introduction to NoSQL Database
Introduction to NoSQL DatabaseIntroduction to NoSQL Database
Introduction to NoSQL Database
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Mongodb basics and architecture
Mongodb basics and architectureMongodb basics and architecture
Mongodb basics and architecture
 
Mongo db nosql (1)
Mongo db nosql (1)Mongo db nosql (1)
Mongo db nosql (1)
 
Updating materialized views and caches using kafka
Updating materialized views and caches using kafkaUpdating materialized views and caches using kafka
Updating materialized views and caches using kafka
 
CouchDB
CouchDBCouchDB
CouchDB
 
ELK - Stack - Munich .net UG
ELK - Stack - Munich .net UGELK - Stack - Munich .net UG
ELK - Stack - Munich .net UG
 
Basics of MongoDB
Basics of MongoDB Basics of MongoDB
Basics of MongoDB
 
MongoDB for Beginners
MongoDB for BeginnersMongoDB for Beginners
MongoDB for Beginners
 
MongoDB basics & Introduction
MongoDB basics & IntroductionMongoDB basics & Introduction
MongoDB basics & Introduction
 
Webtech Conference: NoSQL and Web scalability
Webtech Conference: NoSQL and Web scalabilityWebtech Conference: NoSQL and Web scalability
Webtech Conference: NoSQL and Web scalability
 
Intro To Mongo Db
Intro To Mongo DbIntro To Mongo Db
Intro To Mongo Db
 
Lecture 40 1
Lecture 40 1Lecture 40 1
Lecture 40 1
 
Intro To Couch Db
Intro To Couch DbIntro To Couch Db
Intro To Couch Db
 
JS App Architecture
JS App ArchitectureJS App Architecture
JS App Architecture
 
Mongo db
Mongo dbMongo db
Mongo db
 
Azure doc db (slideshare)
Azure doc db (slideshare)Azure doc db (slideshare)
Azure doc db (slideshare)
 

Ähnlich wie FITC presents: Mobile & offline data synchronization in Angular JS

Decoupled (Headless) Drupal
Decoupled (Headless) DrupalDecoupled (Headless) Drupal
Decoupled (Headless) DrupalDaniel Stout
 
Perl Tools for Productivity
Perl Tools for ProductivityPerl Tools for Productivity
Perl Tools for ProductivityTudor Constantin
 
GraphQL in an Age of REST
GraphQL in an Age of RESTGraphQL in an Age of REST
GraphQL in an Age of RESTYos Riady
 
Designing a json/rest api for your mobile app
Designing a json/rest api for your mobile appDesigning a json/rest api for your mobile app
Designing a json/rest api for your mobile appOlivier Destrebecq
 
MongoDB World 2019: Packing Up Your Data and Moving to MongoDB Atlas
MongoDB World 2019: Packing Up Your Data and Moving to MongoDB AtlasMongoDB World 2019: Packing Up Your Data and Moving to MongoDB Atlas
MongoDB World 2019: Packing Up Your Data and Moving to MongoDB AtlasMongoDB
 
Tech meetup: Web Applications Performance
Tech meetup: Web Applications PerformanceTech meetup: Web Applications Performance
Tech meetup: Web Applications PerformanceSantex Group
 
Web App Prototypes with Google App Engine
Web App Prototypes with Google App EngineWeb App Prototypes with Google App Engine
Web App Prototypes with Google App EngineVlad Filippov
 
Progressive web applications
Progressive web applicationsProgressive web applications
Progressive web applicationsTom Martin
 
Design Web Service API by HungerStation
Design Web Service API by HungerStationDesign Web Service API by HungerStation
Design Web Service API by HungerStationArabNet ME
 
JavascriptMVC: Another choice of web framework
JavascriptMVC: Another choice of web frameworkJavascriptMVC: Another choice of web framework
JavascriptMVC: Another choice of web frameworkAlive Kuo
 
[AWS DC Meetup] Not Your Father’s WebApp: The Cloud-Native Architecture of im...
[AWS DC Meetup] Not Your Father’s WebApp: The Cloud-Native Architecture of im...[AWS DC Meetup] Not Your Father’s WebApp: The Cloud-Native Architecture of im...
[AWS DC Meetup] Not Your Father’s WebApp: The Cloud-Native Architecture of im...Chris Shenton
 
Web Service and Mobile Integrated Day I
Web Service and Mobile Integrated Day IWeb Service and Mobile Integrated Day I
Web Service and Mobile Integrated Day IAnuchit Chalothorn
 
AngularJS in Production (CTO Forum)
AngularJS in Production (CTO Forum)AngularJS in Production (CTO Forum)
AngularJS in Production (CTO Forum)Alex Ross
 
Undo, Redo and Collaboration in Web Applications
Undo, Redo and Collaboration in Web ApplicationsUndo, Redo and Collaboration in Web Applications
Undo, Redo and Collaboration in Web ApplicationsMiro Cupak
 
Ten practical ways to improve front-end performance
Ten practical ways to improve front-end performanceTen practical ways to improve front-end performance
Ten practical ways to improve front-end performanceAndrew Rota
 

Ähnlich wie FITC presents: Mobile & offline data synchronization in Angular JS (20)

Offline db
Offline dbOffline db
Offline db
 
Decoupled (Headless) Drupal
Decoupled (Headless) DrupalDecoupled (Headless) Drupal
Decoupled (Headless) Drupal
 
Perl Tools for Productivity
Perl Tools for ProductivityPerl Tools for Productivity
Perl Tools for Productivity
 
Next.js with drupal, the good parts
Next.js with drupal, the good partsNext.js with drupal, the good parts
Next.js with drupal, the good parts
 
GraphQL in an Age of REST
GraphQL in an Age of RESTGraphQL in an Age of REST
GraphQL in an Age of REST
 
Designing a json/rest api for your mobile app
Designing a json/rest api for your mobile appDesigning a json/rest api for your mobile app
Designing a json/rest api for your mobile app
 
MongoDB World 2019: Packing Up Your Data and Moving to MongoDB Atlas
MongoDB World 2019: Packing Up Your Data and Moving to MongoDB AtlasMongoDB World 2019: Packing Up Your Data and Moving to MongoDB Atlas
MongoDB World 2019: Packing Up Your Data and Moving to MongoDB Atlas
 
Dive into AngularJS and directives
Dive into AngularJS and directivesDive into AngularJS and directives
Dive into AngularJS and directives
 
Tech meetup: Web Applications Performance
Tech meetup: Web Applications PerformanceTech meetup: Web Applications Performance
Tech meetup: Web Applications Performance
 
Dust.js
Dust.jsDust.js
Dust.js
 
Web App Prototypes with Google App Engine
Web App Prototypes with Google App EngineWeb App Prototypes with Google App Engine
Web App Prototypes with Google App Engine
 
AngularJS Workshop
AngularJS WorkshopAngularJS Workshop
AngularJS Workshop
 
Progressive web applications
Progressive web applicationsProgressive web applications
Progressive web applications
 
Design Web Service API by HungerStation
Design Web Service API by HungerStationDesign Web Service API by HungerStation
Design Web Service API by HungerStation
 
JavascriptMVC: Another choice of web framework
JavascriptMVC: Another choice of web frameworkJavascriptMVC: Another choice of web framework
JavascriptMVC: Another choice of web framework
 
[AWS DC Meetup] Not Your Father’s WebApp: The Cloud-Native Architecture of im...
[AWS DC Meetup] Not Your Father’s WebApp: The Cloud-Native Architecture of im...[AWS DC Meetup] Not Your Father’s WebApp: The Cloud-Native Architecture of im...
[AWS DC Meetup] Not Your Father’s WebApp: The Cloud-Native Architecture of im...
 
Web Service and Mobile Integrated Day I
Web Service and Mobile Integrated Day IWeb Service and Mobile Integrated Day I
Web Service and Mobile Integrated Day I
 
AngularJS in Production (CTO Forum)
AngularJS in Production (CTO Forum)AngularJS in Production (CTO Forum)
AngularJS in Production (CTO Forum)
 
Undo, Redo and Collaboration in Web Applications
Undo, Redo and Collaboration in Web ApplicationsUndo, Redo and Collaboration in Web Applications
Undo, Redo and Collaboration in Web Applications
 
Ten practical ways to improve front-end performance
Ten practical ways to improve front-end performanceTen practical ways to improve front-end performance
Ten practical ways to improve front-end performance
 

Mehr von FITC

Cut it up
Cut it upCut it up
Cut it upFITC
 
Designing for Digital Health
Designing for Digital HealthDesigning for Digital Health
Designing for Digital HealthFITC
 
Profiling JavaScript Performance
Profiling JavaScript PerformanceProfiling JavaScript Performance
Profiling JavaScript PerformanceFITC
 
Surviving Your Tech Stack
Surviving Your Tech StackSurviving Your Tech Stack
Surviving Your Tech StackFITC
 
How to Pitch Your First AR Project
How to Pitch Your First AR ProjectHow to Pitch Your First AR Project
How to Pitch Your First AR ProjectFITC
 
Start by Understanding the Problem, Not by Delivering the Answer
Start by Understanding the Problem, Not by Delivering the AnswerStart by Understanding the Problem, Not by Delivering the Answer
Start by Understanding the Problem, Not by Delivering the AnswerFITC
 
Cocaine to Carrots: The Art of Telling Someone Else’s Story
Cocaine to Carrots: The Art of Telling Someone Else’s StoryCocaine to Carrots: The Art of Telling Someone Else’s Story
Cocaine to Carrots: The Art of Telling Someone Else’s StoryFITC
 
Everyday Innovation
Everyday InnovationEveryday Innovation
Everyday InnovationFITC
 
HyperLight Websites
HyperLight WebsitesHyperLight Websites
HyperLight WebsitesFITC
 
Everything is Terrifying
Everything is TerrifyingEverything is Terrifying
Everything is TerrifyingFITC
 
Post-Earth Visions: Designing for Space and the Future Human
Post-Earth Visions: Designing for Space and the Future HumanPost-Earth Visions: Designing for Space and the Future Human
Post-Earth Visions: Designing for Space and the Future HumanFITC
 
The Rise of the Creative Social Influencer (and How to Become One)
The Rise of the Creative Social Influencer (and How to Become One)The Rise of the Creative Social Influencer (and How to Become One)
The Rise of the Creative Social Influencer (and How to Become One)FITC
 
East of the Rockies: Developing an AR Game
East of the Rockies: Developing an AR GameEast of the Rockies: Developing an AR Game
East of the Rockies: Developing an AR GameFITC
 
Creating a Proactive Healthcare System
Creating a Proactive Healthcare SystemCreating a Proactive Healthcare System
Creating a Proactive Healthcare SystemFITC
 
World Transformation: The Secret Agenda of Product Design
World Transformation: The Secret Agenda of Product DesignWorld Transformation: The Secret Agenda of Product Design
World Transformation: The Secret Agenda of Product DesignFITC
 
The Power of Now
The Power of NowThe Power of Now
The Power of NowFITC
 
High Performance PWAs
High Performance PWAsHigh Performance PWAs
High Performance PWAsFITC
 
Rise of the JAMstack
Rise of the JAMstackRise of the JAMstack
Rise of the JAMstackFITC
 
From Closed to Open: A Journey of Self Discovery
From Closed to Open: A Journey of Self DiscoveryFrom Closed to Open: A Journey of Self Discovery
From Closed to Open: A Journey of Self DiscoveryFITC
 
Projects Ain’t Nobody Got Time For
Projects Ain’t Nobody Got Time ForProjects Ain’t Nobody Got Time For
Projects Ain’t Nobody Got Time ForFITC
 

Mehr von FITC (20)

Cut it up
Cut it upCut it up
Cut it up
 
Designing for Digital Health
Designing for Digital HealthDesigning for Digital Health
Designing for Digital Health
 
Profiling JavaScript Performance
Profiling JavaScript PerformanceProfiling JavaScript Performance
Profiling JavaScript Performance
 
Surviving Your Tech Stack
Surviving Your Tech StackSurviving Your Tech Stack
Surviving Your Tech Stack
 
How to Pitch Your First AR Project
How to Pitch Your First AR ProjectHow to Pitch Your First AR Project
How to Pitch Your First AR Project
 
Start by Understanding the Problem, Not by Delivering the Answer
Start by Understanding the Problem, Not by Delivering the AnswerStart by Understanding the Problem, Not by Delivering the Answer
Start by Understanding the Problem, Not by Delivering the Answer
 
Cocaine to Carrots: The Art of Telling Someone Else’s Story
Cocaine to Carrots: The Art of Telling Someone Else’s StoryCocaine to Carrots: The Art of Telling Someone Else’s Story
Cocaine to Carrots: The Art of Telling Someone Else’s Story
 
Everyday Innovation
Everyday InnovationEveryday Innovation
Everyday Innovation
 
HyperLight Websites
HyperLight WebsitesHyperLight Websites
HyperLight Websites
 
Everything is Terrifying
Everything is TerrifyingEverything is Terrifying
Everything is Terrifying
 
Post-Earth Visions: Designing for Space and the Future Human
Post-Earth Visions: Designing for Space and the Future HumanPost-Earth Visions: Designing for Space and the Future Human
Post-Earth Visions: Designing for Space and the Future Human
 
The Rise of the Creative Social Influencer (and How to Become One)
The Rise of the Creative Social Influencer (and How to Become One)The Rise of the Creative Social Influencer (and How to Become One)
The Rise of the Creative Social Influencer (and How to Become One)
 
East of the Rockies: Developing an AR Game
East of the Rockies: Developing an AR GameEast of the Rockies: Developing an AR Game
East of the Rockies: Developing an AR Game
 
Creating a Proactive Healthcare System
Creating a Proactive Healthcare SystemCreating a Proactive Healthcare System
Creating a Proactive Healthcare System
 
World Transformation: The Secret Agenda of Product Design
World Transformation: The Secret Agenda of Product DesignWorld Transformation: The Secret Agenda of Product Design
World Transformation: The Secret Agenda of Product Design
 
The Power of Now
The Power of NowThe Power of Now
The Power of Now
 
High Performance PWAs
High Performance PWAsHigh Performance PWAs
High Performance PWAs
 
Rise of the JAMstack
Rise of the JAMstackRise of the JAMstack
Rise of the JAMstack
 
From Closed to Open: A Journey of Self Discovery
From Closed to Open: A Journey of Self DiscoveryFrom Closed to Open: A Journey of Self Discovery
From Closed to Open: A Journey of Self Discovery
 
Projects Ain’t Nobody Got Time For
Projects Ain’t Nobody Got Time ForProjects Ain’t Nobody Got Time For
Projects Ain’t Nobody Got Time For
 

Kürzlich hochgeladen

Mira Road Housewife Call Girls 07506202331, Nalasopara Call Girls
Mira Road Housewife Call Girls 07506202331, Nalasopara Call GirlsMira Road Housewife Call Girls 07506202331, Nalasopara Call Girls
Mira Road Housewife Call Girls 07506202331, Nalasopara Call GirlsPriya Reddy
 
20240508 QFM014 Elixir Reading List April 2024.pdf
20240508 QFM014 Elixir Reading List April 2024.pdf20240508 QFM014 Elixir Reading List April 2024.pdf
20240508 QFM014 Elixir Reading List April 2024.pdfMatthew Sinclair
 
Abu Dhabi Escorts Service 0508644382 Escorts in Abu Dhabi
Abu Dhabi Escorts Service 0508644382 Escorts in Abu DhabiAbu Dhabi Escorts Service 0508644382 Escorts in Abu Dhabi
Abu Dhabi Escorts Service 0508644382 Escorts in Abu DhabiMonica Sydney
 
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girlsRussian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girlsMonica Sydney
 
Tadepalligudem Escorts Service Girl ^ 9332606886, WhatsApp Anytime Tadepallig...
Tadepalligudem Escorts Service Girl ^ 9332606886, WhatsApp Anytime Tadepallig...Tadepalligudem Escorts Service Girl ^ 9332606886, WhatsApp Anytime Tadepallig...
Tadepalligudem Escorts Service Girl ^ 9332606886, WhatsApp Anytime Tadepallig...meghakumariji156
 
Call girls Service in Ajman 0505086370 Ajman call girls
Call girls Service in Ajman 0505086370 Ajman call girlsCall girls Service in Ajman 0505086370 Ajman call girls
Call girls Service in Ajman 0505086370 Ajman call girlsMonica Sydney
 
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查ydyuyu
 
Real Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirtReal Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirtrahman018755
 
best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...
best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...
best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...kajalverma014
 
Best SEO Services Company in Dallas | Best SEO Agency Dallas
Best SEO Services Company in Dallas | Best SEO Agency DallasBest SEO Services Company in Dallas | Best SEO Agency Dallas
Best SEO Services Company in Dallas | Best SEO Agency DallasDigicorns Technologies
 
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样ayvbos
 
Vip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac Room
Vip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac RoomVip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac Room
Vip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac Roommeghakumariji156
 
Local Call Girls in Seoni 9332606886 HOT & SEXY Models beautiful and charmin...
Local Call Girls in Seoni  9332606886 HOT & SEXY Models beautiful and charmin...Local Call Girls in Seoni  9332606886 HOT & SEXY Models beautiful and charmin...
Local Call Girls in Seoni 9332606886 HOT & SEXY Models beautiful and charmin...kumargunjan9515
 
Russian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi EscortsRussian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi EscortsMonica Sydney
 
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoil
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime NagercoilNagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoil
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoilmeghakumariji156
 
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
20240509 QFM015 Engineering Leadership Reading List April 2024.pdfMatthew Sinclair
 
Indian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Indian Escort in Abu DHabi 0508644382 Abu Dhabi EscortsIndian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Indian Escort in Abu DHabi 0508644382 Abu Dhabi EscortsMonica Sydney
 
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrStory Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrHenryBriggs2
 
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制pxcywzqs
 

Kürzlich hochgeladen (20)

Mira Road Housewife Call Girls 07506202331, Nalasopara Call Girls
Mira Road Housewife Call Girls 07506202331, Nalasopara Call GirlsMira Road Housewife Call Girls 07506202331, Nalasopara Call Girls
Mira Road Housewife Call Girls 07506202331, Nalasopara Call Girls
 
20240508 QFM014 Elixir Reading List April 2024.pdf
20240508 QFM014 Elixir Reading List April 2024.pdf20240508 QFM014 Elixir Reading List April 2024.pdf
20240508 QFM014 Elixir Reading List April 2024.pdf
 
Abu Dhabi Escorts Service 0508644382 Escorts in Abu Dhabi
Abu Dhabi Escorts Service 0508644382 Escorts in Abu DhabiAbu Dhabi Escorts Service 0508644382 Escorts in Abu Dhabi
Abu Dhabi Escorts Service 0508644382 Escorts in Abu Dhabi
 
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girlsRussian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
 
Tadepalligudem Escorts Service Girl ^ 9332606886, WhatsApp Anytime Tadepallig...
Tadepalligudem Escorts Service Girl ^ 9332606886, WhatsApp Anytime Tadepallig...Tadepalligudem Escorts Service Girl ^ 9332606886, WhatsApp Anytime Tadepallig...
Tadepalligudem Escorts Service Girl ^ 9332606886, WhatsApp Anytime Tadepallig...
 
Call girls Service in Ajman 0505086370 Ajman call girls
Call girls Service in Ajman 0505086370 Ajman call girlsCall girls Service in Ajman 0505086370 Ajman call girls
Call girls Service in Ajman 0505086370 Ajman call girls
 
call girls in Anand Vihar (delhi) call me [🔝9953056974🔝] escort service 24X7
call girls in Anand Vihar (delhi) call me [🔝9953056974🔝] escort service 24X7call girls in Anand Vihar (delhi) call me [🔝9953056974🔝] escort service 24X7
call girls in Anand Vihar (delhi) call me [🔝9953056974🔝] escort service 24X7
 
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
 
Real Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirtReal Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirt
 
best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...
best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...
best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...
 
Best SEO Services Company in Dallas | Best SEO Agency Dallas
Best SEO Services Company in Dallas | Best SEO Agency DallasBest SEO Services Company in Dallas | Best SEO Agency Dallas
Best SEO Services Company in Dallas | Best SEO Agency Dallas
 
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
 
Vip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac Room
Vip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac RoomVip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac Room
Vip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac Room
 
Local Call Girls in Seoni 9332606886 HOT & SEXY Models beautiful and charmin...
Local Call Girls in Seoni  9332606886 HOT & SEXY Models beautiful and charmin...Local Call Girls in Seoni  9332606886 HOT & SEXY Models beautiful and charmin...
Local Call Girls in Seoni 9332606886 HOT & SEXY Models beautiful and charmin...
 
Russian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi EscortsRussian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
 
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoil
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime NagercoilNagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoil
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoil
 
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
 
Indian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Indian Escort in Abu DHabi 0508644382 Abu Dhabi EscortsIndian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Indian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
 
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrStory Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
 
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
 

FITC presents: Mobile & offline data synchronization in Angular JS

  • 1. Mobile & Offline Data Synchronization in AngularJS http://bit.ly/zen-ng-pouchdb Daniel Zen @zendigital
  • 2. My Background ● Longtime JavaScript programmer ● Former XP Consultant for Google & Pivotal ● Started using AngularJS 2 years ago ● Started AngularJS-NYC Meetup May 2012 ● Reformed Zen Digital consultancy 2013 ○ Web & mobile application development ○ Focus on using latest technologies & solutions
  • 3. Outline for this talk: ● Requirements for AngularJS data models ● Standard Online Techniques ○ CRUD,RESTful APIs ○ $http, $resource ● Offline issues ● local storage options ● Sample Application walk through ○ Ionic ○ PouchDb
  • 4. Requirements for data models in AngularJS:
  • 5. Requirements for models in AngularJS: ABSOLUTELY NOTHING ● AngularJS is model agnostic ● Any variable or object can serve as a model ● No unique ID required ● No built-in persistence model for objects ● ng-model binds javascript variables to UI not to backend
  • 6. What does this mean for data persistence ● There is no standard, yet ○ See AngularJS 2.0 Data Persistence Design Doc ● Various open source storage options ○ SQL ■ MySQL ■ PostgreSQL ○ NoSQL ■ MongoDB ■ CouchDB
  • 7. Common Persistence Practices ● CRUD - Create, read, update and delete Each letter in the acronym can map to a standard SQL statement and HTTP method: Operation` SQL HTTP Create INSERT PUT / POST Read (Retrieve) SELECT GET Update (Modify) UPDATE PUT / PATCH Delete (Destroy) DELETE DELETE
  • 8. Typically we employ RESTful APIs ● RESTful APIs - Representational state transfer The name “Representational State Transfer” is intended to evoke an image of how a well-designed Web application behaves: a network of Web pages forms a virtual state machine, allowing a user to progress through the application by selecting a link or submitting a short data-entry form, with each action resulting in a transition to the next state of the application by transferring a representation of that state to the user. - Roy Fielding ● HTTP 1.1 based on REST
  • 9. Common REST Practices Resource POST create GET read PUT update DELETE delete /accounts Create a new account List accounts Bulk update accounts Delete all accounts /accounts/123 Error Show account 123 If exists update account 123 If not error Delete account 123 /customers Create a new customer List customers Bulk update customers Delete all customers /customers/456 Error Show customer 456 If exists update customer 456 If not error Delete customer 456
  • 10. $http Service ● The AngularJS XmlHttpRequest API follows the Promise interface ($q service) ○ Returns a promise object with the standard then method and two http specific methods: success and error. $http({method: 'GET', url: '/someUrl'}). success(function(data, status, headers, config) { // this callback will be called asynchronously // when the response is available }). error(function(data, status, headers, config) { // called asynchronously if an error occurs // or server returns response with an error status. });
  • 11. $resource - a higher level abstraction ● service in module ngResource ● factory lets you interact with server-side data ● returns resource with methods for CRUD operations: get, save, query, remove, delete ● operations can be invoked by the following: ● no need to interact with the low level $http ● HTTP GET "class" actions: Resource.action([parameters], [success], [error]) ● non-GET "class" actions: Resource.action([parameters], postData, [success], [error]) ● non-GET instance actions: instance.$action([parameters], [success], [error])
  • 12. $resource - a higher level abstraction ● You can also access the raw $http promise via the $promise property on the object returned ● More reference: Angular communication $http & $resource var User = $resource('/users/:userId', {userId:'@id'}); User.get({userId:123}) .$promise.then(function(user) { $scope.user = user; })
  • 13. But what about offline? ● Web apps no longer dependent on servers ● Solution: richer clients (using AngularJS ;) ● Google Docs is a good example ● For offline first experience: ○ You need to store the data in the front end ○ You need it to sync to the server’s data store. ● In browser databases available: ○ derby.js, Lawnchair, Sench touch ● requirement: online synchronization
  • 14. What have we come to expect ● Email should work offline ○ Local copy of recent emails ○ Can read or delete ○ Can write new emails, and will send when online ● Google Docs keeps pushing threshold ○ In Chrome we can view and edit while offline ○ mobile version now has offline edit capability ● Conflict resolution ○ Intelligently merge documents with multiple edits
  • 15. Connectivity Lifecycle Failures can happen on: client push, or client pull/ server push ● Communicate or hide connectivity state ○ Chat app ● Enable client-side creation and editing features ○ Todo app ● Disable, modify, or hide features that won’t work ○ Facebook status, Twitter Tweets ● Notify user about possibly conflicting data ● Conflict resolution tools (merge)
  • 16. How to deal with being offline ● “You are offline” ○ “Unable to connect to the Internet” ○ We need to stop treating offline as an error condition ● Try not to block features completely ○ If you can’t update, show old data (with message) ○ Let user create data locally to be sent later ● Dealing with new incoming data. Options: ○ Show it as the most recent ○ Show it in chronological order
  • 17. So what are local storage storage? ● Roll your own! ○ Use localstorage, indexDb, or WebSql directly ● Open source local storage databases that sync ○ PouchDB (JavaScript database that syncs!) ○ Hoodie (Another JS db that syncs. In preview mode) ○ remotestorage.io (IETF Proposed Standard) ● Proprietary solution? ○ Firebase (AngularFire) ■ Firebase transparently reconnects to server ■ But doesn’t persist to local storage
  • 18. Firebase ● Pros ○ AngularJS library (AngularFire) ○ 3-way binding with $bind ○ Free Developer (Hacker) plan ○ Paid solution with premium support ○ Hosted solution ○ Can deploy static hosted apps ● Cons ○ Proprietary solution ○ Hosted solution (can’t run local or on own servers) ○ No local storage solution
  • 19. PouchDB ● Pros: ○ Open Source ○ Lightweight Cross Browser JavaScript implementation ○ Syncs with open source CouchDB protocol servers ■ PouchDB-Server - a HTTP on top of PouchDB ■ Cloudant - A cluster aware fork of CouchDB ■ Couchbase Sync Gateway ● Cons: ○ No Standard AngularJS library (yet) ■ angular-pouchdb looks promising
  • 20. Sample Application: ionic-pouchdb-todo ● Source code will be available at: ○ http://github.com/danielzen/ionic-pouchdb-todo (soon) ● Uses ionic hybrid mobile app framework ● Pre-requisites: ○ Node ○ CouchDb
  • 21. Resources ● Data Persistence in Angular 2.0 ● Designing Offline - Alex Feyerke ● Building offline applications with AngularJS and PouchDB ● Sync multiple AngularJS apps without server via PouchDB ● TodoMVC (AngularJS) + Hood.ie = 60 minutes to awesome A copy of these slides is available at: http://bit.ly/zen-ng-pouchdb