-
-
Notifications
You must be signed in to change notification settings - Fork 604
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
Not able to store circular object in the node.data
with ext-dnd5
#1053
Comments
My current workaround is to override the every node's(in this case, only non-folder node's) const ftreeOptions = {
createNode: (e, data) => {
if (!data.node.isFolder()) {
// Store the reference to original `toDict`
const oDict = data.node.toDict;
// "Override" `toDict` to skip the circular ref property (assign to new function)
data.node.toDict = (...args) => {
// Call the original `toDict` in `data.node`'s context and store the result in `d`
const d = oDict.call(data.node, ...args);
// `d.data.propObjKey` has the circular ref property, find if it exists
if(Object.keys(d.data).find(k => k === 'propObjKey')) {
// It exists. So, create a new object without the
// the property that holds circular ref (ie., `d.data.propObjKey.__host_tree_node__`)
const newPropObj = {};
Object.keys(d.data.propObjKey).forEach(key => {
if (key === '__host_tree_node__') {
// THIS IS THE PROPERTY THAT HOLDS REFERENCE TO THE NODE IT IS RESIDING IN.
// THIS IS SOURCE OF CIRCULAR REF.
// SO, DO NOT CONSIDER IT, SKIP IT
} else {
// Populate other key-value pairs
newPropObj[sk] = d.data.propObjKey[sk];
}
});
// Finally, assign the new serializeble object to `d.data.propObjKey`
d.data.propObjKey = newPropObj ;
}
// Return serializeable object
return d;
};
}
}
} |
Maybe an optional |
@mar10 , It could be like this: (line.no: 2333) And tree options would be: const ftreeOptions = {
getSerializableData: (data) => {
/*
User defined logic to construct and return the
serializable data goes here
*/
}
} |
I don't want to encourage users to store recursive references in |
Could you test if this works for you? var nodeData = node.toDict(true, dndOpts.sourceCopyHook); and then pass the new option dnd5: {
...
sourceCopyHook: function(dict, node) {
...
}
} |
why not? I will test it and let you know. |
@mar10 , |
Because the In these cases you would not have cyclic structures or references either. Thanks for testing! |
I want to store the node's ref inside the
node.data
object but usingdnd5
extension, it throws errorExpected and Actual Behavior
Someway to allow circular object (may, safe stringify?)
or allow users to override the
node.toDict
Steps to Reproduce the Problem
node.data
Environment
enabled/affected extensions: dnd5
The text was updated successfully, but these errors were encountered: