Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/haxe-react/haxe-redux-connect
@:connect support for haxe-redux
https://github.com/haxe-react/haxe-redux-connect
Last synced: about 2 months ago
JSON representation
@:connect support for haxe-redux
- Host: GitHub
- URL: https://github.com/haxe-react/haxe-redux-connect
- Owner: haxe-react
- License: mit
- Created: 2018-03-12T10:35:19.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-03-06T11:53:46.000Z (almost 6 years ago)
- Last Synced: 2024-04-28T04:04:13.008Z (9 months ago)
- Language: Haxe
- Size: 9.77 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# 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.
```haxe
@:connect
class MyComponent extends ReactComponentOfProps
{
static function mapDispatchToProps(dispatch:Dispatch):Props
{
return {
onClick: function() return dispatch(Actions.Click)
};
}override public function render()
{
return jsx('
');
}
}
```### Providing params
You can use any function instead of your own static fields.
```haxe
@:connect(null, Helpers.myMapDispatchToProps)
class MyComponent extends ReactComponentOfProps {}
```Or even declare your function inline, if you're into this:
```haxe
@:connect(null, function(dispatch:Dispatch) return {onClick: function() return dispatch(Actions.Click))
class MyComponent extends ReactComponentOfProps {}
```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.