I'd really love this api:
someObject.lookup('some.really.long.property.path') - works essentially just like lodash.get or optional chaining. But what if you want to know why the lookup failed?
just print someObject.lastLookupMsg
As a failsafe, is the last lookup was successful.. this could be set to true (there is no meaningful message for successful lookups)
If the last lookup failed, it COULD just automatically console.log("Lookup failed: some.really.long is:", some.really.long, "some.really is:", some.really);
Maybe there could be a cousin to optional chaining ?. – perhaps ~. Means "tread carefully" and returns the last property lookup that was not undefined/null.
Or perhaps ?. could have a debugging version which does the console.log for you in development only.
One issue is that passing an object lookup path as a string results in no syntax highlighting, you probably lose out on a bunch of other potential ide goodies, but from what I know they mostly don't apply to the main use case of check data from the user or from over the wire.
I wasn't able to add lookup to the Object.prototype because I was getting this error with my CRA v3+CRACO setup...
"Invariant Violation: EventPluginRegistry: Cannot inject event plugins that do not exist in the plugin ordering, lookup"
The stack trace was pure webpack hell, did not include it in my google search..
I tried adding it directly in my index.html in a script tag but that didn't fix it. I could, however, delay defining it for 5 seconds via setTimeout and I can then define Object.prototype.lookup
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
what do people think of this debugging focused cousin of lodash.get, I call it "safeGet"
I'd really love this api:
someObject.lookup('some.really.long.property.path') - works essentially just like lodash.get or optional chaining. But what if you want to know why the lookup failed?
just print someObject.lastLookupMsg
As a failsafe, is the last lookup was successful.. this could be set to
true(there is no meaningful message for successful lookups)If the last lookup failed, it COULD just automatically console.log("Lookup failed: some.really.long is:", some.really.long, "some.really is:", some.really);
Maybe there could be a cousin to optional chaining ?. – perhaps ~. Means "tread carefully" and returns the last property lookup that was not undefined/null.
Or perhaps ?. could have a debugging version which does the console.log for you in development only.
At the end of the day I think I would prefer to use a simple Object.prototype.lookup method that automatically console.log's the message I described.
One issue is that passing an object lookup path as a string results in no syntax highlighting, you probably lose out on a bunch of other potential ide goodies, but from what I know they mostly don't apply to the main use case of check data from the user or from over the wire.
I wasn't able to add lookup to the Object.prototype because I was getting this error with my CRA v3+CRACO setup...
"Invariant Violation: EventPluginRegistry: Cannot inject event plugins that do not exist in the plugin ordering,
lookup"The stack trace was pure webpack hell, did not include it in my google search..
I tried adding it directly in my index.html in a script tag but that didn't fix it. I could, however, delay defining it for 5 seconds via setTimeout and I can then define Object.prototype.lookup