-
Notifications
You must be signed in to change notification settings - Fork 55
Implement CID.asCID and depracte CID.isCID #23
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
Conversation
cid.js
Outdated
} | ||
|
||
static isCID (value) { | ||
deprecate(/^0\.0/, `CID.isCID(v) is deprecated and will be removed in the next major release. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we move this string up to the top so that the indentation doesn’t flow backwards below?
So, first of all, I’m +1 on dropping For the record, I’m +1 on this change, but I think I need to spend some time explaining it for the benefit of others and for myself a month from now because I already got my head around this once and then forgot it. Currently, we write code like this: if (typeof value === ‘object’) {
if (CID.isCID(value)) return handleLink(value)
return handleObject(value)
} Since If you have a Separately, we have another issue with What @Gozala figured out, which is quite brilliant, is that all serialization libraries will choke on circular references, but circular references are preserved when passed to a Worker. This means that we can move to a method of detection that uses circular references, as we have done here, and we have a good way to preserve the type over the process boundary without introducing a property that could potentially conflict with real data when it passes over the Worker boundary. This does mean we will need to migrate to writing code that looks more like. if (typeof value === ‘object’) {
const link = CID.asCID(value)
if (link) return handleLink(link)
return handleObject(value)
} |
I actually thought of this. That is why removal of |
This change builds upon #18 as per discussion at multiformats/js-cid#111.
It does following:
.asCID
property that points to the CID instance that has it. This is a unique (enough) marker to distinguish CID values form other values.[Symbol.for('@ipld/js-cid/CID')]
marker this:CID.asCID
static method as a replacement forCID.isCID
, which improves following:CID.asCID
will be able to work withCID
instances from other threads without (receiver doing any work). Becauseconst cid = CID.asCID(value)
will return instance of thisCID
class.--
Things I could use some help with: