Closed torgeir closed 9 years ago
Well if you know a keypath and what data you're getting at in advance I don't see why something like this would not work. For routing/dynamic paths, that's another story.
I was thinking more of a shorthand if (keypath.indexOf('.') !== -1) { return keypath.split('.') }
. You are already doing ['some', 'long', 'keypath']
anyways
Well, map keys don't need to be just strings.
From your example, if you set keyPath
conventions for your project, you can have a simple utility parsing function:
// utils.js in your project
function pathParsing(path) {
return path.split('/');
}
var keypath = immstruct({ some: { long: { keypath: 42 } } })
.cursor(pathParsing('some/long/keypath'));
Aye :) Seems tedious, tho
You'll probably also need to wrap the immstruct
library to get the API flavour you want (i.e. less tedious).
If this gets baked into immstruct, there needs to be a nota bene in the README.
This seems like a really nice-to-have feature, but I don't really think this something that should be a part of immstruct. There would also be alot of confusion, as immstruct only exposes the "first level cursor".
Where as if you do:
structure.cursor('foo').cursor('bar');
The first .cursor
method will be immstruct, but the second will be Immutable.js cursor. So we would either have to live with the difference, or patching each cursor level. Neither sound like a feasible solution in my mind, really.
Oh, you're right, I didn't think of that. That makes it pretty much a no-go then..
This would be handy