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

feat: add class-is module #84

Merged
merged 2 commits into from
Oct 18, 2018
Merged

feat: add class-is module #84

merged 2 commits into from
Oct 18, 2018

Conversation

vasco-santos
Copy link
Member

The instance of fails when using different versions of a module. This way, we end up with problems using this in other places, such as js-ipfs/core/ipns/publisher.js#L54.

In the context of js-ipfs/issues/1615. This is not a problem now, as it is only occurring with interface-datastore key. However, it may occur in a future release of this module.

@vasco-santos vasco-santos requested review from pgte and fsdiogo October 4, 2018 10:32
@ghost ghost assigned vasco-santos Oct 4, 2018
@ghost ghost added the status/in-progress In progress label Oct 4, 2018
Copy link
Member

@fsdiogo fsdiogo left a comment

Choose a reason for hiding this comment

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

👍

src/index.js Outdated
@@ -132,7 +133,7 @@ class PeerId {
}
}

exports = module.exports = PeerId
exports = module.exports = withIs(PeerId, { className: 'PeerId', symbolName: '@libp2p/js-peer-id/PeerId' })
Copy link
Member

Choose a reason for hiding this comment

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

There are a number of occasions in this file where we're accessing the non-wrapped PeerId class:

callback(null, new PeerId(digest, privKey))

return new PeerId(mh.fromHexString(str))

return new PeerId(buf)

return new PeerId(mh.fromB58String(str))

callback(null, new PeerId(digest, null, pubKey))

callback(null, new PeerId(digest, privKey, privKey.public))

callback(null, new PeerId(id, priv, pub))

These all need to be changed otherwise they create PeerId objects that don't have the '@libp2p/js-peer-id/PeerId' symbol and so aren't considered to be instances of PeerId when used with PeerId.isPeerId.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes! Thanks for noticing that.

I added PeerIdWithIs to all of them. However, I feel that there might be a better approach here. What do you think?

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor

@pgte pgte left a comment

Choose a reason for hiding this comment

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

LGTM! 👍

@pgte pgte merged commit d7e633a into master Oct 18, 2018
@ghost ghost removed the status/in-progress In progress label Oct 18, 2018
alanshaw pushed a commit to ipfs/js-ipfs that referenced this pull request Oct 29, 2018
As `instance of` fails using different versions of a module, it was changed to use `class-is`.

Needs:

- [x] [js-peer-id#84](libp2p/js-peer-id#84)
- [x] [interface-datastore#24](ipfs/interface-datastore#24)

Fixes #1615
@jacobheun jacobheun deleted the feat/add-class-is-module branch April 22, 2020 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants