Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get Start with redux-bind #1

Open
sorrycc opened this issue Jan 15, 2016 · 0 comments
Open

Get Start with redux-bind #1

sorrycc opened this issue Jan 15, 2016 · 0 comments

Comments

@sorrycc
Copy link
Owner

sorrycc commented Jan 15, 2016

// 1. import dependencies
import { createBind, reducer, middleware } from 'redux-bind';

// 2. create store with middleware and reducer
const store = applyMiddleware(middleware)(createStore)(combineReducers({
  bind: reducer,
}));

// 3. create bind component
const FileUploadModal = createBind('Modal', {
  id: 'uploadFileModal',  // 指定唯一 id,可选
  fields: ['visible'],    // 指定绑到 store 里的属性
})(Modal);

// 4. use component
render() {
  return <FileUploadModal />;       // 不需要重复配置已绑定到 store 里的属性
}

// 5.1 update component state
dispatch({
  type: 'redux-bind',
  id: 'uploadFileModal',
  payload: { visible: true },
});

// 5.2 update component state with function
dispatch({
  type: 'redux-bind',
  id: 'uploadFileModal',
  payload: { visible: (v) => !v },
});

// 5.3 update component state with action creator helper
this.props.updateReduxBind({
  id: 'uploadFileModal',
  payload: { visible: true },
});
@sorrycc sorrycc changed the title Usage Get Start with redux-bind Jan 15, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant