Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(connector): allow override of stateSliceEqualityComparer #224

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

g7ed6e
Copy link

@g7ed6e g7ed6e commented Sep 25, 2019

Hi,

First of all, thanks for great job, ng-redux is a first class tool to move away from AngularJS service based state applications to a more robust state management solution.

In a large scale legacy application we started to refactor the whole app using ng-redux and are now facing a performance issue due to an increasing $digest cycle time.

We noticed the updateTarget method was called because the provided shallowEqual does not exactly fit our model shape. Please see below a sample component.

import template from './header-template.html';
import ngRedux from 'ng-redux';
import { Unsubscribe } from 'redux';
import { getProfile } from '../../store/profile/selectors';
import { getCustomer } from '../../store/project/selectors';

export interface IHeaderModel {
    profile: IProfileModel;
    customer: ICustomerOutput;
}

export const mapStateToThis = (state: IRootState) => {
    const profile = getProfile(state);
    const customer = getCustomer(state);
    const result = {
        model: {
            profile,
            customer,
        },
    };
    return result;
};

export class HeaderController implements angular.IController, IViewModel<IHeaderModel> {
    public model: IHeaderModel;
    public unsubscribe: Unsubscribe;
    constructor($ngRedux: ngRedux.INgRedux) {
        this.unsubscribe = $ngRedux.connect(mapStateToThis)(this);
    }

    public $onDestroy() {
        this.unsubscribe();
    }
}

HeaderController.$inject = ['$ngRedux'];

export const HeaderComponent: angular.IComponentOptions = {
    template,
    controller: HeaderController,
};

Motivation:
The goal of this PR is to allow to override the default shallowEqual implementation at connect time and at component level.

@g7ed6e g7ed6e marked this pull request as ready for review September 25, 2019 09:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant