Skip to content

Instantly share code, notes, and snippets.

@mchampaneri
Last active October 10, 2020 05:32
Show Gist options
  • Save mchampaneri/a6cf58e119c71e990d721a490765f52a to your computer and use it in GitHub Desktop.
Save mchampaneri/a6cf58e119c71e990d721a490765f52a to your computer and use it in GitHub Desktop.
Using OrderdMap from immutable.js with firebase javascript example.
const { OrderedMap } = require('immutable');
var documentMap = OrderedMap()
const messageListner = () => {
let unsubscribe = database
.collection('documents')
.orderBy('created_at', 'asc')
.limitToLast(10)
.onSnapshot(async (snap) => {
for (let msg of snap.docs) {
documentMap = documentMap.set(msg.data().created_at, msg.data())
}
}, (err) => {
unsubscribe();
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment