Created
December 4, 2015 08:07
-
-
Save tivac/a0b596920ea80f2758b5 to your computer and use it in GitHub Desktop.
Setting nested objects that maintain order into Firebase
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var traverse = require("traverse"); | |
// Traverse object, calculate priority at each level | |
// so order is maintained (barf barf barf) | |
traverse(obj).forEach(function(value) { | |
if(this.isRoot) { | |
priority = 0; | |
return; | |
} | |
db.child(this.path.join("/")).setWithPriority( | |
this.isLeaf ? value : "placeholder", | |
priority | |
); | |
if(this.notLeaf) { | |
priority = 0; | |
} else { | |
priority++; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment