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

$raw support numbered indexes for ramda #10

Closed
paul-sachs opened this issue Nov 19, 2020 · 9 comments
Closed

$raw support numbered indexes for ramda #10

paul-sachs opened this issue Nov 19, 2020 · 9 comments

Comments

@paul-sachs
Copy link

Currently, using an index field with ramda can cause some confusion:

tp<typeof state>().array[index].x.y.$raw

This produces a path of ['array', index.toString(), 'x', 'y']. This causes problems in ramda since it looks to the path type to determine array or object. This will cause something like assocPath to turn an array into an object.

@paul-sachs
Copy link
Author

I believe a simple fix to this line would do:

return typedPath(handlersConfig, [...path, name.toString()], true);

Changing it to something like:

return typedPath(handlersConfig, [...path, (typeof name === 'number' ? name : name.toString())], true);

This would break some typing currently in place but would also make sure we support ramda properly.

@bsalex
Copy link
Owner

bsalex commented Nov 21, 2020

Hi @paul-sachs
Thanks for the report.

I've added another default handler, .$rawPath, to keep backward compatibility.
Could you try your scenario with version typed-path@2.2.0-beta.0 and .$rawPath?
https://github.com/bsalex/typed-path/tree/beta#rawpath

@paul-sachs
Copy link
Author

@bsalex Yeah I'll give it a shot in the next few days. Thanks for the quick response.

@paul-sachs
Copy link
Author

@bsalex looks better. I think my version of ramda has problems with the (string | number | symbol)[] bit though, works fine with (string | number)[]. Might just my version of ramda types though (@types/ramda@0.26.18) so I can work around that with a simple cast.

@bsalex
Copy link
Owner

bsalex commented Nov 23, 2020

@paul-sachs
Thanks.

Could you clarify whether the changes in the 2.2.0-beta.0 fixed the issue you have with ramda (with the workaround)?
The goal is to push the changes to the public package if they help.

Also, it would be great to add documentation for a simple use case with ramda.
Could you share an example for the issue that you've encountered?

@paul-sachs
Copy link
Author

@bsalex yeah, i'll write something up shortly. My example is pretty nested in an application so I'll simplify and put something together.

@paul-sachs
Copy link
Author

@bsalex I've created a simple codesandbox to show the issue: https://codesandbox.io/s/thirsty-sunset-q85b2?file=/src/App.tsx

You can see the change in array status if you switch to an older version of typed-path (and replace $rawPath with $raw)

@bsalex bsalex mentioned this issue Nov 29, 2020
@bsalex
Copy link
Owner

bsalex commented Nov 29, 2020

Thanks for the contribution,
typed-path@2.2.0 has been published
https://www.npmjs.com/package/typed-path

@bsalex
Copy link
Owner

bsalex commented Nov 29, 2020

I'm closing the issue, thanks again for the report.
Feel free to open another issue if you encounter a problem.

@bsalex bsalex closed this as completed Nov 29, 2020
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

No branches or pull requests

2 participants