Skip to content

Conversation

@dmarcos
Copy link
Member

@dmarcos dmarcos commented Aug 7, 2017

a-saturday-night uses selector properties that change at run time. This triggered Converted circular structure to JSON errors when trying to clone into previousData A-Frame entity elements that hold references to other A-Frame entities via components .We should only be cloning plain objects.

@ngokevin
Copy link
Member

ngokevin commented Aug 8, 2017

Can you paste pseudocode that describes "selector properties being changed at runtime"?

data = typeof schema.default === 'object' ? utils.clone(schema.default) : schema.default;
// Clone default value if plain object so components don't share the same object
// that might be modified by the user.
data = typeof schema.default === 'object' && schema.default.constructor === Object ? utils.clone(schema.default) : schema.default;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need both typeof and .constructor checks?

*/
function cloneData (data) {
var clone = {};
var parsedProperty;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

declare vars up top.

i wonder if we should start to use for (key in obj) for every loop over an object where we know it's a plain JS object. e.g., change some of the code in the buildData to also use for...in

@dmarcos
Copy link
Member Author

dmarcos commented Aug 8, 2017

An example is: el.setAttribute('avatar', 'el', '#bear') A selector changes at runtime and the previous is cloned as oposed to being defined statically in the HTML

@cvan
Copy link
Contributor

cvan commented Aug 11, 2017

@fernandojsg is this true that this blocks aframevr/a-saturday-night#118 (comment) ?

@fernandojsg
Copy link
Member

@cvan yes, it was described on my PR aframevr/a-saturday-night#117 (I closed it because @caseyyee and I were doing practically the same)

@ngokevin
Copy link
Member

Speaking towards the technicals, I start to often use strings rather than selector property type. The selector property time has given us issues like these, keeping a DOM object in state. And my problems were I often wanted a reference to the raw selector string in case I wanted to re-run it. Still useful to have, but if you ever have issues with selector property type, fall back to string.

default values that are not plain objects into data.
@dmarcos
Copy link
Member Author

dmarcos commented Aug 11, 2017

I addressed the review comments and fixed the test. Ok to merge?

data = typeof previousData === 'object' ? utils.clone(previousData) : {};
// Clone previous data to prevent sharing references with attrValue that might be
// modified by the user.
data = typeof previousData === 'object' ? cloneData(previousData) : {};
Copy link
Member

@ngokevin ngokevin Aug 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe you can use utils.extend({}, previousData). The problem with utils.clone is it uses JSON to do it. Getting rid of the clone function you made.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utils.extend copies references. I still want to clone the plain object properties

@ngokevin
Copy link
Member

r+wc

@dmarcos dmarcos merged commit 2938822 into aframevr:master Aug 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants