redux-connect

@:connect support for haxe-redux
https://github.com/kLabz/haxe-redux-connect

To install, run:

haxelib install redux-connect 0.2.1 

See using Haxelib in Haxelib documentation for more information.

README.md

Haxe Redux Connect

A shorthand for react-redux connect(...) to transform a ReactComponent into a self-wrapping Higher-Order component.

This is a library meant to work with haxe-react and haxe-redux, adding support for @:connect meta on react components, as the @connect decorator of react-redux. Note that typing is not checked here; however react-redux does some checks at runtime.

ReactRedux extern is temporarily included, but will be removed once included in haxe-redux.

Usage

Installation

Using haxelib: haxelib install redux-connect

@:connect without params

If you do not provide params to the connect meta, a macro will loop through your fields to find static fields named mapStateToProps, mapDispatchToProps, mergeProps or options and use those it found.

@:connect
class MyComponent extends ReactComponentOfProps<Props>
{
	static function mapDispatchToProps(dispatch:Dispatch):Props
	{
		return {
			onClick: function() return dispatch(Actions.Click)
		};
	}

	override public function render()
	{
		return jsx('
			<button onClick=${props.onClick} />
		');
	}
}

Providing params

You can use any function instead of your own static fields.

@:connect(null, Helpers.myMapDispatchToProps)
class MyComponent extends ReactComponentOfProps<Props> {}

Or even declare your function inline, if you're into this:

@:connect(null, function(dispatch:Dispatch) return {onClick: function() return dispatch(Actions.Click))
class MyComponent extends ReactComponentOfProps<Props> {}

Please note that you must respect the order of arguments of ReactRedux.connect(), so you must pass null as first argument if you only want to define mapDispatchToProps, for example.

Contributors
klabz
Version
0.2.1
Published
7 years ago
Dependencies
License
MIT

All libraries are free

Every month, more than a thousand developers use Haxelib to find, share, and reuse code — and assemble it in powerful new ways. Enjoy Haxe; It is great!

Explore Haxe

Haxe Manual

Haxe Code Cookbook

Haxe API documentation

You can try Haxe in the browser! try.haxe.org

Join us on GitHub!

Haxe is being developed on GitHub. Feel free to contribute or report issues to our projects.

Haxe on GitHub

⌂