Skip to content

externalEffect

Sezer Ekinci edited this page Sep 5, 2017 · 4 revisions

"externalEffect" can be defined in manifest under the "_q" property of any node. That property has a condition part for looking in other collection and make some actions. "externalEffect" will be triggered, if data is sent or if "set" option is defined (as "true" or "permanent") while "flatte.do" function called. Otherwise it will never work.

"externalEffect" property is an array. You can add unlimited copies to any node.

{
  node: {
    _q:{
      // Simple
      externalEffect: [{
        path: "external/collection/path",
        if: {
          key: "looking for key in collection",
          value: "equal to value of key"
        },
        save: {
          key: "effect field name on save action",
          value: "effect field value on save action"
        }
        delete: {
          key: "effect field name on delete action",
          value: "effect field value on delete action"
        }
      }]
    }
  }
}

path

The path of copy collection. You can use parent nodes' ID's with # (hastag).

Available Options: String.

if

This is the condition part of externalEffect. Works like;

if (path[key] === value) {...}

* key

The looking for collection property name. You can use parent nodes' ID's with # (hastag).

Available Options: String.

* value

The same usage with "saveValue".

save

On save action, this property will be triggered. Assigns "key = value" inside found collections.

* key

Key name of found collection. You can use parent nodes' ID's with # (hastag).

Available Options: String.

* value

The same usage with "saveValue".

delete

On delete action, this property will be triggered. Assigns "key = value" inside found collections.

* key

Key name of found collection. You can use parent nodes' ID's with # (hastag).

Available Options: String.

* value

The same usage with "saveValue".

Examples

This example updates or deletes group names in users collection if name of group is changed or deleted.

{
  groups: {
    childs: {
      groupID: {
        _q: {
          ID: true,
        },
        childs: {
          groupName: {
            _q:{
              externalEffect: {
                path: "users",
                if: {
                  key: "groups/#groupID/id",
                  value: "#groupID"
                },
                save: {
                  key: "groups/#groupID/groupName",
                  value: "$"
                },
                delete: {
                  key: "groups/#groupID/groupName",
                  value: null
                }
              }
            }
          }
        }
      }
    }
  }
}

Clone this wiki locally