How to use the shallow-equal.shallowEqualArrays function in shallow-equal

To help you get started, we’ve selected a few shallow-equal examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github TimboKZ / Chonky / src / components / FileBrowser.tsx View on Github external
public UNSAFE_componentWillReceiveProps(nextProps: Readonly): void {
        const old = this.props;
        const {
            files, folderChain, onSelectionChange, disableSelection,
            view, options, sortProperty, sortOrder,
        } = nextProps;

        let selectionStatus = SelectionStatus.Ok;

        if (!shallowEqualArrays(files, old.files)) {
            selectionStatus = SelectionStatus.NeedsCleaning;
            this.setState({rawFiles: files});
        }
        if (!shallowEqualArrays(folderChain, old.folderChain)) {
            if (!isArray(folderChain) || getNonNil(folderChain, -1) !== getNonNil(old.folderChain, -1)) {
                selectionStatus = SelectionStatus.NeedsResetting;
            }
            this.setState({folderChain});
        }

        if (disableSelection === true && disableSelection !== old.disableSelection) {
            selectionStatus = SelectionStatus.NeedsResetting;
        }
        if (!isNil(view) && view !== old.view) this.setState({view});
        if (isObject(options) && options !== old.options) {
            this.setState(prevState => ({options: {...prevState.options, ...options}}));
github TimboKZ / Chonky / src / components / FileBrowser.tsx View on Github external
public componentDidUpdate(prevProps: Readonly, prevState: Readonly): void {
        const {onSelectionChange} = this.props;
        const {
            rawFiles: oldRawFiles, selection: oldSelection, options: oldOptions,
            sortProperty: oldSortProperty, sortOrder: oldSortOrder,
        } = prevState;
        const {rawFiles, selection, options, sortProperty, sortOrder} = this.state;

        let justChangedSelection = false;

        const needToResort = !shallowEqualArrays(rawFiles, oldRawFiles)
            || !shallowEqualObjects(options, oldOptions)
            || sortProperty !== oldSortProperty
            || sortOrder !== oldSortOrder;
        if (needToResort) {
            const [sortedFiles, fileIndexMap] = FileUtil.sortFiles(rawFiles, options, sortProperty, sortOrder);
            const newState: Partial = {sortedFiles, fileIndexMap};

            const newSelection = {};
            let additionCount = 0;
            for (const file of sortedFiles) {
                if (isNil(file) || selection[file.id] !== true) continue;
                newSelection[file.id] = true;
                additionCount++;
            }
            if (additionCount !== Object.keys(selection).length) {
                newState.selection = newSelection;
github TimboKZ / Chonky / src / components / FileBrowser.tsx View on Github external
public UNSAFE_componentWillReceiveProps(nextProps: Readonly): void {
        const old = this.props;
        const {
            files, folderChain, onSelectionChange, disableSelection,
            view, options, sortProperty, sortOrder,
        } = nextProps;

        let selectionStatus = SelectionStatus.Ok;

        if (!shallowEqualArrays(files, old.files)) {
            selectionStatus = SelectionStatus.NeedsCleaning;
            this.setState({rawFiles: files});
        }
        if (!shallowEqualArrays(folderChain, old.folderChain)) {
            if (!isArray(folderChain) || getNonNil(folderChain, -1) !== getNonNil(old.folderChain, -1)) {
                selectionStatus = SelectionStatus.NeedsResetting;
            }
            this.setState({folderChain});
        }

        if (disableSelection === true && disableSelection !== old.disableSelection) {
            selectionStatus = SelectionStatus.NeedsResetting;
        }
        if (!isNil(view) && view !== old.view) this.setState({view});
        if (isObject(options) && options !== old.options) {
            this.setState(prevState => ({options: {...prevState.options, ...options}}));
        }
        if (!isNil(sortProperty) && sortProperty !== old.sortProperty) this.setState({sortProperty});
        if (!isNil(sortOrder) && sortOrder !== old.sortOrder) this.setState({sortOrder});

shallow-equal

Typescript-compatible minimalistic shallow equality check for arrays/objects

MIT
Latest version published 2 years ago

Package Health Score

71 / 100
Full package analysis