-
Notifications
You must be signed in to change notification settings - Fork 86
Open
Milestone
Description
I'm inclined to throw an error (or an specialized error, like ObjectPathError) when the provided path is empty. It's usually a programming mistake, and it bit me a couple of times (usually when dealing with JSON coming from the server). Returning the original object shouldn't be the right thing to do, since it can be 'truthy'.
Examples:
var ok;
Ok = 'some.path'; // mistyped the variable name
objectPath.set(obj, ok, 'some value');
/* ... */
$http.get('/endpoint').then(function(r) {
if (objectPath.has(obj, r.path)) { // returns true even though r.path is undefined!
return 'do something';
}
// it's actually in r.data.path, a return from angular $http, really easy to mess up
});What is your opinion @mariocasciaro?
I think it's the only place where the module should actually forcefully throw, to prevent hard-to-debug scenarios, since it will 'swallow' the empty path. And we shouldn't worry about it in the next version, since it's a major breaking change anyway
Metadata
Metadata
Assignees
Labels
No labels