|
@@ -1,46 +1,11 @@
|
|
|
var adapter = {
|
|
|
server_url: "",
|
|
|
responseJson: {},
|
|
|
- onset: function () {},
|
|
|
- onget: function () {},
|
|
|
- differ: function (base, object) {
|
|
|
- base = JSON.parse(JSON.stringify(base));
|
|
|
- object = JSON.parse(JSON.stringify(object));
|
|
|
-
|
|
|
- console.log('INPUT', base, object);
|
|
|
-
|
|
|
- function difference(o1, o2) {
|
|
|
- var k, kDiff,
|
|
|
- diff = {};
|
|
|
- for (k in o1) {
|
|
|
- if (!o1.hasOwnProperty(k)) {
|
|
|
- } else if (typeof o1[k] != 'object' || typeof o2[k] != 'object') {
|
|
|
- if (!(k in o2) || o1[k] !== o2[k]) {
|
|
|
- diff[k] = o2[k];
|
|
|
- }
|
|
|
- } else if (kDiff = difference(o1[k], o2[k])) {
|
|
|
- diff[k] = kDiff;
|
|
|
- }
|
|
|
- }
|
|
|
- for (k in o2) {
|
|
|
- if (o2.hasOwnProperty(k) && !(k in o1)) {
|
|
|
- diff[k] = o2[k];
|
|
|
- }
|
|
|
- }
|
|
|
- for (k in diff) {
|
|
|
- if (diff.hasOwnProperty(k)) {
|
|
|
- return diff;
|
|
|
- }
|
|
|
- }
|
|
|
- return {};
|
|
|
- }
|
|
|
- return difference(base, object);
|
|
|
- },
|
|
|
+ onset: function() {},
|
|
|
+ onget: function() {},
|
|
|
setter: function () {
|
|
|
-
|
|
|
- var diff = this.differ(this.responseJson, this.onset());
|
|
|
xhr = new XMLHttpRequest();
|
|
|
- xhr.open('GET', this.server_url + '/set/' + encodeURIComponent(JSON.stringify(diff)));
|
|
|
+ xhr.open('GET', this.server_url + '/set/' + encodeURIComponent(JSON.stringify(this.onset())));
|
|
|
xhr.onload = function () {
|
|
|
console.log(xhr.responseText);
|
|
|
};
|
|
@@ -52,10 +17,9 @@ var adapter = {
|
|
|
xhr.open('GET', this.server_url + '/get');
|
|
|
xhr.onload = function () {
|
|
|
try {
|
|
|
- console.log(JSON.parse(this.responseText));
|
|
|
- self.responseJson = JSON.parse(this.responseText);
|
|
|
+ var response = JSON.parse(this.responseText);
|
|
|
+ self.responseJson = response;
|
|
|
self.onget();
|
|
|
- console.log('loaded');
|
|
|
} catch (err) {
|
|
|
console.warn("json could not be parsed:", err, this.responseText);
|
|
|
}
|