Skip to content

Latest commit

 

History

History
66 lines (53 loc) · 1.52 KB

File metadata and controls

66 lines (53 loc) · 1.52 KB

Actions

Actions are data payloads that provide information from your application to your Interbit blockchain. Interbit uses the Redux design, so actions in Interbit are essentially the same as actions in Redux. Specifically, actions are plain JavaScript objects that must have a type and a payload property. Types should be defined as string constants. The contents of the payload property are completely up to you.

Actions are sent to the blockchain by calling the dispatch(), redispatch(), and remote_dispatch() methods. You define your own application actions, and at runtime they originate from either user or system activity. Your Smart Contracts (reducers) typically evaluate the incoming Action type to determine appropriate behavior.

Below are the various contexts in which you will work with actions.

Defining your Action:

let actions = {
  EVENT_OCCURRED: 'EVENT_OCCURRED',
  eventOccurred: (data) => {
    return {
      type: actions.EVENT_OCCURRED,
      payload: {
        data
      }
    }
  }
}

Dispatching an Action:

chain.dispatch(action)

Evaluating an Action in a Smart Contract:

if (action.type === actions.EVENT_OCCURRED) {
  // Take appropriate behavior
}

//OR

switch (action.type) {
  // Case for each action type
}
Note

Example

To see actions in practice, please see the actions in the To-do List example.