-
Notifications
You must be signed in to change notification settings - Fork 39
Drop class-is dependecy #110
Comments
sigh, In principal I’m all for this. Taking an entire dependency that creates a new class wrapper for what should be a relatively simple symbol convention has always seemed a bit off to me. |
Is that still the case ? In my work I have being defining static class methods and have not seen any complaints from aegir. |
We should not move to
In this specific case, we’re also relying on the symbol to avoid transparent errors in the migration to the new And finally, I’ve said this in another thread, but we should definitely not allow things that are not instances of some sort of if (CID.isCID(value)) {
fn(value.toString()) // multibase encoded CID
} If |
That’s because class Test {
static test = 'asdf'
}
console.log(Test)
|
I think it's well understood, I do mention that here and also further point out how
I was not proposing to drop symbol check, I did however assumed (incorrectly it seems) that
I understand that and is not what I am suggesting. |
Right I was referring to static methods which are ok, static properties are not. P.S.: I have being using static getters to work around lack of static properties support. |
Ok, sorry for my miss-understanding. |
Then the properties aren’t enumerable tho :( which is why I’ve stuck with I can’t actually figure out what the status is of this in standards. The originally proposal went to Stage 2, was then merged into another proposal which was then merged into another proposal which now doesn’t actually mention |
yes this is what i was suggesting, which assumptions are we breaking ? |
const {codec, version, multihash, multibaseName } = new CID(...)
const v = {codec, version, multihash, multibaseName }
if (CID.isCID(v)) {
v.toV0() // throws
} |
Above being said, I think it would be better to not rely on instance methods and instead migrate to static methods so above would translated to: if (CID.isCID(v)) {
CID.toV0(v)
} However that is going to be a big change. I think this can be a more pragmatic compromise #111 Better yet would be to do both and internally use static methods. However I don't feel like proposal to use statics got much support. |
Can someone point me to what V0 conversion is so limited ( |
To be clear I just picked on |
Got it, I guess I would like to find a solution that could be applied to all the other modules that use class-is. Something like this https://github.com/feross/is-buffer/blob/master/index.js Even something that is best effort, would be acceptable and avoid having that ugly wrapper. |
I think following should do pretty much what current implementation does without wrappers and all: class CID {
static isCID(value) {
return value instanceof CID || (value && value[typeSymbol])
}
}
const typeSymbol = Symbol.for('@ipld/js-cid/CID') I can submit a pull request if there is a consensus on this. |
yeah, sure and we can go a bit further and test for constructor, the isCID method itself and some critical internal data/component that would fail for breaking changes. @mikeal how are you relying on the symbol for the new multiformats ? |
Suggestion to drop class-is dependency an implementing
isCID
locally came from the discussion in moxystudio/js-class-is#25Submitting issue here for further discussions.
@hugomrdias what do you mean by validating components ?
At the moment as far as I understand
isCID
just boils down to:Are you suggesting new CID.isCID should be something along these lines:
Or do you meant something like:
If later that would be pretty wonderful, and step towards #109. On the other hand it may break some assumptions about the availability of certain instance methods.
I think it would be better to avoid such a dramatic change of
isCID
and just let it be a glorifiedinstanceof
check. Instead I would propose to introduceasCID
static method as described in #111 (originally I wrote it up here, but decided it would be better to move into separate thread)The text was updated successfully, but these errors were encountered: