firebase
うおおおおおおつかいづれえええ
code: index.js
const db = firebase.database()
//シングルトンのオブジェクトを同期する
const userRef = db.ref('users/taro')
userRef.on('value', (snapshot) =>{
var val = snapshot.val()
});
//起動時に読みたいだけ
ref.once("value");
//配列を同期する
const ref = db.ref("messages")
ref.on("child_added", option.onChildAdded)
onChildAdded: (item)=>{
//1件読み込んだら呼ばれる
let post = item.val()
post.key = item.key
this.messages.push(post)
this.scrollBottom()
}
//クラスでwrap
export class SeminarAppModel{
constructor(option){
this.app = firebase.initializeApp(config);
this.ref = this.app.database().ref("messages")
this.ref.on("child_added", option.onChildAdded)
}
add(obj){
this.ref.push(obj)
}
remove(id){
this.ref.child(id).remove()
}
}
this.ref.update({
onlineState: true,
});
this.ref.onDisconnect().update({
onlineState: false,
});