Skip to content

Commit

Permalink
fix(store): don't call the projector function if there are no selecto…
Browse files Browse the repository at this point in the history
…rs and props (#1515)

Closes #1501
  • Loading branch information
timdeschryver authored and brandonroberts committed Jan 20, 2019
1 parent 7bba0f4 commit e0ad3c3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 11 additions & 0 deletions modules/store/spec/selector.spec.ts
Expand Up @@ -143,6 +143,17 @@ describe('Selectors', () => {
});
});

it('should not short circuit to the projector fn if there are no selectors and props', () => {
const projectFn = jasmine.createSpy('projectionFn');
const state = { counter: {} };

const selector = (createSelector(projectFn) as any)(state);

// the projector still fires but without arguments,
// this because there are no selectors and props
expect(projectFn).toHaveBeenCalledWith();
});

it('should be possible to test a projector fn independent from the selectors it is composed of', () => {
const projectFn = jasmine.createSpy('projectionFn');
const selector = createSelector(
Expand Down
2 changes: 1 addition & 1 deletion modules/store/src/selector.ts
Expand Up @@ -551,7 +551,7 @@ export function createSelectorFactory(
const memoizedState = defaultMemoize(function(state: any, props: any) {
// createSelector works directly on state
// e.g. createSelector((state, props) => ...)
if (selectors.length === 0) {
if (selectors.length === 0 && props !== undefined) {
return projector.apply(null, [state, props]);
}

Expand Down

0 comments on commit e0ad3c3

Please sign in to comment.