From e65d4bc00585d693a9fc0a9ba4daaf8fe1bfc717 Mon Sep 17 00:00:00 2001 From: PeterHdd Date: Wed, 5 Sep 2018 11:37:09 +0300 Subject: [PATCH] added more firestore commands --- README.md | 6 +++++- snippets/snippets.json | 34 +++++++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 00e4564..bd62f09 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ ## VS Code Firebase and Firestore snippets ------------------- [![Version](https://vsmarketplacebadge.apphb.com/version/peterhdd.firebase-firestore-snippets.svg)](https://marketplace.visualstudio.com/items?itemName=peterhdd.firebase-firestore-snippets) +[![Installs](https://vsmarketplacebadge.apphb.com/installs/peterhdd.firebase-firestore-snippets.svg)](https://marketplace.visualstudio.com/items?itemName=peterhdd.firebase-firestore-snippets) ## Supported Languages * JavaScript (.js) @@ -59,7 +60,7 @@ | `firedeleteuser` | Delete a user account with the delete method | | `firesignout` | Sign out the user | | `firegoogleinstance` | Get instance of the google provider | -| `fireprovidersignin` | eSign in with google | +| `fireprovidersignin` | Sign in with google | | `firefacebookinstance` | Get instance of facebook provider | | `firetwitterinstance` | Get instance of twitter provider | | `firegithubinstance` | Get instance of github provider | @@ -71,12 +72,15 @@ | -------: | ------- | | `initializefirestore` | Initialize Cloud Firestore through Firebase | | `adddatafirestore` | Creating a new collection and document in firestore | +| `setdatafirestore` | Creates or overwrite a single document, use the `set()` method | | `readdatafirestore` | Read data from a collection in firestore | | `referencefirestore` | Add firestore reference | | `updatefirestore` | Update the document in firestore | | `deletedocfirestore` | Delete a document in firestore | | `deletefieldfirestore` | Delete a field in firestore document | | `wherefirestore` | where query in firestore | +| `arraycontainsfirestore` | Using `array-contains` it filters based on array value | | `limitfirestore` | Retrieves the first three value of the field | | `ordermultifirestore` | Order by multiple fields in firestore | +| `realtimeupdatefirestore` | Listens for realtime changes on a document using `onSnapshot` | diff --git a/snippets/snippets.json b/snippets/snippets.json index 981eb25..fc25356 100644 --- a/snippets/snippets.json +++ b/snippets/snippets.json @@ -467,6 +467,17 @@ ], "description":"Read data from a collection in firestore" }, + + "firestore set data":{ + "prefix":"setdatafirestore", + "body":[ + "${0:db}.collection(${1:/* collection_name */}).doc(${2:/* document_name */}).set({", + "${3:attribute}: ${4:value}", + " });" + + ], + "description":"Creates or overwrite a single document, use the `set()` method" + }, "firestore reference":{ "prefix":"referencefirestore", @@ -506,7 +517,7 @@ "firestore delete a field":{ "prefix":"deletefieldfirestore", "body":[ - "let ${0:ref}= ${0:db}.collection(${2:/* collection_name */}).doc(${3: /* document_name */});", + "let ${0:ref}= ${1:db}.collection(${2:/* collection_name */}).doc(${3: /* document_name */});", "let ${4:removeField} = ${5:ref}.update({", "${6:fieldName}: firebase.firestore.FieldValue.delete()", " });" @@ -523,6 +534,16 @@ ], "description":"where query in firestore" }, + + "firestore array contains":{ + "prefix":"arraycontainsfirestore", + "body":[ + " ${0:ref}.where(${1:/* field name */}, ${2:array-contains}, ${3:/* value */})" + ], + "description":" Using `array-contains` it filters based on array value" + + }, + "firestore limit":{ "prefix":"limitfirestore", "body": "${0:ref}.orderBy(${1:/* fieldname */}).limit(${2: /* number */});", @@ -534,6 +555,17 @@ "${0:ref}.orderBy(${1:/* fieldname */}).orderBy(${2: /* name */}, ${3: /* desc */});" ], "description":"Order by multiple fields in firestore." + }, + + "firestore Listen to Changes":{ + "prefix":"realtimeupdatefirestore", + "body":[ + "${0:db}.collection(${1:/* collection_name */}).doc(${2:/* collection_name */})", + ".onSnapshot(function(${3:doc}) {", + "console.log(${3:doc}.data());", + " });" + ], + "description":"Listens for realtime changes on a document using `onSnapshot`" } }