import pageState from 'bitbucket/internal/model/page-state';

/**
 *
 * @param {Object} newPullRequestJSON
 * @param {boolean} dispatch - whether or not to dispatch the new pull request data
 * @param {Object} props - pull-request-header react component props
 */
export default (newPullRequestJSON, dispatch, props) => {
    // also update the pageState for current legacy operations.
    if (newPullRequestJSON._stash) {
        pageState.getPullRequest().set(newPullRequestJSON._stash);
    }
    if (dispatch === true) {
        props.dispatch({ type: 'PR_SET_PULL_REQUEST', payload: newPullRequestJSON });
    }
}
