from kivy.uix.screenmanager import Screen # noqa
from sjfirebase.tools.mixin import FirestoreMixin
class MyScreen(Screen, FirestoreMixin):
def on_event1(self):
# gets a dictionary of data from "document_id" if any data and passes
# `success` (True/False) and `data` (dict/errorMessage).
# always check if success is True before accessing items from data,
# or check if data is an instance of dict. Else log the data to see the error message
self.get_document("individual/document_id", lambda success, data: print(success, data))
def on_event2(self):
# everything @on_event1 plus `source` that states where the data should be fetched.
# either cache, server or default. cache gets from firebase data stored locally
# on the device for offline purposes while server gets from firebase cloud directly.
# default can be either cache or cloud depending on your configuration.
self.get_document("individual/document_id", lambda success, data: print(success, data), source="cache")
def on_event3(self):
# gets all document at "individual" collection and passes success and data argument.
# here, data is a list of dict. before accessing, refer to @on_event1
self.get_collection_of_documents("individual", lambda success, data: print(success, data))
def on_event4(self):
# refer to @on_event2 for "source" and @on_event3 for functionality description
self.get_collection_of_documents("individual", lambda success, data: print(success, data), source="cache")
def on_event5(self):
# refer to @on_event3 for functionality description. The new thing here is `limit`.
# limit is used to limit the amount of data you fetch from firebase and paginate as you go.
self.get_pagination_of_documents("individual", 10, lambda success, data: print(success, data))
def on_event6(self):
# listens for document changes and returns a dict of data and location
# where the data is coming from. `data`(dict/errorMessage), where("Local"/"Server")
self.add_document_snapshot_listener("individual/document_id", lambda data, where: print(data, where))
def on_event7(self):
# same as @on_event6 but gets a list of document with information on whether they were
# added, removed or modified
self.add_collection_snapshot_listener("individual", lambda data, where: print(data, where))