<commit_before>'use strict';

import React from 'react';
import invariant from 'invariant';
import { connect } from 'react-redux';

import Registry from '../common/Registry';
import { isElementRef, canonical } from '../common/element';
import { isSubclassOf } from '../common/classes';

const uiRegistry = new Registry();

import ImmutableProps from '../common/ImmutableProps';
import { mix } from '../vendor/mixwith';

export function register(kind, Component) {
  invariant(
    isElementRef(kind),
    "You must provide a valid element reference to register");
  invariant(
    Component != null && (isSubclassOf(Component, React.Component) || typeof Component === 'function'),
    "You must provide a react component class or a pure-function component"
  );

  class ElementView extends mix(React.Component).with(ImmutableProps) {

    static propTypes = {
      dispatch: React.PropTypes.func.isRequired,
      element: React.PropTypes.object.isRequired
    };

    constructor(props) {
      super(props);
    }

    dispatch = (action) => {
      const { element } = this.props;
      const fromKind = canonical(element.get('kind'));
      const fromPath = element._keyPath;
      return this.props.dispatch({ ...action, fromKind, fromPath });
    };

    render() {
      return <Component element={this.props.element} dispatch={this.dispatch} />;
    }
  }

  const ConnectedElementView = connect()(ElementView);
  uiRegistry.register(kind, ConnectedElementView);

  return ConnectedElementView;
}

export function forElement(element, reactKey) {
  if (element.get && element._keyPath) {
    const fromKind = canonical(element.get('kind'));
    const Component = uiRegistry.get(fromKind);
    if (Component) {
      return <Component element={element} key={reactKey} />;
    }
  }
}

export function forElements(elementSeq) {
  return elementSeq.map(forElement).filter(ui => !!ui);
}

export function reset() {
  uiRegistry.reset();
}<commit_msg>Disconnect each registered element from redux<commit_after>'use strict';

import React from 'react';
import invariant from 'invariant';

import Registry from '../common/Registry';
import { isElementRef, canonical } from '../common/element';
import { isSubclassOf } from '../common/classes';

const uiRegistry = new Registry();

import ImmutableProps from '../common/ImmutableProps';
import { mix } from '../vendor/mixwith';

export function register(kind, Component) {
  invariant(
    isElementRef(kind),
    "You must provide a valid element reference to register");
  invariant(
    Component != null && (isSubclassOf(Component, React.Component) || typeof Component === 'function'),
    "You must provide a react component class or a pure-function component"
  );

  class ElementView extends mix(React.Component).with(ImmutableProps) {

    static propTypes = {
      element: React.PropTypes.object.isRequired
    };

    static contextTypes = {
      store: React.PropTypes.object
    };

    constructor(props) {
      super(props);
    }

    dispatch = (action) => {
      const { dispatch } = this.context.store;
      const { element } = this.props;
      const fromKind = canonical(element.get('kind'));
      const fromPath = element._keyPath;
      return dispatch({ ...action, fromKind, fromPath });
    };

    render() {
      return <Component element={this.props.element} dispatch={this.dispatch} />;
    }
  }

  uiRegistry.register(kind, ElementView);

  return ElementView;
}

export function forElement(element, reactKey) {
  if (element.get && element._keyPath) {
    const fromKind = canonical(element.get('kind'));
    const Component = uiRegistry.get(fromKind);
    if (Component) {
      return <Component element={element} key={reactKey} />;
    }
  }
}

export function forElements(elementSeq) {
  return elementSeq.map(forElement).filter(ui => !!ui);
}

export function reset() {
  uiRegistry.reset();
}
{'fraction_non_alphanumeric': 0.13165338133196194, 'fraction_numerical': 0.0, 'mean_word_length': 3.732360097323601, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, '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': '3702004', 'n_tokens_mistral': 1088, 'n_tokens_neox': 1067, 'n_words': 287}