Geep5

Real-time example

Aug 29th, 2020
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. <script>
  2. export let name;
  3.  
  4. import firebase from "firebase/app";
  5. import "firebase/database";
  6. let firebaseConfig = {
  7. // Insert Firebase Credentials here
  8. apiKey: "AIzaSyAQoaJeiL0051YuJWEwxhePEUpaFXOVwgc",
  9. authDomain: "spell-party.firebaseapp.com",
  10. databaseURL: "https://spell-party.firebaseio.com",
  11. projectId: "spell-party",
  12. storageBucket: "spell-party.appspot.com",
  13. messagingSenderId: "649504032254",
  14. appId: "1:649504032254:web:c7dc2d2a2815d7ee2bacaf"
  15. };
  16. firebase.initializeApp(firebaseConfig);
  17.  
  18. // let db = firebase.database().ref().child('object');
  19.  
  20.  
  21. // function writeUserData(userId, name, email, imageUrl) {
  22. firebase.database().ref('users/' + 'player1').set({
  23. health : 55,
  24. cast : 85,
  25. spell : 'Rectify',
  26. color : '#FF0000'
  27. });
  28. // }
  29.  
  30.  
  31. // let cast = firebase.database().ref('users/player1/cast');
  32. // let health
  33. // cast.on('value', function(snapshot) {
  34. // console.log('snapshot', snapshot.val())
  35. // health = snapshot.val()
  36. // });
  37.  
  38. let players = firebase.database().ref('users/');
  39.  
  40. let playerlist = []
  41. players.on('value', function(snapshot) {
  42. playerlist = Object.values(snapshot.val())
  43. console.log('playerlist', playerlist);
  44. });
  45.  
  46.  
  47. </script>
  48.  
  49. <main>
  50.  
  51.  
  52. {#each playerlist as banana}
  53. {banana.health}
  54. {/each}
  55.  
  56.  
  57. players
  58.  
  59. <!-- {#each {length: 5} as _, i} -->
  60. <!-- {/each} -->
  61.  
  62. </main>
  63.  
  64. <style>
  65. </style>
Add Comment
Please, Sign In to add comment