Open phillipskevin opened 5 years ago
Could we make can-reflect avoid serializing elements all together?
Serializing elements is not the issue.
canReflect.serialize
does avoid serializing elements because built ins are directly returned.
The performance problem is specific to devtools because it doesn't always use serialize
directly. It is using canReflect.getOwnKeys
so that it can recursively get the names for objects.
I've fixed this in devtools.
That being said, what should components serialize to?
Right now, serializing a component like:
const C = Component.extend({
tag: "a-pp",
view: `<p>Hello</p>`,
ViewModel: {}
});
Reflect.serialize( new C() );
...gives something like:
{
"_initialArgs": [
null,
null
],
"element": {
"canFri Dec 07 2018 15:21:07 GMT-0600 (Central Standard Time)": "2",
"viewModel": {}
},
"viewModel": {},
"nodeList": [
{}
],
"_torndown": false
}
Is this useful? It's not actually "serialized" since the element
is an actual element.
We should add a Symbol so that component instances serialize to empty objects, this way if a ViewModel has component instances on it, the serialization will not be extremely slow.
Related to https://github.com/canjs/devtools/issues/41#issuecomment-445121130.