本文整理匯總了TypeScript中firebase.child函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript child函數的具體用法?TypeScript child怎麽用?TypeScript child使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了child函數的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: startWatching
startWatching() {
this.movesRef = this.rootRef.child('moves')
this.actionRef = this.rootRef.child('action')
this.actionRef.on('value', onlineSnap => {
const val = onlineSnap.val()
if (val == null) {
this.resetGame()
return
}
switch (val.action) {
case Action.PUT:
console.log(val)
const stone: Stone = val.playerId + 1
if (this.board.turn == stone &&
this.board.canPut(val.x, val.y, stone)) {
this.movesRef.push({x: val.x, y: val.y, stone})
this.board.putStone(val.x, val.y, stone)
if (this.board.gameOver) {
this.finishGame()
}
}
break
}
})
console.log('Start watching...')
}
示例2: resetGame
resetGame() {
console.log('Reset game')
this.board = new Board()
this.board.startGame(0)
this.rootRef.child('action').remove()
this.rootRef.child('moves').remove()
}
示例3: Promise
return new Promise((resolve, reject) => {
if (!keyExists(key)) return reject();
this.ref.child(key).remove((error) => {
if (error) reject(error);
else resolve();
});
});
示例4: getItems
getItems():Promise<Array<any>> {
let promise:Promise<Array<any>>;
this.firebaseRef.child("/").on("value", function(snapshot) {
let items = [];
items.push(snapshot.val());
// items.push(new ProductModel("Maggara"));
});
return promise;
}
示例5:
export const clearCompleted = ({user, tab}: ActionContext) => (dispatch) => {
let tasks = dbRoot.child(`${user.userId}/${getTabProp(tab)}`);
tasks.once('value', snapshot => {
snapshot.forEach(todo => {
const { completed } = todo.val() as Todo;
if (completed) {
tasks.child(todo.key()).remove();
}
})
});
};
示例6: next
next() {
let category = "cat" + Math.floor((Math.random() * 3) + 1);
let id = "id" + Math.floor((Math.random() * 10) + 2001);
let name = "Joe" + Math.floor((Math.random() * 900) + 1001);
let score = Math.floor((Math.random() * 100) + 1);
this.ref.child(category).child(id).set({
name: name,
score: score,
present: score>2
});
}
示例7: User
query.then((users: Map<string, any>) => {
if (users.size) {
// Found the user.
// Check if providers contains the current `auth.provider` and update the user providers if it does not contain it.
let {key, providers} = Array.from(users.values())[0];
if (Array.isArray(providers) && providers.includes(auth.provider)) resolve(
new User({key, email, providers})
);
else {
let firebaseUserProvidersRef = firebaseUsersRef.child(key).child('providers');
let observable = new FirebaseQueryObservable(firebaseUserProvidersRef, [
FirebaseQueryEventType.Value
]);
let first = true;
let subscription = observable.subscribe((event: FirebaseQueryEvent) => {
if (first) first = false;
else {
let user = new User({key, email, providers: event.data.val()});
subscription.unsubscribe();
resolve(user);
}
});
firebaseUserProvidersRef.set(
Array.isArray(providers)
? providers.concat([auth.provider])
: [auth.provider]
);
}
} else {
// Could not find the user.
// If no user could be found we need to create one.
// After user is saved, resolve the promise with the newly created user.
let providers = [auth.provider];
usersArray.add({email, providers}).then((ref: Firebase) => {
let key = ref.key();
let firebaseUserKeyRef = ref.child('key');
let observable = new FirebaseQueryObservable(firebaseUserKeyRef, [
FirebaseQueryEventType.Value
]);
let first = true;
let subscription = observable.subscribe(() => {
if (first) first = false;
else {
let user = new User({email, providers, key});
subscription.unsubscribe();
resolve(user);
}
});
firebaseUserKeyRef.set(key);
});
}
});