You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've come to the conclusion that the fromJS reviver should have access to the full key path.
If that was provided then we can easily setup a map to do custom things at certain paths when converting nested objects and lists into Immutable.js structures.
If we want to convert structures like this into Records and Lists, we might create a reviver that maps the root, profile, emails, and emails entries to records.
Then in our reviver, we can apply the appropriate record based on the full path of the key.
Currently as of today, we only get the local key, so there is no good way to setup a proper mapping. That local key might be used in many places so we really need a full path key. Also with the list items, the local key will just be a number, so this doesn't tell us which Record to use assuming there could be many lists in the structure.
I see that your v4 subRecords feature might help but even then I'm not sure they go deep enough and can reach into lists.
But besides the use of Records if you wanted to do any specific tailoring to structures when converting with fromJS, it really makes sense to have the full key path available so you can know what to do. You can't always just assume things based on the data, it would be better to also have the full key path so you know if you are in the right part of the structure.
I thought I might be able to figure out the full key path using the this object which provides the parent, but as far as I can tell that doesn't help any.
If there is another way to get the full path in the reviver, please let me know.
Otherwise, I'm thinking it would be good to add another parameter which is the full key path to the reviver. For consistency with the rest of the API it would probably be an array like ['profile', 'emails', 1].
So the new signature for the fromJS reviver would be
fromJS(json: any,reviver?: (k: any,v: Iterable<any,any>,path: Array<string>)=>any): any
Thoughts or alternative ideas?
The text was updated successfully, but these errors were encountered:
I've come to the conclusion that the fromJS reviver should have access to the full key path.
If that was provided then we can easily setup a map to do custom things at certain paths when converting nested objects and lists into Immutable.js structures.
For instance, given a plain JS structure
If we want to convert structures like this into Records and Lists, we might create a reviver that maps the root, profile, emails, and emails entries to records.
Then in our reviver, we can apply the appropriate record based on the full path of the key.
Currently as of today, we only get the local key, so there is no good way to setup a proper mapping. That local key might be used in many places so we really need a full path key. Also with the list items, the local key will just be a number, so this doesn't tell us which Record to use assuming there could be many lists in the structure.
I see that your v4 subRecords feature might help but even then I'm not sure they go deep enough and can reach into lists.
But besides the use of Records if you wanted to do any specific tailoring to structures when converting with fromJS, it really makes sense to have the full key path available so you can know what to do. You can't always just assume things based on the data, it would be better to also have the full key path so you know if you are in the right part of the structure.
I thought I might be able to figure out the full key path using the this object which provides the parent, but as far as I can tell that doesn't help any.
If there is another way to get the full path in the reviver, please let me know.
Otherwise, I'm thinking it would be good to add another parameter which is the full key path to the reviver. For consistency with the rest of the API it would probably be an array like
['profile', 'emails', 1]
.So the new signature for the fromJS reviver would be
Thoughts or alternative ideas?
The text was updated successfully, but these errors were encountered: