Permalink
Browse files

Working on selectJSON, refactoring some code.

  • Loading branch information...
1 parent 29850cd commit 792501e139ff69b2255cff68ca7939c8f3f91cf9 @zefhemel zefhemel committed Sep 26, 2010
Showing with 295 additions and 108 deletions.
  1. +4 −2 README.md
  2. +37 −0 docs/DEVELOPMENT.md
  3. +197 −55 lib/persistence.js
  4. +15 −49 lib/persistence.store.sql.js
  5. +42 −2 test/test.persistence.js
View
@@ -90,7 +90,7 @@ Browser support
* Modern webkit browsers (Google Chrome and Safari)
* Firefox (through Google Gears)
-* Android browser (tested on 1.6 and 2.1)
+* Android browser (tested on 1.6 and 2.x)
* iPhone browser (iPhone OS 3+)
* Palm WebOS (tested on 1.4.0)
@@ -286,7 +286,9 @@ using the `list(...)` method on a database `QueryCollection`, which also
flushes first, although this behavior may change in the future.
Dumping and restoring data
---------------------------------
+--------------------------
+
+The library supports two kinds of dumping and restoring data.
`persistence.dump` can be used to create an object containing a full
dump of a database. Naturally, it is adviced to only do this with
View
@@ -40,3 +40,40 @@ Extension hooks
add new functionality to constructo functions, such as `Task.index`.
* `persistence.flushHooks`: a list of functions to be called before flushing.
* `persistence.schemaSyncHooks`: a list of functions to be called before syncing the schema.
+
+Idioms
+------
+
+Because persistence.js is an asynchronous library, a lot happens
+asynchronously (shocker). The way I typically handle an unknown
+sequence of asynchronous calls is as follows, I know it's expensive on
+the stack (it makes a lot of recursive calls), but it's the best I've
+been able to come up with.
+
+Let's say we have an array `myArray` of values and we have to invoke a
+function `someAsyncFunction` on each item sequentially. Except, the
+function is asynchronous, and thus does not return a value
+immediately, but instead has a callback that is called with the
+result. This is how I typically implement that in persistence.js, note
+that this destroys `myArray`, at the end the array is empty, so if you
+care about its value, `.slice(0)` it first.
+
+ var myArray = [1, 2, 3, 4, 5];
+
+ function processOne() {
+ var item = myArray.pop(); // pop (last) item from the array
+ someAsyncFunction(item, function(result) {
+ // do something with result
+ if(myArray.length > 0) {
+ processOne();
+ } else {
+ // Do whatever you need when you're completely done
+ }
+ });
+ }
+
+ if(myArray.length > 0) {
+ processOne();
+ } else {
+ // Do whatever you need when you're completely done
+ }
Oops, something went wrong.

0 comments on commit 792501e

Please sign in to comment.