Skip to content

Commit 92c64c5

Browse files
authored
Merge pull request #6 from flamebase/develop
Develop
2 parents b477130 + 360eba7 commit 92c64c5

3 files changed

Lines changed: 59 additions & 6 deletions

File tree

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ var message = {};
6060
message.author = "john_travolta@ddd.com";
6161
message.text = "Message 5";
6262

63-
var messageId = new Date().getTime().toString();
63+
var messageId = new Date().getTime() + "";
6464

6565
FD.ref.messages[messageId] = message;
6666

@@ -125,6 +125,12 @@ config.notification = function() {
125125

126126
FD.setSyncConfig(config);
127127
```
128+
Now all reference changes are sent every time you call `FD.syncToDatabase()`. It only sends changes.
129+
130+
For sending full reference:
131+
```javascript
132+
FD.syncToDatabase(true);
133+
```
128134
- Enable debug logs:
129135
```javascript
130136
FD.debug(true);

index.js

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,21 +53,30 @@ function FlamebaseDatabase(database, path) {
5353
object.ref = object.db.getData(path);
5454
object.syncNotifications();
5555
} catch(e) {
56-
console.log("####################### data error: " + e);
57-
console.log("####################### deleting: " + path);
56+
console.log("####################### not found, generating {} ");
57+
// object.createEmptyReferenceForPath(e, path);
58+
59+
/*
5860
try {
61+
// console.log("####################### deleting: " + path);
5962
object.db.delete(path);
6063
} catch (e) {
6164
62-
}
65+
}*/
6366
object.ref = {};
6467
}
6568
};
6669

6770
/**
6871
* sync to database
6972
*/
70-
this.syncToDatabase = function() {
73+
this.syncToDatabase = function(restart) {
74+
if (restart !== undefined && restart) {
75+
this.lastStringReference = JSON.stringify({});
76+
if (this.debugVal) {
77+
logger.debug("cleaning last reference on " + path);
78+
}
79+
}
7180
object.db.push(path, object.ref);
7281
object.syncNotifications();
7382
};
@@ -262,6 +271,44 @@ function FlamebaseDatabase(database, path) {
262271
return result;
263272
};
264273

274+
/*this.createEmptyReferenceForPath = function(e, path) {
275+
var aux = null;
276+
if (e.toString().indexOf("Can't find dataPath") > -1) {
277+
278+
var mainRef = object.db.getData("/");
279+
var pathParts = path.split("/");
280+
281+
for (var p = 0; p < pathParts.length; p++) {
282+
var pa = pathParts[p];
283+
284+
if (pa.length === 0) {
285+
continue;
286+
}
287+
288+
if (aux === null) {
289+
if (mainRef[pa] !== undefined) {
290+
aux = mainRef[pa];
291+
} else {
292+
mainRef[pa] = {};
293+
aux = mainRef[pa]
294+
}
295+
} else {
296+
if (aux[pa] !== undefined) {
297+
aux = aux[pa];
298+
} else {
299+
aux[pa] = {};
300+
aux = aux[pa]
301+
}
302+
}
303+
}
304+
305+
logger.debug("generated: " + JSON.stringifyAligned(mainRef));
306+
307+
object.ref = mainRef;
308+
object.db.push("/", mainRef);
309+
}
310+
};*/
311+
265312
this.exist = function() {
266313
return !(this.ref === null || this.ref === undefined)
267314
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,5 @@
4747
"scripts": {
4848
"test": "echo \"Error: no test specified\" && exit 1"
4949
},
50-
"version": "1.0.2"
50+
"version": "1.1.0"
5151
}

0 commit comments

Comments
 (0)