mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-09-09 11:13:57 +08:00
テストコードの更新途中
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
var myapp = angular.module("myapp", ["firebase"]);
|
||||
|
||||
interface AngularFireScope extends ng.IScope {
|
||||
items: AngularFire;
|
||||
items: AngularFireArray;
|
||||
remoteItems: RemoteItems;
|
||||
}
|
||||
|
||||
@@ -14,23 +14,46 @@ interface RemoteItems {
|
||||
var url = "https://myapp.firebaseio.com";
|
||||
|
||||
myapp.controller("MyController", ["$scope", "$firebase",
|
||||
function($scope: AngularFireScope, $firebase: AngularFireService) {
|
||||
$scope.items = $firebase(new Firebase(url));
|
||||
function ($scope: AngularFireScope, $firebase: AngularFireService) {
|
||||
var sync = $firebase(new Firebase(url));
|
||||
|
||||
sync.$asArray()
|
||||
.$loaded()
|
||||
.then(function (list: AngularFireArray) {
|
||||
console.log("list has " + list.length + " items");
|
||||
|
||||
list.$add({ foo: "bar" }).then(function (ref) {
|
||||
ref.on("value", function (snapshot) {
|
||||
if (snapshot.val().foo !== "bar") throw "error";
|
||||
});
|
||||
});
|
||||
|
||||
var item = list.$getRecord("foo");
|
||||
list.$remove("foo");
|
||||
list.$remove(0);
|
||||
list.$save();
|
||||
});
|
||||
sync.$asObject()
|
||||
|
||||
|
||||
$scope.items = sync.$asArray();
|
||||
$scope.object = sync.$asObject();
|
||||
|
||||
$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" });
|
||||
$scope.items.$set({ bar: "baz" });
|
||||
var keys = $scope.items.$getIndex();
|
||||
keys.forEach(function(key, i) {
|
||||
keys.forEach(function (key, i) {
|
||||
console.log(i, (<any>$scope.items)[key]);
|
||||
});
|
||||
$scope.items.$on("loaded", function() {
|
||||
$scope.items.$on("loaded", function () {
|
||||
console.log("Initial data received!");
|
||||
});
|
||||
$scope.items.$on("change", function() {
|
||||
$scope.items.$on("change", function () {
|
||||
console.log("A remote change was applied locally!");
|
||||
});
|
||||
$scope.items.$off('loaded');
|
||||
@@ -39,7 +62,7 @@ myapp.controller("MyController", ["$scope", "$firebase",
|
||||
}
|
||||
$scope.items.$bind($scope, "remoteItems");
|
||||
$scope.remoteItems.bar = "foo";
|
||||
$scope.items.$bind($scope, "remote").then(function(unbind) {
|
||||
$scope.items.$bind($scope, "remote").then(function (unbind) {
|
||||
unbind();
|
||||
$scope.remoteItems.bar = "foo";
|
||||
});
|
||||
@@ -55,7 +78,7 @@ interface AngularFireAuthScope extends ng.IScope {
|
||||
}
|
||||
|
||||
myapp.controller("MyAuthController", ["$scope", "$firebaseSimpleLogin",
|
||||
function($scope: AngularFireAuthScope, $firebaseSimpleLogin: AngularFireAuthService) {
|
||||
function ($scope: AngularFireAuthScope, $firebaseSimpleLogin: AngularFireAuthService) {
|
||||
var dataRef = new Firebase(url);
|
||||
$scope.loginObj = $firebaseSimpleLogin(dataRef);
|
||||
$scope.loginObj.$getCurrentUser().then(_ => {
|
||||
@@ -65,9 +88,9 @@ myapp.controller("MyAuthController", ["$scope", "$firebaseSimpleLogin",
|
||||
$scope.loginObj.$login('password', {
|
||||
email: email,
|
||||
password: password
|
||||
}).then(function(user) {
|
||||
}).then(function (user) {
|
||||
console.log('Logged in as: ', user.uid);
|
||||
}, function(error) {
|
||||
}, function (error) {
|
||||
console.error('Login failed: ', error);
|
||||
});
|
||||
$scope.loginObj.$logout();
|
||||
|
||||
Vendored
+40
-12
@@ -1,4 +1,4 @@
|
||||
// Type definitions for AngularFire 0.6.0
|
||||
// Type definitions for AngularFire 0.8.2 and Firebase Simple Login 1.6.4
|
||||
// Project: http://angularfire.com
|
||||
// Definitions by: Dénes Harmath <http://github.com/thSoft>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
@@ -7,25 +7,53 @@
|
||||
/// <reference path="../firebase/firebase.d.ts"/>
|
||||
|
||||
interface AngularFireService {
|
||||
(firebase: Firebase): AngularFire;
|
||||
(firebase: Firebase, config?:any): 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>;
|
||||
$asArray(): AngularFireArray;
|
||||
$asObject(): AngularFireObject;
|
||||
$ref(): Firebase;
|
||||
$push(data: any): ng.IPromise<Firebase>;
|
||||
$set(key: string, data: any): ng.IPromise<Firebase>;
|
||||
$set(data: any): ng.IPromise<Firebase>;
|
||||
$remove(key?: string): ng.IPromise<Firebase>;
|
||||
$update(key: string, data: any): ng.IPromise<Firebase>;
|
||||
$update(data: any): ng.IPromise<Firebase>;
|
||||
$transaction(updateFn: (currentData: any) => any, applyLocally?: boolean): ng.IPromise<IFirebaseDataSnapshot>;
|
||||
}
|
||||
|
||||
interface AngularFireObject {
|
||||
$id: string;
|
||||
$priority: number;
|
||||
$value: any;
|
||||
$save(): ng.IPromise<Firebase>;
|
||||
$loaded(): ng.IPromise<AngularFireObject>;
|
||||
$inst(): Firebase;
|
||||
$bindTo(scope: ng.IScope, varName: string): ng.IPromise<any>;
|
||||
$watch(callback: Function, context: any): Function;
|
||||
$destroy(): void;
|
||||
|
||||
$extendFactory(ChildClass: Object, methods?: Object);
|
||||
}
|
||||
|
||||
interface AngularFireArray extends Array<any> {
|
||||
$add(newData: any): ng.IPromise<Firebase>;
|
||||
$save(recordOrIndex: any): ng.IPromise<Firebase>;
|
||||
$remove(recordOrIndex: any): ng.IPromise<Firebase>;
|
||||
$getRecord(key: string): any;
|
||||
$keyAt(recordOrIndex: any): string;
|
||||
$indexFor(key: string): number;
|
||||
$loaded(): ng.IPromise<AngularFireArray>;
|
||||
$inst(): Firebase;
|
||||
$watch(cb: (event: string, key: string, prevChild: string) => void, context?: any): Function;
|
||||
$destroy(): void;
|
||||
|
||||
$extendFactory(ChildClass:Object, methods?:Object);
|
||||
}
|
||||
|
||||
|
||||
|
||||
interface AngularFireAuthService {
|
||||
(firebase: Firebase): AngularFireAuth;
|
||||
}
|
||||
@@ -34,7 +62,7 @@ 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>;
|
||||
$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>;
|
||||
|
||||
Reference in New Issue
Block a user