MCPcopy Create free account
hub / github.com/firebase/quickstart-js / toggleStar

Function toggleStar

database/scripts/main.ts:154–170  ·  view source on GitHub ↗

* Star/unstar post.

(postRef: DatabaseReference, uid: string)

Source from the content-addressed store, hash-verified

152 * Star/unstar post.
153 */
154function toggleStar(postRef: DatabaseReference, uid: string) {
155 runTransaction(postRef, function (post) {
156 if (post) {
157 if (post.stars && post.stars[uid]) {
158 post.starCount--;
159 post.stars[uid] = null;
160 } else {
161 post.starCount++;
162 if (!post.stars) {
163 post.stars = {};
164 }
165 post.stars[uid] = true;
166 }
167 }
168 return post;
169 });
170}
171
172/**
173 * Creates a post element.

Callers 1

onStarClickedFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected