Categories > Firebase > rex_firebase_savedata

Introduction

Private save slots.

Links


Categories > Firebase > rex_firebase_savedataIntroductionLinksDependenceUsageData structure on firebaseSaveLoadFlow chart of load headersFlow chart of load bodyCleanDebug panelSecurity

Dependence

Usage

Data structure on firebase

<sub-domain>\
    <UserID>
        headers\
    	    <slotName>
    		    <key> - value
    
    	bodies\
    	    <slotName>
    		    <key> - value

Save

CallbackYesNoActionis successCondition:On saveCondition:On save errorExpression:LastErrorMessageExpression:LastErrorCodeAction:Set ownerAction:Set valueAction:Set boolean valueAction:Set JSONAction:Remove keyAction:Save

Sample capx, sample capx2

  1. Action:Set owner

  2. Prepare slot

    • Action:Set value

      • Parameter Key supports dot-notation. For example, set pos.x to 10 to update header or body with
       
      xxxxxxxxxx
      {
        "pos":{
          "x": 10
        }
      }
    • Action:Set boolean value

    • Action:Set JSON

    • Action:Remove key

  3. Action:Save

  4. Callback

    • Success : Condition:On save

    • Failed : Condition:On save error

      • Error : Expression:LastErrorMessage, Expression:LastErrorCode

Load

Flow chart of load headers

CallbackYesHeadersKeys in a headerNoActionis successCondition:On get headers Slot:Condition:All slots are emptyCondition:Slot is occupied Header value:Expression:HeaderValue(slotName, key)Expression:HeadersToJSONCondition:For each header Expression:CurSlotNameExpression:CurHeaderValue(key)Condition:For each key Expression:CurKeyExpression:CurValueCondition:On get headers error Expression:LastErrorMessageExpression:LastErrorCodeAction:Set ownerAction:Get all headers

Flow chart of load body

CallbackUser selects a slotYesNoKeys in bodyYesNoActionis successBody is NullCondition:On get body Expression:BodyValue(key)Expression:BodyToJSONCondition:For each key Expression:CurKeyExpression:CurValueCondition:On get unused body Condition:Body is invalidCondition:On get body error Expression:LastErrorMessageExpression:LastErrorCodeAction:Set ownerGet & display headersAction:Get body
  1. Action:Set owner

  2. Read headers, optional

    1. Action:Get all headers

    2. Callback

      • Success : Condition:On get headers

        • Expression:HeaderValue(slotName, key), returns a value

          • Expression:HeaderValue(slotName, key, defaultValue)
        • Expression:HeadersToJSON, returns a header in JSON string

          • Expression:HeaderValue(slotName)
        • Condition:For each header, retrieves each header

          • Expression:CurSlotName

          • Expression:CurHeaderValue(key)

            • Expression:CurHeaderValue(key, defaultValue)
        • Condition:For each key, in Load - header category, retrieves each key in a header

          • Expression:CurKey
          • Expression:CurValue
        • Slot

          • Condition:All slots are empty, returns true if no slot is used
          • Condition:Slot is occupied, returns true if a slot is used
      • Failed : Condition:On get headers error

        • Error : Expression:LastErrorMessage, Expression:LastErrorCode
  3. Read a body

    1. Action:Get body

    2. Callback

      • Success :

        • Body is valid (i.e. not null) : Condition:On get body

          • Expression:BodyValue(key), returns a value

            • Expression:BodyValue(key, defaultValue)
          • Expression:BodyToJSON, returns body in JSON string

            • Expression:BodyValue
          • Condition:For each key, in Load - body category, retrieves each key in a header

            • Expression:CurKey
            • Expression:CurValue
        • Else, Condition:On get unused body

          • Condition:Body is invalid, returns true
      • Failed : Condition:On get body error

        • Error : Expression:LastErrorMessage, Expression:LastErrorCode

Clean

CallbackYesNoActionis successCondition:On cleanCondition:On clean errorExpression:LastErrorMessageExpression:LastErrorCodeAction:Set ownerAction:Clean slotAction:Clean all slots
  1. Action:Set owner

  2. Action:Clean slot, or Action:Clean all slots

  3. Callback

    • Success : Condition:On clean

      • Slot will become unused
    • Failed : Condition:On clean error

      • Error : Expression:LastErrorMessage, Expression:LastErrorCode

Debug panel

Current loaded headers and loaded body will be presented on debug panel.


Security

Add security rule to make private slots set. (Reference)

Assume that sub domain is save-data :

 
xxxxxxxxxx
{
    "rules": {
        "save-data": {
            "$user": {
                ".read":"auth.uid === $user",
                ".write":"auth.uid === $user"
            }
        }
    }
}