This file contains 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
{ | |
"rules": { | |
// REQUIRED FIELDS | |
"example1" : { | |
"$record": { | |
// foo and bar are required fields that must always exist | |
// this will reject writes to $record, as well as directly to $record/foo or $record/bar if they are null | |
".validate": "newData.hasChildren(['foo', 'bar'])" | |
} |
This file contains 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 Firebase = require('firebase'); | |
var rootRef = new Firebase("https://<YOUR-FIREBASE-APP>.firebaseio.com/"); | |
var archiveRef = rootRef.child('path/to/archive'); | |
var dataRef = rootRef.child('path/to/data'); | |
var archiveTimestamp = Date.now() - 3600; // everything older than an hour | |
dataRef.orderByChild('<date field>').endAt(archiveTimestamp).once('value', function(snap) { | |
snap.forEach(function(childSnap) { | |
archiveRef.child( childSnap.key() ).set( childSnap.val(), function(err) { |
This file contains 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
// Not all API methods are implemented in this proof | |
// See https://www.firebase.com/docs/web/api/query/ | |
var FirebaseQueryWrapper = (function() { | |
function FirebaseQueryWrapper(url) { | |
this.ref = new Firebase(url); | |
this.parms = {}; | |
} | |
var proto = FirebaseQueryWrapper.prototype; |
This file contains 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 fb = new Firebase('https://<INSTANCE>.firebaseio.com'); | |
var idxRef = fb.child('users/kato/companies'); | |
var dataRef = fb.child('companies'); | |
idxRef.on('child_added', function(userSnap) { | |
dataRef.child(userSnap.key()).once('value', function(snap) { | |
console.log('user ' + userSnap.key() + ' belongs to company ' + snap.key()); | |
}); | |
}); |
This file contains 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
// this will be much more efficient than $watch() | |
app.factory('FilteredArray', function($firebaseArray) { | |
function FilteredArray(ref, filterFn) { | |
this.filterFn = filterFn; | |
return $firebaseArray.call(this, ref); | |
} | |
FilteredArray.prototype.$$added = function(snap) { | |
var rec = $firebaseArray.prototype.$$added.call(this, snap); | |
if( !this.filterFn || this.filterFn(rec) ) { | |
return rec; |
This file contains 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
{ | |
"auctions": { | |
"$auction_id": { | |
"current_bid": { | |
".validate": "newData.hasChildren(['uid', 'amount'])", | |
"uid": { | |
".validate": "newData.val() === auth.uid" | |
}, | |
"amount": { | |
".validate": "newData.isNumber() && newData.val() > data.val() && newData.val() === root.child('auctions/'+$auction_id+'/bids/'+auth.uid+'/amount').val()" |
This file contains 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 DynamicPathMonitor = require('./DynamicPathMonitor'); | |
// call this instead of new PathMonitor inside PathMonitor.process | |
function NestedPathMonitor(ref, factory) { | |
this.factory = factory; | |
this.paths = {}; | |
ref.on('child_added', this._add, this); | |
ref.on('child_removed', this._remove, this); | |
} | |
This file contains 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 app = angular.module('app', ['firebase']); | |
app.controller('ctrl', function($scope, $pageArray) { | |
$scope.pageItems = $pageArray(ref, 'number'); | |
}); | |
app.factory('$pageArray', function($firebaseArray) { | |
return function(ref, field) { | |
// create a Paginate reference | |
var pageRef = new Firebase.util.Paginate(ref, field, {maxCacheSize: 250}); |
This file contains 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 app = angular.module('app', ['firebase']); | |
app.controller('ctrl', function($scope) { | |
var ref = new Firebase('https://fbutil.firebaseio.com/paginate'); | |
$scope.scrollItems = $scrollArray(ref, 'number'); | |
}); | |
app.factory('$scrollArray', function($firebaseArray) { | |
return function(ref, field) { | |
// create a special scroll ref |
This file contains 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 app = angular.module('app', ['firebase', 'ui.grid', 'ui.grid.infiniteScroll']); | |
app.controller('ctrl', function($scope, $firebaseArray) { | |
var baseRef = new Firebase('https://fbutil.firebaseio.com/paginate'); | |
var scrollRef = new Firebase.util.Scroll(baseRef, 'number'); | |
//$scope.data = $firebaseArray(scrollRef); | |
$scope.opts = { | |
columnDefs: [ | |
{name: '$id', displayName: 'ID'}, |