Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

feature request: include reference to IPFS inside node instance #3053

Closed
tabcat opened this issue May 28, 2020 · 3 comments
Closed

feature request: include reference to IPFS inside node instance #3053

tabcat opened this issue May 28, 2020 · 3 comments

Comments

@tabcat
Copy link
Contributor

tabcat commented May 28, 2020

Hi, I'd like to be able to access classes like CID from just an 'instance' of ipfs made from the .create method on the IPFS factory object.
My use case is that I have a package that exports a class that takes an instance of ipfs as a parameter. I want to use the CID class included with the IPFS package instead of having to require it. Adding a reference to the IPFS factory object from the ipfs node instance object is one way to enable this.

@tabcat tabcat added the need/triage Needs initial labeling and prioritization label May 28, 2020
@achingbrain
Copy link
Member

achingbrain commented Dec 3, 2020

Adding a reference to the IPFS factory object from the ipfs node instance object

This doesn't sound like a great idea, an instance should not have a reference to its factory.

I want to use the CID class included with the IPFS package instead of having to require it.

Could you expand a little more on why you would do that? It's bundled with IPFS as a top-level export, why not just require it?

const {
  CID
} = require('ipfs')

@achingbrain achingbrain added kind/feature and removed need/triage Needs initial labeling and prioritization labels Dec 3, 2020
@tabcat
Copy link
Contributor Author

tabcat commented Dec 7, 2020

Pardon my ignorance on this but it seems like Class instances in javascript all have references to their factories via .constructor. Is it different since IPFS is not a Class or is it a good rule? Explicitly making a reference to the factory for the ipfs instance does sound useless, except for being able to access those bundled Classes.

Could you expand a little more on why you would do that? It's bundled with IPFS as a top-level export, why not just require it?

I believe I just wished to inject CID with the IPFS instance. OrbitDB and my package that uses OrbitDB take an ipfs instance as a parameter to keep things simple for users. I was probably specifically looking to eliminate an older version of whats happening here, which is actually not that bad because I have to create those preceding CID instances anyway.

@achingbrain
Copy link
Member

it seems like Class instances in javascript all have references to their factories via .constructor

They have a reference to their constructor, but a factory function might not be the constructor:

class Foo {
  constructor () {

  }
}

function createFoo () {
  return new Foo()
}

IPFS is a class, but you get instances of it via the create factory method because it needs to do some async work before the node is ready to use (set up the repo, open ports, etc) which cannot be done in a constructor since they cannot be marked async.

OrbitDB and my package that uses OrbitDB take an ipfs instance as a parameter
I was probably specifically looking to eliminate an older version of whats happening here

In this project I would declare ipfs as a peer dependency and just require CID from it as per my previous comment above.

This also says to the user 'my project is compatible with this version of ipfs` and the user will get a warning if they don't declare a dep on ipfs at the right version.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants