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

Pass the entire slice to selectors function #188

Merged
merged 2 commits into from
Dec 5, 2023

Conversation

robbaman
Copy link
Contributor

@robbaman robbaman commented Dec 5, 2023

Changed the selector definition to be the entire signalSlice as oposed to just the state.

Not sure how to run the tests (the docs just say to 'run the tests'), so not sure if this also required a change to the test framework. The changed version did do what I'd expect in my project.

@joshuamorony
Copy link
Contributor

Note to reviewers this was discussed/agreed in this issue: #187

@robbaman you can run the tests with pnpm exec nx run ngxtension/signal-slice:test, this likely will not break any existing tests but ideally it would be good to add an extra test where one of the top level selectors is accessed to create a custom selector

@robbaman
Copy link
Contributor Author

robbaman commented Dec 5, 2023

It seems while this change does work in runtime it does in fact break a test because of a TypeScript compiler flag.

image

This error can be suppressed by setting noPropertyAccessFromIndexSignature to false in the tsconfig.json file, but I'm not sure if that's the direction you'd want to go with the project.

@joshuamorony
Copy link
Contributor

You should be able to solve this by passing in any instead of TSelectors when typing the selectors config:

	selectors?: (
		state: SignalSlice<
			TSignalValue,
			TActionSources,
			any,
			TEffects,
			TActionEffects
		>
	) => TSelectors;

Copy link
Contributor

@joshuamorony joshuamorony left a comment

Choose a reason for hiding this comment

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

With the typing change I think we will then just need a test to verify the new functionality and we should be good to merge

Comment on lines 143 to 151
selectors?: (
state: SignalSlice<
TSignalValue,
TActionSources,
TSelectors,
any,
TActionEffects
>
) => TSelectors;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
selectors?: (
state: SignalSlice<
TSignalValue,
TActionSources,
TSelectors,
any,
TActionEffects
>
) => TSelectors;
selectors?: (
state: SignalSlice<
TSignalValue,
TActionSources,
any,
TEffects,
TActionEffects
>
) => TSelectors;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're correct. I've made the change and also changed the test file to read the age property from state().age to state.age() to confirm it is indeed the entire slice that is provided.

Copy link
Contributor

@joshuamorony joshuamorony left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

Will just need to wait on a reviewer with write access to trigger the workflow and get this merged

Copy link

nx-cloud bot commented Dec 5, 2023

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 5ee21f4. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


⌛ The following target is in progress

✅ Successfully ran 3 targets

Sent with 💌 from NxCloud.

@nartc nartc enabled auto-merge (squash) December 5, 2023 13:43
@nartc nartc merged commit c2ae394 into ngxtension:main Dec 5, 2023
@nartc
Copy link
Collaborator

nartc commented Dec 5, 2023

@all-contributors please add @robbaman for code

Copy link
Contributor

@nartc

I've put up a pull request to add @robbaman! 🎉

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.

3 participants