Skip to content
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

Components should serialize to empty objects #321

Open
phillipskevin opened this issue Dec 7, 2018 · 3 comments
Open

Components should serialize to empty objects #321

phillipskevin opened this issue Dec 7, 2018 · 3 comments

Comments

@phillipskevin
Copy link
Contributor

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 canjs/devtools#41 (comment).

@justinbmeyer
Copy link
Contributor

Could we make can-reflect avoid serializing elements all together?

@phillipskevin
Copy link
Contributor Author

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.

@phillipskevin
Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants