mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-08-27 11:40:08 +08:00
Merge pull request #1680 from thSoft/patch-1
Preliminary version of AngularFire definition
This commit is contained in:
@@ -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))
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
/// <reference path="angularfire.d.ts"/>
|
||||
|
||||
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(_ => {
|
||||
});
|
||||
}
|
||||
]);
|
||||
Vendored
+41
@@ -0,0 +1,41 @@
|
||||
// Type definitions for AngularFire 0.6.0
|
||||
// Project: http://angularfire.com
|
||||
// Definitions by: Dénes Harmath <http://github.com/thSoft>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
/// <reference path="../angularjs/angular.d.ts"/>
|
||||
/// <reference path="../firebase/firebase.d.ts"/>
|
||||
|
||||
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<any>;
|
||||
}
|
||||
|
||||
interface AngularFireObject {
|
||||
$priority: number;
|
||||
}
|
||||
|
||||
interface AngularFireAuthService {
|
||||
(firebase: Firebase): AngularFireAuth;
|
||||
}
|
||||
|
||||
interface AngularFireAuth {
|
||||
$getCurrentUser(): ng.IPromise<any>;
|
||||
$login(provider: string, options?: Object): ng.IPromise<any>;
|
||||
$logout(): void;
|
||||
$createUser(email: string, password: string, noLogin?: boolean): 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>;
|
||||
}
|
||||
Vendored
+1
-1
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user