-
Notifications
You must be signed in to change notification settings - Fork 5
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
Path syntax: merge slice syntax and prop list syntax #167
Comments
Having commas in the array/slice notation is a very good idea, and would allow the users to do anything they want. |
*anything they want :) Yes, of course I'm fine with postponing. |
I feel this issue deprecated since tc39 have a proposal for slice notation https://github.com/tc39/proposal-slice-notation I think we should stick to standard approach |
I think this needs further discussions. What this issue was originally about isThe bracket notation (not slice notation) allows accessing array indexes, array slices, properties, non identifier named properties. Sticking to the standardsSticking to the standards is obviously a good idea. The slice notation (with the step added) follows tc39's proposal. But the properties list access follows no standard, it was inspired by bash's notation for multiple directories, and it looks like destructuring: const { a, b } = obj
set(obj, '{a,b}', 123) But what about access to non identifier named properties ? When accessing one property we stick to the standard: obj["my prop"] = "foo"
set(obj, '["my prop"]', "bar") But when accessing multiple properties, it doesn't look like destructuring anymore: const { myProp1, ["my prop2"]: myProp2 } = obj
set(obj, '{myProp1,"my prop2"}', 123) Destructuring requires aliasing the property to a valid identifier, but in the path this is not necessary. This is not so bad after all... if we wanted to look more like destructuring we could put back the brackets: set(obj, '{myProp1,["my prop2"]}', 123) Finally what about the all props access ? Using the star may not have been such a good idea. Following the idea of sticking to the destructuring, we could have used the three dots: set(obj, '{...}', 123) |
Prerequisites
Description
Since #159, immutadot supports both slices for arrays (
arr[1:4]
) and prop lists for objects (obj{a,b}
). Since arrays and objects are actually the same concept, would it be possible to merge the two syntaxes?Only for feature requests ✨
Example
The text was updated successfully, but these errors were encountered: