本文整理汇总了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);
});
}
});