Skip to content

Latest commit

 

History

History
127 lines (103 loc) · 4.72 KB

api.md

File metadata and controls

127 lines (103 loc) · 4.72 KB

API

查看中文

Module exports

  1. Default export a initialize method: import createApp from 'mickey'
  2. Component and method
  1. Directly export The following components and methods from dependencies.

API

Initialization

Methods

Properties

  • app.store
  • app.history
  • app.actions
  • app.plugin

createApp(options)

Create an instance of Mickey and return it:

import createApp from 'mickey';
const app = createApp(options);

<ActionsProvider actions>

Makes the actions available to the injectActions() calls in the component hierarchy below. We should never use this component, and it was used in the render method, like this:

<ActionsProvider actions={app.actions}>
  <App />
</ActionsProvider>

injectActions(Component, {propName = 'actions', withRef = false})

Inject actions to a React component. By default the propName would be actions. If withRef is true, stores a ref to the wrapped component instance and makes it available via getWrappedInstance() method.

For example, Counter

import React from 'react'
import { connect, injectActions } from 'mickey'
import './App.css'

const App = props => (
  <div id="counter-app">
    <h1>{props.count}</h1>
    <div className="btn-wrap">
      <button onClick={() => props.actions.counter.decrement()}>-</button>
      <button onClick={() => props.actions.counter.increment()}>+</button>
      <button
        style={{ width: 100 }}
        onClick={() => {
          if (props.loading) {
            alert('loading') // eslint-disable-line
          } else {
            props.actions.counter.incrementAsync()
          }
        }}
      >
        {props.loading ? 'loading' : '+ Async'}
      </button>
    </div>
  </div>
)

export default injectActions(connect(store => ({ ...store.counter }))(App))