]> git.proxmox.com Git - sencha-touch.git/blob - src/src/platform/src/data/sync/CS.js
import Sencha Touch 2.4.2 source
[sencha-touch.git] / src / src / platform / src / data / sync / CS.js
1
2 Ext.data.CS = Ext.extend(Object, { // Change Stamp
3
4 r: 0, // replica_number
5 t: 0, // time, in seconds since the epoch
6 s: 0, // sequence number
7
8 constructor: function(config) {
9 this.set(config);
10 },
11
12 set: function(x) {
13 if (typeof x === 'string' || x instanceof String) {
14 this.from_s(x)
15 } else if (typeof x === 'object') {
16 this.r= x.r||0;
17 this.t= x.t||0;
18 this.s= x.s||0;
19 }
20 },
21
22 changeReplicaNumber: function(old_replica_number,new_replica_number) {
23 if (this.r==old_replica_number) {
24 this.r= new_replica_number;
25 return true;
26 }
27 return false;
28 },
29
30 greaterThan: function(x) { return this.compare(x)>0; },
31 lessThan: function(x) { return this.compare(x)<0; },
32 equals: function(x) { return this.compare(x)===0 },
33 compare: function(x) {
34 var r= this.t-x.t
35 if (r==0) {
36 r= this.s-x.s;
37 if (r==0) {
38 r= this.r-x.r
39 }
40 }
41 return r;
42 },
43
44 from_s: function(t) {
45 var m= t.match(/(\d+)-(\d+)-?(\d+)?/)
46 if (m && m.length>0) {
47 this.r= parseInt(m[1])
48 this.t= parseInt(m[2])
49 this.s= m[3] ? parseInt(m[3]) : 0
50 } else {
51 throw "Error - CS - Bad change stamp '"+t+"'."
52 }
53 return this;
54 },
55
56 to_s: function() {
57 return this.r+"-"+this.t+(this.s>0 ? "-"+this.s : "");
58 }
59
60 });