Skip to content

Comments

feat(store) add overload for projector to inform about incorrect usage#3223

Closed
david-shortman wants to merge 1 commit intongrx:masterfrom
david-shortman:strict-projector
Closed

feat(store) add overload for projector to inform about incorrect usage#3223
david-shortman wants to merge 1 commit intongrx:masterfrom
david-shortman:strict-projector

Conversation

@david-shortman
Copy link
Contributor

@david-shortman david-shortman commented Nov 9, 2021

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

[ ] Bugfix
[x] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Documentation content changes
[ ] Other... Please describe:

What is the current behavior?

Starts process on #3097

What is the new behavior?

A message on an overload for projector when it is used incorrectly:

Screen Shot 2021-11-11 at 15 00 12

Does this PR introduce a breaking change?

[ ] Yes
[x] No

Other information

@ngrxbot
Copy link
Collaborator

ngrxbot commented Nov 9, 2021

Preview docs changes for 5662d21 at https://previews.ngrx.io/pr3223-5662d219/

@david-shortman
Copy link
Contributor Author

@timdeschryver The docs-app test is failing, seemingly for a reason unrelated to the PR.

@timdeschryver
Copy link
Member

@david-shortman 👍 you can leave it as is - we'll take a look at it.
For now, let's try a rerun.

@brandonroberts
Copy link
Member

Needs a rebase

@david-shortman
Copy link
Contributor Author

david-shortman commented Nov 11, 2021

@brandonroberts The opt-in for strict projectors can take place in two ways:

export const selector = createSelector(
        selectUrl,
        url => url,
        { strict: true } // specify a `strict` flag, which means the developer can allow the Slices and Result to be inferred
      );

or

export const selector = createSelector<[string], string>( // directly supply generic arguments for Slices and Result
        selectUrl,
        url => url
      );


export type ProjectorFn<Args extends unknown[], T> = (...args: Args) => T;

export type StrictMemoizedSelector<
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this type is not exported from the index so that developers do not create a dependency on this type (presuming it can one day be removed, and all memoized selectors have strict projectors).

instead, if a dev needs to declare the type of a variable, they can use the form MemoizedSelector<State, Result, (slices...Slices) => Result>

@david-shortman david-shortman changed the title feat(store) deprecate loose projector in favor of strict projector feat(store) introduce opt-in strict projectors from createSelector Nov 11, 2021
@david-shortman david-shortman force-pushed the strict-projector branch 2 times, most recently from cb65036 to c2ee493 Compare November 11, 2021 18:20
> = MemoizedSelector<
State,
Result,
{ strict: true } & ((...slices: Slices) => Result)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{ strict: true } is purely type information which is used by MemoizedSelector to determine which projector function is used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently this is known as an opaque type.

@david-shortman david-shortman changed the title feat(store) introduce opt-in strict projectors from createSelector feat(store) add overload for projector to inform about incorrect usage Nov 11, 2021
@netlify
Copy link

netlify bot commented Mar 25, 2022

Deploy Preview for ngrx-io canceled.

Built without sensitive environment variables

Name Link
🔨 Latest commit be88aaa
🔍 Latest deploy log https://app.netlify.com/sites/ngrx-io/deploys/623d1633ea97f4000882595f

@david-shortman
Copy link
Contributor Author

closing and reopening with updates once #3354 is merged

@david-shortman david-shortman deleted the strict-projector branch September 17, 2022 21: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.

4 participants