<commit_before>import React from "react";
import {createStore} from "redux";

import {leanReducer, connectLean} from "../src/lean";

import {render} from "./helpers";

describe("performance", () => {

    test("component does not render if the mapped state does not change", () => {
        const store = createStore(leanReducer);
        const renderSpy = jest.fn();
        let handler = null;

        class Hello extends React.PureComponent {
            render() {
                console.log("render");
                handler = this.props.setName;
                renderSpy();
                return <div>Hello {name}</div>;
            }
        }

        Hello = connectLean({
            scope: "ascope",
            getInitialState() {
                return {name: "from initial"};
            },
            mapState() {
                return {name: "hard coded"};
            },
            setName() {
                this.setState({name: "from handler"});
            },
        })(Hello);

        render(store, Hello);
        const renderCount = renderSpy.mock.calls.length;
        handler();
        expect(renderSpy).toHaveBeenCalledTimes(renderCount);
    });

    test("mapState is not called if state does not change", () => {
        const store = createStore(leanReducer);
        const mapSpy = jest.fn();
        let handler = null;

        class Hello extends React.PureComponent {

            render() {
                handler = this.props.setName;
                mapSpy();
                return <div>Hello {name}</div>;
            }
        }

        Hello = connectLean({
            scope: "ascope",
            getInitialState() {
                return {name: "same value"};
            },
            mapState() {
                mapSpy();
                return {name: "hard coded"};
            },
            setName() {
                this.setState({name: "same value"});
            },
        })(Hello);

        render(store, Hello);
        const mapCount = mapSpy.mock.calls.length;
        handler();<commit_msg>cleanup<commit_after>import React from "react";
import {createStore} from "redux";

import {leanReducer, connectLean} from "../src/lean";

import {render} from "./helpers";

describe("performance", () => {

    test("component does not render if the mapped state does not change", () => {
        const store = createStore(leanReducer);
        const renderSpy = jest.fn();
        let handler = null;

        class Hello extends React.PureComponent {
            render() {
                console.log("render");
                handler = this.props.setName;
                renderSpy();
                return <div>Hello {name}</div>;
            }
        }

        Hello = connectLean({
            scope: "ascope",
            getInitialState() {
                return {name: "from initial"};
            },
            mapState() {
                return {name: "hard coded"};
            },
            setName() {
                this.setState({name: "from handler"});
            },
        })(Hello);

        render(store, Hello);
        const renderCount = renderSpy.mock.calls.length;
        handler();
        expect(renderSpy).toHaveBeenCalledTimes(renderCount);
    });

    test("mapState is not called if state does not change", () => {
        const store = createStore(leanReducer);
        const mapSpy = jest.fn();
        let handler = null;

        class Hello extends React.PureComponent {

            render() {
                handler = this.props.setName;
                return <div>Hello {name}</div>;
            }
        }

        Hello = connectLean({
            scope: "ascope",
            getInitialState() {
                return {name: "same value"};
            },
            mapState() {
                mapSpy();
                return {name: "hard coded"};
            },
            setName() {
                this.setState({name: "same value"});
            },
        })(Hello);

        render(store, Hello);
        const mapCount = mapSpy.mock.calls.length;
        handler();
{'fraction_non_alphanumeric': 0.1254262055528495, 'fraction_numerical': 0.0, 'mean_word_length': 1.4981751824817517, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 17, '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': '1521114', 'n_tokens_mistral': 1090, 'n_tokens_neox': 1034, 'n_words': 260}