{"size": 890, "ext": "js", "max_stars_repo_path": "packages/stranded/source/Provider.js", "max_stars_repo_name": "downplay/stranded", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "packages/stranded/source/Provider.js", "max_issues_repo_name": "downplay/stranded", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "packages/stranded/source/Provider.js", "max_forks_repo_name": "downplay/stranded", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 22.8205128205, "max_line_length": 86, "alphanum_fraction": 0.6550561798}
import { Component } from "react";
import PropTypes from "prop-types";
import invariant from "invariant";

import { Strand } from "./strand";
import execute from "./execute";

export const strandsContextShape = PropTypes.shape({
    execute: PropTypes.func.isRequired
}).isRequired;

/**
 * Provider connects to Redux and connects the execute function to stranded components
 */
class Provider extends Component {
    static childContextTypes = {
        strandsContext: strandsContextShape
    };

    getChildContext() {
        return {
            strandsContext: {
                execute: this.executeStrand
            }
        };
    }

    executeStrand(strand) {
        invariant(strand instanceof Strand);
        execute(this.props.store.dispatch, this.props.store.getState)(strand);
    }

    render() {
        return this.props.children;
    }
}

export default Provider;
