LearnTeachCode / pair-partners

A web app that helps people find study partners for virtual pair programming and collaboration
http://learnteachcode.org/pair-partners/
38 stars 16 forks source link

Up for grabs: Create an example of the Firebase "key" property #54

Open LearningNerd opened 7 years ago

LearningNerd commented 7 years ago

⭐️ This challenge is up for grabs! Claim it by clicking "assign yourself" on the right, under the "Assignees" section for this GitHub issue! You can work on this by yourself or in pairs.

✔️ To complete this challenge: Post a comment at the bottom of this page with some instructions and sample code, so the rest of our team can learn how to use this new Firebase property by reading your comment!

You can edit your comment at any point to update your answer, so you don't have to do these all at once! To edit your comment after you publish it, click the pencil icon in the top right corner of your comment: github-edit-comments

If you have any questions, please post a comment at the bottom of this page! (You can also ask us on Slack, but please post a comment here too so we can more easily reference it later.)

About the Firebase key property

📚 Official documentation: Firebase API section on the key property

Every database Reference object in Firebase has a key, except for the root of the database.

Your challenge

🏆 The goal: learn how this property works, test it out for yourself, and then post a comment at the bottom of this page with some instructions and sample code to help teach the rest of our team!

Questions to keep in mind:

kammitama5 commented 7 years ago

The key can be null or non-null The key is used for accessing data at the end of the path. You can find it by accessing the last item after the last "/"

for example,

var dbRef = firebase.database().ref("path/key");

Here, your key would be "key";

If you have no key (ie the reference is null), it would look like :

var dbRef = firebase.database().ref();
LearningNerd commented 7 years ago

Great start @kammitama5! Try refining this description and the example code some more when you have a chance -- right now your example isn't actually use the key property. For example, see the sample code in the official documentation:

// The key of any non-root reference is the last token in the path
var adaRef = firebase.database().ref("users/ada");
var key = adaRef.key;  // key === "ada"
key = adaRef.child("name/last").key;  // key === "last"

So the key property is used in adaRef.key to get the key (or path) of that database location, which is the string "ada" in this case.