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

Optional chaining and more in path notation #116

Open
nlepage opened this issue Sep 22, 2017 · 3 comments
Open

Optional chaining and more in path notation #116

nlepage opened this issue Sep 22, 2017 · 3 comments
Milestone

Comments

@nlepage
Copy link
Member

nlepage commented Sep 22, 2017

Description

Add optional chaining operator in path notation :

const obj = { a: { b: {} } }
set(obj, 'a?.b.c', 1) // => { a: { b: { c: 1 } } }
set(obj, 'a?.c.b', 1) // => returns obj reference

Also add a null check operator :

const obj = { a: { b: {} } }
set(obj, 'a!.b.c', 1) // => { a: { b: { c: 1 } } }
set(obj, 'a!.c.b', 1) // => throws TypeError

The default behavior would stay "lodash like", that is failsafe and do the best we can.
The "do the best we can" is to be defined depending on the case.

As suggested by @EmrysMyrddin it would be nice to have a way of changing the default behavior, for example turn all of immutadot in null check mode.

@nlepage nlepage added this to the 0.4-alpha milestone Sep 22, 2017
@nlepage
Copy link
Member Author

nlepage commented Sep 22, 2017

@frinyvonnick @hgwood @EmrysMyrddin @charlyx
What do you think ? This is open for debate 😉

@nlepage
Copy link
Member Author

nlepage commented Sep 22, 2017

Also optional chaining is in stage 1 : tc39/proposal-optional-chaining

@hgwood
Copy link
Contributor

hgwood commented Sep 22, 2017

Looks really cool! 💯 Could you add some more examples to cover the following cases so we can have a broader view of impacts?

  • array notation
  • access to properties ending with ? and !

The obvious downside is the increasing complexity of the path syntax and associated parser, but I guess this syntax is one of the corner stone of the lib so I'm OK with it.

@nlepage nlepage modified the milestones: 0.4-alpha, Future Nov 8, 2017
@nlepage nlepage modified the milestones: Future, 2.0 May 29, 2018
@nlepage nlepage modified the milestones: 2.0, Future Dec 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants