<commit_before>import { Component } from './component';
import { createElement } from './create-element';

// having a "custom class" here saves 50bytes gzipped
export function s(props) {}
s.prototype = new Component();

/**
 * @param {Promise} promise The thrown promise
 */
s.prototype._childDidSuspend = function(promise) {
	this.setState({ _loading: true });
	const cb = () => { this.setState({ _loading: false }); };

	// Suspense ignores errors thrown in Promises as this should be handled by user land code
	promise.then(cb, cb);
};

s.prototype.render = function(props, state) {
	return state._loading ? props.fallback : props.children;
};

// exporting s as Suspense instead of naming the class iself Suspense saves 4 bytes gzipped
// TODO: does this add the need of a displayName?
export const Suspense = s;

export function lazy(loader) {
	let prom;
	let component;
	let error;

	function Lazy(props) {
		if (!prom) {
			prom = loader();
			prom.then(
				(exports) => {
					component = exports.default;
					Lazy.displayName = 'Lazy(' + (component.displayName || component.name) + ')';
				},
				(e) => { error = e; },
			);
		}

		if (error) {
			throw error;
		}

		if (!component) {
			throw prom;
		}
<commit_msg>Fix display name of Suspense<commit_after>import { Component } from './component';
import { createElement } from './create-element';

// having a "custom class" here saves 50bytes gzipped
export function Suspense(props) {}
Suspense.prototype = new Component();

/**
 * @param {Promise} promise The thrown promise
 */
Suspense.prototype._childDidSuspend = function(promise) {
	this.setState({ _loading: true });
	const cb = () => { this.setState({ _loading: false }); };

	// Suspense ignores errors thrown in Promises as this should be handled by user land code
	promise.then(cb, cb);
};

Suspense.prototype.render = function(props, state) {
	return state._loading ? props.fallback : props.children;
};

export function lazy(loader) {
	let prom;
	let component;
	let error;

	function Lazy(props) {
		if (!prom) {
			prom = loader();
			prom.then(
				(exports) => {
					component = exports.default;
					Lazy.displayName = 'Lazy(' + (component.displayName || component.name) + ')';
				},
				(e) => { error = e; },
			);
		}

		if (error) {
			throw error;
		}

		if (!component) {
			throw prom;
		}

{'fraction_non_alphanumeric': 0.14132762312633834, 'fraction_numerical': 0.0021413276231263384, 'mean_word_length': 3.4836852207293667, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '3691837', 'n_tokens_mistral': 815, 'n_tokens_neox': 735, 'n_words': 224}