Filip Petkovski
account.signUp({
username: 'Filip',
password: 'NoPassword',
customFields: {...}
})
.then ( sayWelcome )
.fail ( failGracefully );
products.add({
name: 'Coke',
description: 'Sugar in a can',
price: '$4.99'
})
.then ( ... )
.fail ( ... );
// Push data
app.child('products').push({
name: ...,
description: ...,
price: ...,
owner: ...
}, callback);
// Set data
var id = 'some-id';
app.child('products').child(id).set({
...
}, callback);
// Update data
app.child('products').child(id).update({...}, callback);
...
<script src="https://cdn.firebase.com/js/client/1.0.24/firebase.js"></script>
...
// Firebase root handler
var app = new Firebase("https://best-app-ever.firebaseio.com");
var app = new Firebase("https://best-app-ever.firebaseio.com");
// Read data once:
app.child('products').once('value', function (snapshot) {
var data = snapshot.val();
// process data
});
// On value changed:
app.child('products').on('value', function (snapshot) {
var data = snapshot.val();
// process data
});
// On child added:
app.child('products').on('child_added', function (snapshot) {
var childAdded = snapshot.val();
// ...
});
// On child removed:
app.child('products').on('child_removed', function (snapshot) {
var removedChild = snapshot.val();
// ...
});
app.child('products/5/price').transaction(function (current) {
if (current < 10) {
return 0;
} else {
return 20;
}
});
var authClient = new FirebaseSimpleLogin(app, function(error, user) {
if (error) {
// an error occurred while attempting login
} else if (user) {
// user authenticated with Firebase
} else {
// user is logged out
}
});
authClient.login('password', {
email: '<email@domain.com>',
password: '<password>'
});
{
"rules": {
"products": {
"$product_id": {
".read": true,
".write": "auth.email == data.child('owner').val()",
".validate": "newData.hasChildren(['name', 'price'])",
"price": {
".validate": newData.isNumber() && newData.val() > 0
},
"name": {
".validate": !newData.exists()
}
}
}
}
}
$ git clone https://github.com/deployd/deployd.git
$ npm install
$ npm link
$ dpd create best-app-ever
$ cd best-app-ever
$ dpd
starting deployd v0.6.10...
deployd v0.7.0 is available.
listening on port 2403
type help for a list of commands
dpd >
Server side event handlers:
Text
https://github.com/fpetkovski/webcampzg2014