Update angularfire / firebase.

This commit is contained in:
Arnaud Bosc
2015-05-01 19:23:19 +02:00
parent 1400e07731
commit dd82479470
3 changed files with 99 additions and 47 deletions

View File

@@ -62,8 +62,8 @@ myapp.controller("MyController", ["$scope", "$firebase", '$FirebaseObject', '$Fi
obj.$save();
});
// $inst()
if (obj.$inst() !== sync) throw "error";
// $ref()
if (obj.$ref() !== sync) throw "error";
// $bindTo()
obj.$bindTo($scope, "data").then(function () {
@@ -81,8 +81,8 @@ myapp.controller("MyController", ["$scope", "$firebase", '$FirebaseObject', '$Fi
// $destroy()
obj.$destroy();
// $extendFactory()
var NewFactory = $FirebaseObject.$extendFactory({
// $extend()
var NewFactory = $FirebaseObject.$extend({
getMyFavoriteColor: function () {
return this.favoriteColor + ", no green!"; // obscure Monty Python reference
}
@@ -94,8 +94,8 @@ myapp.controller("MyController", ["$scope", "$firebase", '$FirebaseObject', '$Fi
{
var list = sync.$asArray();
// $inst()
if (list.$inst() !== sync) throw "error";
// $ref()
if (list.$ref() !== sync) throw "error";
// $add()
list.$add({ foo: "foo value" });
@@ -145,8 +145,8 @@ myapp.controller("MyController", ["$scope", "$firebase", '$FirebaseObject', '$Fi
// $destroy()
list.$destroy();
// $extendFactory()
var ArrayWithSum = $FirebaseArray.$extendFactory({
// $extend()
var ArrayWithSum = $FirebaseArray.$extend({
sum: function () {
var total = 0;
angular.forEach(this.$list, function (rec) {
@@ -167,30 +167,43 @@ interface AngularFireAuthScope extends ng.IScope {
loginObj: AngularFireAuth;
}
myapp.controller("MyAuthController", ["$scope", "$firebaseSimpleLogin",
function($scope: AngularFireAuthScope, $firebaseSimpleLogin: AngularFireAuthService) {
myapp.controller("MyAuthController", ["$scope", "$firebaseAuth",
function($scope: AngularFireAuthScope, $firebaseAuth: AngularFireAuthService) {
var dataRef = new Firebase(url);
$scope.loginObj = $firebaseSimpleLogin(dataRef);
$scope.loginObj.$getCurrentUser().then(_ => {
});
var email = 'my@email.com';
var password = 'mypassword';
$scope.loginObj.$login('password', {
email: email,
password: password
}).then(function(user) {
console.log('Logged in as: ', user.uid);
}, function(error) {
console.error('Login failed: ', error);
});
$scope.loginObj.$logout();
$scope.loginObj.$createUser(email, password).then(_ => {
});
$scope.loginObj.$changePassword(email, password, password).then(_ => {
});
$scope.loginObj.$removeUser(email, password).then(_ => {
});
$scope.loginObj.$sendPasswordResetEmail(email).then(_ => {
});
$scope.loginObj = $firebaseAuth(dataRef);
$scope.loginObj.$getAuth();
var credentials = {
email: 'my@email.com',
password: 'mypassword'
};
var resetPasswordCredentials = {
email: 'my@email.com'
};
var changePasswordCredentials = {
email: 'my@email.com',
oldPassword: 'mypassword',
newPassword: 'mypassword'
};
var changeUserCredentials = {
oldEmail: 'my@email.com',
newEmail: 'my@email.com',
password: 'mypassword'
};
$scope.loginObj.$authWithCustomToken("token").then(_ => {});
$scope.loginObj.$authAnonymously().then(_ => {});
$scope.loginObj.$authWithPassword(credentials).then(_ => {});
$scope.loginObj.$authWithOAuthPopup("github").then(_ => {});
$scope.loginObj.$authWithOAuthRedirect("google").then(_ => {});
$scope.loginObj.$authWithOAuthToken("twitter", "token").then(_ => {});
$scope.loginObj.$getAuth();
$scope.loginObj.$onAuth(() => {});
$scope.loginObj.$unauth();
$scope.loginObj.$waitForAuth();
$scope.loginObj.$requireAuth();
$scope.loginObj.$createUser(credentials).then(_ => {});
$scope.loginObj.$removeUser(credentials).then(_ => {});
$scope.loginObj.$changeEmail(changeUserCredentials).then(_ => {});
$scope.loginObj.$changePassword(changePasswordCredentials).then(_ => {});
$scope.loginObj.$resetPassword(resetPasswordCredentials).then(_ => {});
}
]);
]);

View File

@@ -28,17 +28,18 @@ interface AngularFireObject extends AngularFireSimpleObject {
$id: string;
$priority: number;
$value: any;
$remove(): ng.IPromise<Firebase>;
$save(): ng.IPromise<Firebase>;
$loaded(resolve?: (x: AngularFireObject) => ng.IHttpPromise<{}>, reject?: (err: any) => any): ng.IPromise<AngularFireObject>;
$loaded(resolve?: (x: AngularFireObject) => ng.IPromise<{}>, reject?: (err: any) => any): ng.IPromise<AngularFireObject>;
$loaded(resolve?: (x: AngularFireObject) => void, reject?: (err: any) => any): ng.IPromise<AngularFireObject>;
$inst(): AngularFire;
$ref(): AngularFire;
$bindTo(scope: ng.IScope, varName: string): ng.IPromise<any>;
$watch(callback: Function, context?: any): Function;
$destroy(): void;
}
interface AngularFireObjectService {
$extendFactory(ChildClass: Object, methods?: Object): Object;
$extend(ChildClass: Object, methods?: Object): Object;
}
interface AngularFireArray extends Array<AngularFireSimpleObject> {
@@ -51,12 +52,12 @@ interface AngularFireArray extends Array<AngularFireSimpleObject> {
$loaded(resolve?: (x: AngularFireArray) => ng.IHttpPromise<{}>, reject?: (err: any) => any): ng.IPromise<AngularFireArray>;
$loaded(resolve?: (x: AngularFireArray) => ng.IPromise<{}>, reject?: (err: any) => any): ng.IPromise<AngularFireArray>;
$loaded(resolve?: (x: AngularFireArray) => void, reject?: (err: any) => any): ng.IPromise<AngularFireArray>;
$inst(): AngularFire;
$ref(): AngularFire;
$watch(cb: (event: string, key: string, prevChild: string) => void, context?: any): Function;
$destroy(): void;
}
interface AngularFireArrayService {
$extendFactory(ChildClass: Object, methods?: Object): Object;
$extend(ChildClass: Object, methods?: Object): Object;
}
interface AngularFireSimpleObject {
@@ -72,11 +73,20 @@ interface AngularFireAuthService {
}
interface AngularFireAuth {
$getCurrentUser(): ng.IPromise<any>;
$login(provider: string, options?: Object): ng.IPromise<any>;
$logout(): void;
$createUser(email: string, password: string): ng.IPromise<any>;
$changePassword(email: string, oldPassword: string, newPassword: string): ng.IPromise<any>;
$removeUser(email: string, password: string): ng.IPromise<any>;
$sendPasswordResetEmail(email: string): ng.IPromise<any>;
$authWithCustomToken(authToken: string, options?: Object): ng.IPromise<any>;
$authAnonymously(options?: Object): ng.IPromise<any>;
$authWithPassword(credentials: FirebaseCredentials, options?: Object): ng.IPromise<any>;
$authWithOAuthPopup(provider: string, options?: Object): ng.IPromise<any>;
$authWithOAuthRedirect(provider: string, options?: Object): ng.IPromise<any>;
$authWithOAuthToken(provider: string, credentials: Object|string, options?: Object): ng.IPromise<any>;
$getAuth(): FirebaseAuthData;
$onAuth(callback: Function, context?: any): Function;
$unauth(): void;
$waitForAuth(): ng.IPromise<any>;
$requireAuth(): ng.IPromise<any>;
$createUser(credentials: FirebaseCredentials): ng.IPromise<any>;
$removeUser(credentials: FirebaseCredentials): ng.IPromise<any>;
$changeEmail(credentials: FirebaseNewUserCredentials): ng.IPromise<any>;
$changePassword(credentials: FirebaseNewPasswordCredentials): ng.IPromise<any>;
$resetPassword(credentials: FirebaseResetPasswordCredentials): ng.IPromise<any>;
}

View File

@@ -9,6 +9,11 @@ interface FirebaseAuthResult {
}
interface FirebaseDataSnapshot {
/**
* Returns true if this DataSnapshot contains any data.
* It is slightly more efficient than using snapshot.val() !== null.
*/
exists(): boolean;
/**
* Gets the JavaScript object representation of the DataSnapshot.
*/
@@ -108,6 +113,10 @@ interface FirebaseQuery {
* Generates a new Query object ordered by key name.
*/
orderByKey(): FirebaseQuery;
/**
* Generates a new Query object ordered by child values.
*/
orderByValue(): FirebaseQuery;
/**
* Generates a new Query object ordered by priority.
*/
@@ -255,10 +264,14 @@ interface Firebase extends FirebaseQuery {
* Creates a new user account using an email / password combination.
*/
createUser(credentials: FirebaseCredentials, onComplete: (error: any) => void): void;
/**
* Updates the email associated with an email / password user account.
*/
changeEmail(credentials: FirebaseNewUserCredentials, onComplete: (error: any) => void): void;
/**
* Change the password of an existing user using an email / password combination.
*/
changePassword(credentials: { email: string; oldPassword: string; newPassword: string }, onComplete: (error: any) => void): void;
changePassword(credentials: FirebaseNewPasswordCredentials, onComplete: (error: any) => void): void;
/**
* Removes an existing user account using an email / password combination.
*/
@@ -266,7 +279,7 @@ interface Firebase extends FirebaseQuery {
/**
* Sends a password-reset email to the owner of the account, containing a token that may be used to authenticate and change the user password.
*/
resetPassword(credentials: { email: string }, onComplete: (error: any) => void): void;
resetPassword(credentials: FirebaseResetPasswordCredentials, onComplete: (error: any) => void): void;
onDisconnect(): FirebaseOnDisconnect;
}
interface FirebaseStatic {
@@ -305,4 +318,20 @@ interface FirebaseAuthData {
interface FirebaseCredentials {
email: string;
password: string;
}
}
interface FirebaseNewPasswordCredentials {
email: string;
oldPassword: string;
newPassword: string;
}
interface FirebaseNewUserCredentials {
oldEmail: string;
newEmail: string;
password: string;
}
interface FirebaseResetPasswordCredentials {
email: string;
}