<commit_before>import ILinkableObject = weavejs.api.core.ILinkableObject;
import LinkablePlaceholder = weavejs.core.LinkablePlaceholder;
import WeavePath = weavejs.path.WeavePath;

import * as _ from "lodash";
import * as React from "react";
import * as ReactDOM from "react-dom";
import reactUpdate from "react-addons-update";
import {CSSProperties} from "react";
import ReactUtils from "./utils/ReactUtils";
import {HBox, VBox} from "./react-ui/FlexBox";
import LinkableWatcher = weavejs.core.LinkableWatcher;

export interface IWeaveComponentRendererProps extends React.HTMLProps<WeaveComponentRenderer>
{
	weave:Weave,
	path:typeof LinkableWatcher.prototype.targetPath,
	requestType?:new(..._:any[])=>React.Component<any,any>,
	props?:any
}

export interface IWeaveComponentRendererState
{
	actualType?:React.ComponentClass<any>;
	target?:ILinkableObject;
}

export default class WeaveComponentRenderer extends React.Component<IWeaveComponentRendererProps, IWeaveComponentRendererState>
{
	generatedComponent:React.Component<any, any>;
	watcher:LinkableWatcher;
	key:number = 0;
	
	constructor(props:IWeaveComponentRendererProps)
	{
		super(props);
		this.state = {};
		this.componentWillReceiveProps(props);
	}
	
	shouldComponentUpdate(nextProps:IWeaveComponentRendererProps, nextState:IWeaveComponentRendererState, nextContext:any):boolean
	{
		return !_.isEqual(this.state, nextState)
			|| !_.isEqual(this.props, nextProps)
			|| !_.isEqual(this.context, nextContext);
	}
	
	componentWillReceiveProps(props:IWeaveComponentRendererProps):void
	{
		if (this.props.weave != props.weave || !this.watcher)
		{
			// force React to create a new component for the new instance of Weave
			this.key++;
			
			if (this.watcher)
			{
				// replace the component with a placeholder before it gets unmounted and disposed due to the key changing
				LinkablePlaceholder.replaceInstanceWithPlaceholder(this.watcher.target);
				Weave.dispose(this.watcher);
			}
			
			if (props.weave)
			{
				this.watcher = Weave.disposableChild(props.weave, LinkableWatcher);
				Weave.getCallbacks(this.watcher).addGroupedCallback(this, this.handleWatcher);
			}
			else
			{
				this.watcher = null;
			}
		}
		
		if (this.watcher)
		{<commit_msg>bumping key when path changes<commit_after>import ILinkableObject = weavejs.api.core.ILinkableObject;
import LinkablePlaceholder = weavejs.core.LinkablePlaceholder;
import WeavePath = weavejs.path.WeavePath;

import * as _ from "lodash";
import * as React from "react";
import * as ReactDOM from "react-dom";
import reactUpdate from "react-addons-update";
import {CSSProperties} from "react";
import ReactUtils from "./utils/ReactUtils";
import {HBox, VBox} from "./react-ui/FlexBox";
import LinkableWatcher = weavejs.core.LinkableWatcher;

export interface IWeaveComponentRendererProps extends React.HTMLProps<WeaveComponentRenderer>
{
	weave:Weave,
	path:typeof LinkableWatcher.prototype.targetPath,
	requestType?:new(..._:any[])=>React.Component<any,any>,
	props?:any
}

export interface IWeaveComponentRendererState
{
	actualType?:React.ComponentClass<any>;
	target?:ILinkableObject;
}

export default class WeaveComponentRenderer extends React.Component<IWeaveComponentRendererProps, IWeaveComponentRendererState>
{
	generatedComponent:React.Component<any, any>;
	watcher:LinkableWatcher;
	key:number = 0;
	
	constructor(props:IWeaveComponentRendererProps)
	{
		super(props);
		this.state = {};
		this.componentWillReceiveProps(props);
	}
	
	shouldComponentUpdate(nextProps:IWeaveComponentRendererProps, nextState:IWeaveComponentRendererState, nextContext:any):boolean
	{
		return !_.isEqual(this.state, nextState)
			|| !_.isEqual(this.props, nextProps)
			|| !_.isEqual(this.context, nextContext);
	}
	
	componentWillReceiveProps(props:IWeaveComponentRendererProps):void
	{
		var weaveChanged = this.props.weave != props.weave;
		var pathChanged = !_.isEqual(this.props.renderPath, props.renderPath);
		
		// force React to create a new component if weave instance or renderPath changes
		if (weaveChanged || pathChanged)
			this.key++;
		
		// create a new watcher when weave instance changes
		if (weaveChanged || !this.watcher)
		{
			if (this.watcher)
			{
				// replace the component with a placeholder before it gets unmounted and disposed due to the key changing
				LinkablePlaceholder.replaceInstanceWithPlaceholder(this.watcher.target);
				Weave.dispose(this.watcher);
			}
			
			if (props.weave)
			{
				this.watcher = Weave.disposableChild(props.weave, LinkableWatcher);
				Weave.getCallbacks(this.watcher).addGroupedCallback(this, this.handleWatcher);
			}
			else
			{
				this.watcher = null;
			}
		}
		
		// update watcher with new path
		if (this.watcher)
		{
{'fraction_non_alphanumeric': 0.1059322033898305, 'fraction_numerical': 0.000423728813559322, 'mean_word_length': 5.211842105263158, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, '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': '342710', 'n_tokens_mistral': 1627, 'n_tokens_neox': 1472, 'n_words': 299}