diff --git a/README.md b/README.md index 251263010..317c27f0c 100755 --- a/README.md +++ b/README.md @@ -30,6 +30,7 @@ List of Definitions * [Ace Cloud9 Editor](http://ace.ajax.org/) (by [Diullei Gomes](https://github.com/Diullei)) * [Add To Home Screen] (http://cubiq.org/add-to-home-screen) (by [James Wilkins] (http://www.codeplex.com/site/users/view/jamesnw)) * [AmCharts](http://www.amcharts.com/) (by [Covobonomo](https://github.com/covobonomo/)) +* [AngularFire](https://www.firebase.com/docs/angular/reference.html) (by [Dénes Harmath](https://github.com/thSoft)) * [AngularJS](http://angularjs.org) (by [Diego Vilar](https://github.com/diegovilar)) ([wiki](https://github.com/borisyankov/DefinitelyTyped/wiki/AngularJS-Definitions-Usage-Notes)) * [AngularUI](http://angular-ui.github.io/) (by [Michel Salib](https://github.com/michelsalib)) * [Angular Protractor](https://github.com/angular/protractor) (by [Bill Armstrong](https://github.com/BillArmstrong)) diff --git a/angularfire/angularfire-tests.ts b/angularfire/angularfire-tests.ts new file mode 100644 index 000000000..e3a04712c --- /dev/null +++ b/angularfire/angularfire-tests.ts @@ -0,0 +1,83 @@ +/// + +var myapp = angular.module("myapp", ["firebase"]); + +interface AngularFireScope extends ng.IScope { + items: AngularFire; + remoteItems: RemoteItems; +} + +interface RemoteItems { + bar: string; +} + +var url = "https://myapp.firebaseio.com"; + +myapp.controller("MyController", ["$scope", "$firebase", + function($scope: AngularFireScope, $firebase: AngularFireService) { + $scope.items = $firebase(new Firebase(url)); + $scope.items.$add({ foo: "bar" }); + $scope.items.$remove("foo"); + $scope.items.$remove(); + $scope.items.$save(); + var child = $scope.items.$child("foo"); + child.$remove(); + $scope.items.$set({ bar: "baz" }); + var keys = $scope.items.$getIndex(); + keys.forEach(function(key, i) { + console.log(i, $scope.items[key]); + }); + $scope.items.$on("loaded", function() { + console.log("Initial data received!"); + }); + $scope.items.$on("change", function() { + console.log("A remote change was applied locally!"); + }); + $scope.items.$off('loaded'); + function stopSync() { + $scope.items.$off(); + } + $scope.items.$bind($scope, "remoteItems"); + $scope.remoteItems.bar = "foo"; + $scope.items.$bind($scope, "remote").then(function(unbind) { + unbind(); + $scope.remoteItems.bar = "foo"; + }); + } +]); + +var foo: AngularFireObject = { + $priority: 0 +}; + +interface AngularFireAuthScope extends ng.IScope { + loginObj: AngularFireAuth; +} + +myapp.controller("MyAuthController", ["$scope", "$firebaseSimpleLogin", + function($scope: AngularFireAuthScope, $firebaseSimpleLogin: 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(_ => { + }); + } +]); \ No newline at end of file diff --git a/angularfire/angularfire.d.ts b/angularfire/angularfire.d.ts new file mode 100644 index 000000000..3f2b0aa10 --- /dev/null +++ b/angularfire/angularfire.d.ts @@ -0,0 +1,41 @@ +// Type definitions for AngularFire 0.6.0 +// Project: http://angularfire.com +// Definitions by: Dénes Harmath +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// +/// + +interface AngularFireService { + (firebase: Firebase): AngularFire; +} + +interface AngularFire { + $add(value: any): void; + $remove(key?: string): void; + $save(key?: string): void; + $child(key: string): AngularFire; + $set(value: any): void; + $getIndex(): string[]; + $on(eventType: string, callback: (dataSnapshot: IFirebaseDataSnapshot, prevChildName?: string) => void, cancelCallback?: ()=> void, context?: Object): (dataSnapshot: IFirebaseDataSnapshot, prevChildName?: string) => void; + $off(eventType?: string, callback?: (dataSnapshot: IFirebaseDataSnapshot, prevChildName?: string) => void, cancelCallback?: ()=> void, context?: Object): (dataSnapshot: IFirebaseDataSnapshot, prevChildName?: string) => void; + $bind($scope: ng.IScope, modelName: string): ng.IPromise; +} + +interface AngularFireObject { + $priority: number; +} + +interface AngularFireAuthService { + (firebase: Firebase): AngularFireAuth; +} + +interface AngularFireAuth { + $getCurrentUser(): ng.IPromise; + $login(provider: string, options?: Object): ng.IPromise; + $logout(): void; + $createUser(email: string, password: string, noLogin?: boolean): ng.IPromise; + $changePassword(email: string, oldPassword: string, newPassword: string): ng.IPromise; + $removeUser(email: string, password: string): ng.IPromise; + $sendPasswordResetEmail(email: string): ng.IPromise; +} diff --git a/firebase/firebase.d.ts b/firebase/firebase.d.ts index 83f9ca84b..bac32fbc6 100644 --- a/firebase/firebase.d.ts +++ b/firebase/firebase.d.ts @@ -53,7 +53,7 @@ declare class Firebase implements IFirebaseQuery { toString(): string; set(value: any, onComplete?: (error: any) => void): void; update(value: any, onComplete?: (error: any) => void): void; - remove(onComplete?: (error: any) => void); + remove(onComplete?: (error: any) => void): void; push(value: any, onComplete?: (error: any) => void): Firebase; setWithPriority(value: any, priority: string, onComplete?: (error: any) => void): void; setWithPriority(value: any, priority: number, onComplete?: (error: any) => void): void;