spa-bus

1.0.2 • Public • Published

GitHub stars GitHub issues GitHub forks GitHub last commit license Twitter

NPM NPM

spa-bus

By this tool, you can pass values across multilevel components, you don't need to pass them step by step.

Example

import React from 'react'
import { render } from 'react-dom'
import eventEmitter from 'spa-bus'
 
function Child() {
  eventEmitter.emit('testEvent', '传值给父组件')
 
  return <div>我是子组件</div>
}
 
class App extends React.Component{
  constructor(props) {
    super(props)
    eventEmitter.addEventListener('testEvent', e => console.log(e))
  }
 
  render() {
    return (
      <div>
        <h1>我是父组件</h1>
        <Child/>
      </div>
    )
  }
}
 
render(<App />, document.getElementById('root'))

Install

NPM

npm install spa-bus --save

API

  • addEventListener:

    • type : [ String ] : event type for listening

    • callBack : [ String ] : callback for the event emited

  • emit:

    • type : [ String ] : event type to emit

    • params : [ any ] : parameters to accross

  • removeEventListener:

    • type : [ String ] : event type for removing

Author

Peng Zhang returnzp@gmail.com

Package Sidebar

Install

npm i spa-bus

Weekly Downloads

1

Version

1.0.2

License

MIT

Unpacked Size

145 kB

Total Files

7

Last publish

Collaborators

  • returnzp