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

multi reference objects don't survive serialization on send. #582

Closed
givensnickel opened this issue Sep 27, 2019 · 5 comments
Closed

multi reference objects don't survive serialization on send. #582

givensnickel opened this issue Sep 27, 2019 · 5 comments
Assignees
Labels
feature suggestions for new features or enhancements

Comments

@givensnickel
Copy link

Sorry for opening two tickets on pretty much the same thing ( #581 ), though I might have a possible solution. In this issue if an object has multiple references to the same object the value is cloned so the values are not the same.

Example:

// Sending side:
let common_value = ["This is a mutable object."]
let obj = { one: common_value, two: common_value }
Object.is(obj.one, obj.two) // true
Object.is(obj.one, ["This is a mutable object."]) // false
connection.send(obj)

// Receiving side:
connection.on('data', obj => { 
    // obj = { one: ["This is a mutable object."], two: ["This is a mutable object."] }
    Object.is(obj.one, obj.two) // false
    Object.is(obj.one, ["This is a mutable object."]) // false
})

As a solution I found dojox which would provide serialization to solve both this issue and issue #581.

@afrokick afrokick added the feature suggestions for new features or enhancements label Nov 1, 2019
@afrokick afrokick self-assigned this Nov 1, 2019
@afrokick
Copy link
Member

afrokick commented Nov 1, 2019

@givensnickel could you please try my PR with flatted? #592

@kidandcat
Copy link
Member

kidandcat commented Nov 1, 2019

This is not a library issue, but you are missing the concept of pointers in JS, before sending, your obj.one and obj.two are pointers to common_value. Of course after sending them, they are resolved to their value before serializing them.

I don't think flatted work for this example neither.

What you should do instead is not to use Object.is but do a deep comparition.

@givensnickel
Copy link
Author

@givensnickel could you please try my PR with flatted? #592

@afrokick that is perfect! And exposing the serialization per connection is also wonderful for extending it per use case. Thank you!

@kidandcat Flatted worked perfectly for both circular references and pointer references, preserving the object structure in both cases.

@afrokick
Copy link
Member

afrokick commented Nov 1, 2019

@givensnickel thanks! We will release it in 1.2.0.

@givensnickel
Copy link
Author

Cool! Glad to hear.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature suggestions for new features or enhancements
Projects
None yet
Development

No branches or pull requests

3 participants