Skip to content

Repository files navigation

Rxact React

npm versionCircleCI masterCoveralls github branch

Rxact React is a React observer for Rxact.

After setup this plugin, the instance of StateStream will have an observer function helping you binding stream's state to react component.

Installation

 yarn add rxact rxact-react

Usage

There are two ways:

1. Install as a plugin

import{setup,StateStream}from'rxact'import{pluginasrxactReact}from'rxact-react'setup({Observable: /** Observable lib you like **/,plugins: [rxactReact()],})conststream=newStateStream('stream',{name: 'rxact'})stream.observer(state=>({name: state.name,}))(classReactComponentextendsReact.Component{
...
})

2. Enhance StateStream

import{setup,StateStream}from'rxact'import{decoratorasrxactReact}from'rxact-react'constEnhancedStateStream=decorator()(StateStream)setup({Observable: /** Observable lib you like **/,StateStream: EnhancedStateStream,})conststream=newEnhancedStateStream('stream',{name: 'rxact'})stream.observer(state=>({name: state.name,}))(classReactComponentextendsReact.Component{
...
})

API

plugin()

Return a StateStream plugin.

decorator()

Return a function for wrapping StateStream.

stateStream.observer()

stateStream.observer(mapStateToProps: ?Function,mergeProps: ?Function,): StateStreamPlugin
ParameterTypeDescriptionDefault
mapStateToPropsFunctionFunction for mapping stream state to component state.None
mergePropsFunctionFunction for merging result of mapStateToProps and parent props.None

If you are familiar with react-redux, you will find out it is almost as same as connect.

License

MIT

About

React observer for Rxact

Topics

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages