Sencha Inc. | HTML5 Apps

Blog

Using Sencha.io Sync

September 30, 2011 | Aditya Bansod

Sencha.io Sencha.io Sync was made available as an open beta last week, so we wanted to give a more detailed look at how to use Sync. We announced Sencha.io Sync in the early summer and have spent time honing and tuning the service based on feedback from our private beta customers, and we’re excited to invite the Sencha community to try their hands at our Sync service.

Since Sync is now in open beta, feel free to use it, but it’s still a beta. There are a few things that we suggest you be careful of during the beta. Particularly, please don’t run any production applications against Sync yet. While we don’t expect any data loss (and by its nature, you have a whole replica in your local browser!), it’s still a beta so there may be some edge cases or behaviors we haven’t yet tested. It’s also likely that after the beta period is over we’ll reset the stores, so there may be a migration of your data at the end of the beta before the service goes v1. Of course, we’ll communicate anything that we do here and in the Sencha Forums.

Using Sync, apps can operate offline, ensuring that all writes made to the local storage are replicated to the cloud master; apps can use Sync to backup data so the cloud has a replica of everything that’s in the client, and to recover data if the mobile data set gets lost. Better still, since Sync is multi-master, if an app expects a user to be on multiple devices, the data set can be edited and synced seamlessly between devices; or, if the app is multi-user, the same data set can be edited by multiple users from their own mobile devices.

Sencha.io Sync Essentially, Sencha.io Sync provides the app with a distributed object store. A complete replica of the entire object store is available to each client, and each replica can receive updates and exchange updates with its peers through Sencha.io Sync. If the network is lost, the clients can continue to update and edit the data and it will get synced back together across all the peers when the network is available again.

It’s easy to get started with Sync. First, you need a developer key. During the beta, the developer key is your Sencha login ID, the same ID you use to log in to the Forums or Designer. Second, you need to change your proxy from ‘localstorage’ or whatever else your app is using to ‘syncstorage’. And that’s it. From there, your model will get replicated to Sencha.io Sync, with a local copy kept in local storage.

Here’s a code snippet that shows what you need to change on proxy:

/**
* @class Contact
* @extends Ext.data.Model
* The Contact model
*/
Ext.regModel("Contact", {
   fields: [
       {name: "id", type: "string"},
       {name: "firstName", type: "string"},
       {name: "lastName", type: "string"},
       {name: "email", type: "string"},
   ],

   proxy: {
                id: 'contacts',
                type: 'syncstorage',
                key: 'yoursenchaidname'
   }
});

It’s exactly as easy as it looks. As a reminder, during the beta, your key will be the same as your Sencha ID. For example, if you log in to the Forums as ‘johndoe,’ your key will be ‘johndoe.’ Also during the beta, you will need a special “Sencha Touch 1.2.0-alpha-sync-only” build. We’ve included the new syncstore in this build specifically, otherwise it’s identical to Sencha Touch 1.1. You can download the new special Sencha Touch bits, plus a more detailed Getting Started guide in the Sencha Forum and get started today!

There are 15 responses. Add yours.

Andrea Cammarata

3 years ago

I’m going to try it immediately!
Great work! wink

Andrea Cammarata

3 years ago

I just finish to make some test…wow guys, that’s really an amazing and powerfull tools. I will use for sure in my application!

Andy

3 years ago

One question if I deliver my sencha touch application to a large number of customers:
How can I separate the data? Each customer (=smartphone) should have it´s own data.
If they use the same proxy they all have the same database!

Aditya Bansod Sencha Employee

3 years ago

@Andy—think of it is as shared database. If you need multiple, then give them their own ID and then you can use create independent ones per user.

Ivan Jouikov

3 years ago

The level of ExtJS effort is amazing!

How will you deal with collisions, i.e. 2 offline devices coming back online and trying to sync back the same piece of data?

michael mullany

3 years ago

@Ivan - there is a very simply collision algorithm - it’s just last write wins, and we trust local time to be telling the truth about when the write was made.

Ivan Jouikov

3 years ago

Will you allow customization to that algorithm?  i.e. if such conflict is detect, my preference would be that a higher-privileged user’s changes are kept.

Michael Mullany

3 years ago

@ivan - not in the initial version, and we have no plans to put in in the roadmap.

Andrés León

3 years ago

Is it possible to download a demo application to review the code?

Andrés León

3 years ago

tengo una aplicacion que tien como proxy type local storage. En la aplicacion puede haber varios usuarios. ¿Es posible actualizar solo un usuario concreto y no toda la base de datos?

Andrés León

3 years ago

I have an application that has local storage as a proxy type. In the application may have multiple users. Is it possible to update only a specific user and not the entire database?

Nafisa Williams

3 years ago

A great opportunity to be grabbed.

Aditya Bansod Sencha Employee

3 years ago

@Andres—if you want to do that, create multiple databases (i.e. a new ID for each user). Sync is designed for each to be eventually consistent so across a specific database, you can’t have one update and not the other.

Deep

3 years ago

Hi Guys,

Sync is just some libraries or need your cloud service to work.  Will it be part of free Sencha touch or paid.

Some clarity on this will help us plan.

regards,

Rob

3 years ago

I know you commented on the question of multiple users/phones problem by manually creating unique id’s. But do you have any plans to provide an automated or scalable approach to this? If an app is created and distributed via the app stores it will quickly become unmanageable if it is successful. Any inside in to functionality we will be able to count on as developers is appreciated.

Comments are Gravatar enabled. Your email address will not be shown.

Commenting is not available in this channel entry.