Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // @flow
- import type {Component, Node} from 'react';
- import {connect} from 'react-redux';
- function pick(obj: {[string]: mixed}, props: string[]) {
- const result = {};
- for (let i = 0; i < props.length; ++i) {
- result[props[i]] = obj[i];
- }
- return result;
- }
- function wrapMapper(mapDataToProps: Function): Function {
- return (store, {id}) => {
- const meta = store.meta[id];
- const data = store.widgets[meta.name][id];
- const collections = pick(store.collections, meta.collections);
- return mapDataToProps(data, collections);
- };
- }
- export default function <D, C, P> (
- mapDataToProps: ?(D, C) => $Shape<P>,
- mapDispatchToProps: ?(mixed => void) => $Shape<P>
- ): (Component<P> | P => Node) => Component<P> {
- const mapData = mapDataToProps ? wrapMapper(mapDataToProps) : null;
- const mapDispatch = mapDispatchToProps ? d => mapDispatchToProps(d) : null;
- return connect(mapData, mapDispatch);
- }
Advertisement
Add Comment
Please, Sign In to add comment