Experimental

« Back to index

Experimental

Table of Contents:

FirebaseDB

The Firebase component communicates with a Web service to store and retrieve information. The component has methods to store a value under a tag and to retrieve the value associated with the tag. It also possesses a listener to fire events when stored values are changed.

Additional Information

Properties

DeveloperBucket
Getter for the DeveloperBucket.
FirebaseToken
Getter for the FirebaseToken.
FirebaseURL
Specifies the URL for the Firebase.

The default value is currently my private Firebase URL, but this will eventually changed once the App Inventor Candle plan is activated.

Persist
If true, variables will retain their values when off-line and the App exits. Values will be uploaded to Firebase the next time the App is run while connected to the network. This is useful for applications which will gather data while not connected to the network. Note: AppendValue and RemoveFirst will not work correctly when off-line, they require a network connection.

Note: If you set Persist on any Firebase component, on any screen, it makes all Firebase components on all screens persistent. This is a limitation of the low level Firebase library. Also be aware that if you want to set persist to true, you should do so before connecting the Companion for incremental development.
ProjectBucket
Getter for the ProjectBucket.

Events

DataChanged(tag,value)
Indicates that the data in the Firebase has changed. Launches an event with the tag and value that have been updated.
FirebaseError(message)
Indicates that the communication with the Firebase signaled an error.
FirstRemoved(value)
Event triggered by the “RemoveFirst” function. The argument “value” is the object that was the first in the list, and which is now removed.
GotValue(tag,value)
Indicates that a GetValue request has succeeded.
TagList(value)
Event triggered when we have received the list of known tags. Used with the “GetTagList” Function.

Methods

AppendValue(tag,valueToAdd)
Append a value to the end of a list atomically. If two devices use this function simultaneously, both will be appended and no data lost.
ClearTag(tag)
Asks Firebase to forget (delete or set to “null”) a given tag.
GetTagList()
Get the list of tags for this application. When complete a “TagList” event will be triggered with the list of known tags.
GetValue(tag,valueIfTagNotThere)
GetValue asks Firebase to get the value stored under the given tag. It will pass valueIfTagNotThere to GotValue if there is no value stored under the tag.
RemoveFirst(tag)
Return the first element of a list and atomically remove it. If two devices use this function simultaneously, one will get the first element and the the other will get the second element, or an error if there is no available element. When the element is available, the “FirstRemoved” event will be triggered.
StoreValue(tag,valueToStore)
Asks Firebase to store the given value under the given tag.
Unauthenticate()
Unauthenticate from Firebase.

Firebase keeps track of credentials in a cache in shared_prefs It will re-use these credentials as long as they are valid. Given That we retrieve a FirebaseToken with a version long life, this will effectively be forever. Shared_prefs survive an application update and depending on how backup is configured on a device, it might survive an application removal and reinstallation.

Normally this is not a problem, however if we change the credentials used, for example the App author is switching from one Firebase account to another, or invalided their firebase.secret, this cached credential is invalid, but will continue to be used, which results in errors.

This function permits us to unauthenticate, which tosses the cached credentials. The next time authentication is needed we will use our current FirebaseToken and get fresh credentials.

GraphQL

The GraphQL component communicates with a GraphQL endpoint to execute queries and mutations. It represents returned data as a dictionary. All queries have an associated operation name and are executed asynchronously. Completed queries trigger different events depending on whether there the queries had any errors.

Properties

GqlEndpointUrl
Specifies the URL for this GraphQL component.
GqlHttpHeaders
Specifies the HTTP headers for this GraphQL component as a JSON dictionary.

Events

GqlGotError(gqlQueryName,gqlError)
Triggers an event indicating that there were one or more errors when executing the query. This method should be executed in the application’s main thread.
GqlGotResponse(gqlQueryName,gqlResponse)
Triggers an event indicating that the given operation has successfully executed and returned data. This method should be executed in the application’s main thread.

Methods

GqlQuery(gqlQueryName,gqlQuery)
Executes an arbitrary query against the GraphQL endpoint.