bPanel

bPanel

  • Getting Started
  • About
  • Developers
  • Showcase

›API

Plugin Development

  • Intro to Plugin Development
  • Blockchain API

Guides

  • Node Info View

API

  • metadata
  • decorate
  • mapComponentState/Dispatch
  • getProps
  • reducers
  • middleware
  • Constants
  • Sockets
  • Decorate Plugins
  • Bundling Plugins
  • bPanel Utils

bPanel UI

  • Introduction
  • Components
  • Utilities

Theming (Skins)

  • Getting Started
  • Theming Defaults
  • Theming Variables

Map State & Dispatch

Plugins can share state between each other thanks to redux's state being a single source of truth. Anything in the application state can be accessed by other plugins via mapComponentState and the state can be updated with reducers via mapComponentDispatch.

The idea here is that you are telling a target component what you need it to pull from the state (or dispatch to it). That will get passed as a prop to that component (the next step in some cases is to use getProps to tell that component to pass it down to your plugin)

In order to generalize these extensions, the export is expected to just be an object with at least one key that maps exactly to the name of the component you are mapping (what this is basically doing is extending the default connect from the react-redux library for the target component). The value is a function that accepts two properties: the first is either state or dispatch and the second is a map property that contains all other existing state/dispatch decorators for that component.

Only these components are valid keys for either mapper:

  • Header
  • Footer
  • Panel
  • App
  • Sidebar

mapComponentState

As an example, let's say we want to display the network our node is connected to (e.g. mainnet, testnet, regtest) in our header. This information is available in our store. So all we have to do is map the state to the props for the header.

export const mapComponentState = {
  Header: (state, map) =>
    Object.assign(map, {
      network: state.node.node.network
    })
};

That's it! Then when we use decorateHeader, network will be available as a prop in this.props.

mapComponentDispatch

Dispatch is almost exactly the same except here you're mapping a prop to a dispatched action.

const addWallet = id => {
  type: 'ADD_WALLET',
  payload: id
}

export const mapComponentState = {
  Header: (dispatch, map) =>
    Object.assign(map, {
        addWallet: id => dispatch(addWallet(id))
      })
}
← decorategetProps →
bPanel
Docs
Quick StartPlugin OverviewTheming Overview
Community
Stack OverflowProject ChatTwitter
More
BlogGitHubStar
Copyright © 2019 bcoin
Icons made by artists from https://www.flaticon.com/authors and licensed under CC 3.0