<commit_before>import * as React from 'react';
import { IocContext } from 'power-di';
import { getGlobalType } from 'power-di/utils';
import { Odux } from '../core';
import { EventBus } from '../event';
import { ChangeEvent, ChangeDispatch } from '../core';
import { shallowEqual } from '../utils';

export type MapToProps<OwnPropsType, MapperPropsType> = (ioc: IocContext, ownProps?: OwnPropsType) => MapperPropsType;

export interface StateType {
  data: any;
}

export function connect<OwnPropsType, MapperPropsType>(ioc: IocContext, mapper: MapToProps<OwnPropsType, MapperPropsType>) {

  return function (WrappedComponent: any) {
    const Connect = class extends React.Component<OwnPropsType, StateType> {
      static WrappedComponent: any;
      static displayName: string;

      eventBus: EventBus;
      needUpdate = true;

      constructor(props: OwnPropsType, context: any) {
        super(props, context);

        this.eventBus = ioc.get(EventBus);

        this.state = { data: mapper(ioc, props), };
      }

      onReduxChange = (evt: ChangeEvent) => {
        this.checkStateChange();
      }

      componentDidMount() {
        this.eventBus.addEventListener(ChangeEvent, this.onReduxChange);
      }
      componentWillUnmount() {
        this.eventBus.removeEventListener(ChangeEvent, this.onReduxChange);
      }

      componentWillReceiveProps(nextProps: Readonly<OwnPropsType>, nextContext: any) {
        this.checkStateChange(nextProps);
      }

      shouldComponentUpdate(nextProps: Readonly<OwnPropsType>, nextState: Readonly<{}>, nextContext: any) {
        return this.needUpdate;
      }

      checkStateChange(props = this.props) {
        const newState = mapper(ioc, this.props);
        this.needUpdate = !shallowEqual(this.state.data, newState);
        if (this.needUpdate) {
          this.setState({
            data: newState,
          });
        }
      }

      render() {
        return React.createElement(WrappedComponent, this.state.data);
      }
    };

    const wrappedComponentName = WrappedComponent.displayName
      || WrappedComponent.name
      || getGlobalType(WrappedComponent)
      || 'Component';
    Connect.displayName = `Odux(${wrappedComponentName})`;

    return Connect;
  };
}<commit_msg>fix connect pass ownprops.<commit_after>import * as React from 'react';
import { IocContext } from 'power-di';
import { getGlobalType } from 'power-di/utils';
import { Odux } from '../core';
import { EventBus } from '../event';
import { ChangeEvent, ChangeDispatch } from '../core';
import { shallowEqual } from '../utils';

export type MapToProps<OwnPropsType, MapperPropsType> = (ioc: IocContext, ownProps?: OwnPropsType) => MapperPropsType;

export interface StateType {
  data: any;
}

export function connect<OwnPropsType, MapperPropsType>(ioc: IocContext, mapper: MapToProps<OwnPropsType, MapperPropsType>) {

  return function (WrappedComponent: any) {
    const Connect = class extends React.Component<OwnPropsType, StateType> {
      static WrappedComponent: any;
      static displayName: string;

      eventBus: EventBus;
      needUpdate = true;

      constructor(props: OwnPropsType, context: any) {
        super(props, context);

        this.eventBus = ioc.get(EventBus);

        this.state = { data: mapper(ioc, props), };
      }

      onReduxChange = (evt: ChangeEvent) => {
        this.checkStateChange();
      }

      componentDidMount() {
        this.eventBus.addEventListener(ChangeEvent, this.onReduxChange);
      }
      componentWillUnmount() {
        this.eventBus.removeEventListener(ChangeEvent, this.onReduxChange);
      }

      componentWillReceiveProps(nextProps: Readonly<OwnPropsType>, nextContext: any) {
        this.checkStateChange(nextProps);
      }

      shouldComponentUpdate(nextProps: Readonly<OwnPropsType>, nextState: Readonly<{}>, nextContext: any) {
        return this.needUpdate;
      }

      checkStateChange(props = this.props) {
        const newState = mapper(ioc, this.props);
        this.needUpdate = !shallowEqual(this.state.data, newState);
        if (this.needUpdate) {
          this.setState({
            data: {
              newState
            },
          });
        }
        this.needUpdate = this.needUpdate || !shallowEqual(this.props, props);
      }

      render() {
        return React.createElement(WrappedComponent, {
          ...this.props as any,
          ...this.state.data,
        });
      }
    };

    const wrappedComponentName = WrappedComponent.displayName
      || WrappedComponent.name
      || getGlobalType(WrappedComponent)
      || 'Component';
    Connect.displayName = `Odux(${wrappedComponentName})`;

    return Connect;
  };
}
{'fraction_non_alphanumeric': 0.11820882852292021, 'fraction_numerical': 0.0, 'mean_word_length': 2.967171717171717, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3596735', 'n_tokens_mistral': 1359, 'n_tokens_neox': 1341, 'n_words': 280}