js-class-is
js-class-is copied to clipboard
Could symbol be added to the prototype instead of instace ?
I think it can! However, while it will increase instances creation performance, it will decrease isX invocation performance, as it will have to fallback to the prototype.
Not sure what to do here.
Sorry I submitted this in a rush, and forgot to provide more context. The reason this came up is I'm having to do this nasty bit of a hack:
https://github.com/ipfs/js-ipfs/pull/3081/files#diff-833dfdb70fcd89365dc3bddf93f78e7eR57
Which is needed because once CIDs cross thread boundaries their prototype chain is lost. Code under the link restores those prototype chains. However in case of CID turns out it is not enough because CID.isCID(v) is primarily how checks are performed, and it seems to return false even when v instanceof CID would return true, because that symbol field is set on instance rather than prototype. Which in turn is lost because symbols don't carry over during structure cloning.
When I started looking into this, I got wondering why that field is set on instance vs prototype and created this issue.
I'm not sure if moving symbol field is a best or adequate way to get rid of that nasty code I've linked to, but that was my immediate thought.
@Gozala probably better to remove class-is and just use validateCID.
@Gozala probably better to remove class-is and just use
validateCID.
@hugomrdias remove from where ? All of the code base ?
I was suggesting cid
@hugomrdias sorry I'm not sure I understand what you mean by:
@Gozala probably better to remove class-is and just use validateCID.
Remove class-is from cids library ? If so do you mean also remove isCID static method or implementing it differently ? If former there's a lot of code that uses isCID and probably going to be an impractical to do that. If later would be good to know what you have in mind.
I think it can! However, while it will increase instances creation performance, it will decrease isX invocation performance, as it will have to fallback to the prototype.
Not sure what to do here.
Another alternative could be to set it on both prototype and instance.
Keep the api just without class-is, implement isCID with instanceof with fallback to validating the components