26
loading...
This website collects cookies to deliver better user experience
MyFavouritesOfflineApp
, which handles his favorite movies and books. So we have two main Firebase/Firestore collections: books and movies.await
expression will not be complete until the document write has been successful on the server. This will block your UI even when the changes are made in the cache.const user = {
id:1,
name:blarz
};
const userResponse = await FirebaseService.Collection.User().add(user);
const user = {
id:1,
name:blarz
};
const userRef = FirebaseService.Collection.User().add(user)
.then(docRef => {
console.log(`The user with id ${docRef.id} was added succcesfully`);
}).catch(error=>console.log('There was an error adding a user', error))
async addUser(user: User):Promise<User> {
const { id, ...data } = user;
const result = await FirebaseService.Collection.User().add(data);
user.id = result.id;
return user;
}
await
expression, the code looks like the following:async addUser(user: User):Promise<User> {
const { id, ...data } = user;
const userRef = FirebaseService.Collection.User().doc();
user.id = userRef.id;
userRef
.set(data)
.then(() => console.log(`The user was created successfully`))
.catch((error) =>
console.log('There was an error adding the user', error)
);
return user;
}