Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

feat(state): improve DX by logging undefined keys in selectSlice #852

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
Loading
from

Conversation

mrkpks
Copy link

@mrkpks mrkpks commented Jul 16, 2021

Fixes #639

  • picked a non-breaking solution: logging warning for undefined slices

Note: logs cases for selectSlice operator only. Behavior of this operator, when dealing with undefined slices, was the cause of confusion for developers most of the time

@mrkpks mrkpks self-assigned this Jul 16, 2021
@github-actions github-actions bot added the { } State @rx-angular/state related label Jul 16, 2021
Copy link
Member

@edbzn edbzn left a comment

Choose a reason for hiding this comment

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

Hi, here are my thoughts on this, I get the benefice of notifying the consumer from an undefined or partially undefined state instead of silently emitting nothing which can be hard to debug but, on the other side, lazy state initialization means undefined values and this is a behavior that happens often when using the state library, so this will warn a lot of correct usages. This is something that will really improve DX?

Comment on lines +86 to +92
tap((state) => {
if (isDevMode() && state === undefined) {
console.warn(
'@rx-angular/state#selectSlice WARNING: state is undefined'
);
}
}),
Copy link
Member

Choose a reason for hiding this comment

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

Lazy state initialization is a key concept and warning for an undefined state is contradictory to that from my perspective.

Copy link
Member

Choose a reason for hiding this comment

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

@edbzn true, lazy state is a key concept. the warning in devMode is still very helpful. especially when u are doing your first steps with rx-angular and cannot wrap your head around why selectSlice won't emit any values. The issue gets worse when your state interface has 100's of properties.

We have seen such cases, thats why the PR was opened :)

console.warn(
`@rx-angular/state#selectSlice WARNING: undefined value(s) of selected key(s): "${undefinedKeys.join(
'", "'
)}" selectSlice operator will return undefined`
Copy link
Member

Choose a reason for hiding this comment

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

Technically, selectSlice will not return undefined because the next operator will filter undefined values, it will not emit any notification instead.

Copy link
Member

Choose a reason for hiding this comment

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

agree, selectSlice won't emit any notification

@hoebbelsB
Copy link
Member

@mrkpks thx for the PR! from my perspective it looks good besides the minor comment above. A further improvement would be a way to let it not run everytime. We should at first try it one of the demo applications and see if we get spammed too hard from it?

@nx-cloud
Copy link

nx-cloud bot commented Oct 3, 2021

Nx Cloud Report

CI ran the following commands for commit a587e51. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this branch

Status Command
#000000 nx affected:build --with-deps
#000000 nx run ssr-e2e:e2e --headless
#000000 nx affected:test --parallel --maxParallel=2
#000000 nx affected:lint --parallel --maxParallel=3

Sent with 💌 from NxCloud.

@edbzn
Copy link
Member

edbzn commented Oct 4, 2021

Hi, first of all, thanks for your work.

We discussed this and we think that it will spam too much the console as it is currently implemented. It's a very common scenario to have undefined keys with the lazy state initialization concept. We should find a way to avoid spamming when not desired. We came out with different alternatives:

  • adding an argument debug or verbose to selectSlice
  • adding a selectSliceDebug operator
  • adding a generic debug operator (*)
  • not implementing this (**)

*The generic operator should be used with the same array of keys and before the selectSlice operator, eg:

pipe(debug(['keyA', 'keyB']), selectSlice(['keyA, keyB']))

This solution does not look very satisfying to me.

**This is not a trivial problem, and I feel like there's no perfect solution to solve this. My position is to not augment the API surface and let the developer ensure keys are defined before selecting them.

cc @hoebbelsB @BioPhoton

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core team meeting { } State @rx-angular/state related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Log an error/warning for undefined values in RxState operators
4 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.