2.4.17 • Published 5 years ago

dob-react v2.4.17

Weekly downloads
39
License
ISC
Repository
github
Last release
5 years ago

dob-react · CircleCI Status npm version code coverage

React bindings for dob.

Design idea from Mobx Implementation

Install

npm i dob-react

Online demo

Here is a basic demo, and here is a demo with fractal.

Simple Usage

import { Provider, Connect } from 'dob-react'

@Connect
class App extends React.Component <any, any> {
    render() {
        return (
            <span>{this.props.store.name}</span>
        )
    }
}

ReactDOM.render(
    <Provider store={{ name: 'bob' }}>
        <App />
    </Provider>
, document.getElementById('react-dom'))

Connect: All parameters from outer Provider are injected into the wrapped components, and the component rerender when the variables used in the render function are modified(sync usage).

Connect all functions

Connect all

Connect all from Provider's parameters, also is this example above.

Connect extra data

Will also inject all parameters from outer Provider.

@Connect({
    customStore: {
        name: 'lucy'
    }
})
class App extends React.Component <any, any> {}

Map state to props

Will also inject all parameters from outer Provider.

@Connect(state => {
    return {
        customName: 'custom' + state.store.name
    }
})
class App extends React.Component <any, any> {}

ReactDOM.render(
    <Provider store={{ name: 'bob' }}> <App /> </Provider>
, document.getElementById('react-dom'))

Support stateless component

class App extends React.Component <any, any> {
    render() {
        return (
            <span>{this.props.store.name}</span>
        )
    }
}

const ConnectApp = Connect()(App)
// const ConnectApp = Connect({ ... })(App)
// const ConnectApp = Connect( state => { ... })(App)
2.4.17

5 years ago

2.4.16

5 years ago

2.4.15

6 years ago

2.4.14

6 years ago

2.4.13

6 years ago

2.4.12

6 years ago

2.4.11

6 years ago

2.4.10

6 years ago

2.4.9

6 years ago

2.4.7

6 years ago

2.4.6

6 years ago

2.4.5

6 years ago

2.4.4

6 years ago

2.4.3

6 years ago

2.4.2

6 years ago

2.4.1

6 years ago

2.4.0

7 years ago

2.3.3

7 years ago

2.3.2

7 years ago

2.3.1

7 years ago

2.3.0

7 years ago

2.2.1

7 years ago

2.2.0

7 years ago

2.1.9

7 years ago

2.1.8

7 years ago

2.1.7

7 years ago

2.1.6

7 years ago

2.1.4

7 years ago

2.1.3

7 years ago

2.1.2

7 years ago

2.1.1

7 years ago

2.1.0

7 years ago

2.0.25

7 years ago