Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

RFC: expose types and utils in static context #902

Closed
lidel opened this issue Dec 4, 2018 · 1 comment · Fixed by #951
Closed

RFC: expose types and utils in static context #902

lidel opened this issue Dec 4, 2018 · 1 comment · Fixed by #951

Comments

@lidel
Copy link
Contributor

lidel commented Dec 4, 2018

I just found this, I'm curious why it was defined based on an instance of ipfs, rather than something static since it points at the statically defined types.

My specific use case is to do something like foo instanceof ipfs.types.CID but it happens in static functions or places where the ipfs instance isn't passed as a variable, i.e. where I don't easily have access to the "ipfs" variable, but have easy access to the result of
IPFS = require('ipfs'),

The current code does CID=require('cids') solely to allow this type check, which seems exactly the kind of example this change was intended to avoid.

Originally posted by @mitra42 in #406 (comment)

I remember having similar thoughts at least once (had to make fake instance just to access utils).

Perhaps we could at least support it in the static context by exposing data types and util functions on IPFS (the static constructor) as well.

Thoughts?

@lidel lidel changed the title Expose types and utils in static context RFC: expose types and utils in static context Dec 4, 2018
@alanshaw
Copy link
Contributor

alanshaw commented Dec 4, 2018

I am already +1 for this (ipfs/js-ipfs#1297 (comment))

alanshaw added a commit that referenced this issue Mar 5, 2019
Allows users to access these additional types and utilities without having to create an instance of the c
lient first.

BREAKING CHANGE: `ipfs.util.isIPFS` has moved to a static export and should be accessed via `const { isIPFS } = require('ipfs-http-client'). The modules available under `ipfs.types.*` have also become static exports. `ipfs.util.crypto` has been removed as it is not a dependency of `ipfs-http-client` so reduces the bundle size. If you need to use libp2p crypto primitives then please see the [js-libp2p-crypto](https://github.com/libp2p/js-libp2p-crypto) project for info on how to use it in your project. Finally `ipfs.util.getEndpointConfig` is now a direct instance method, `ipfs.getEndpointConfig`

resolves #902

License: MIT
Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>
@ghost ghost assigned alanshaw Mar 5, 2019
@ghost ghost added in progress and removed ready labels Mar 5, 2019
alanshaw added a commit that referenced this issue Mar 6, 2019
Allows users to access these additional types and utilities without having to create an instance of the c
lient first.

BREAKING CHANGE: `ipfs.util.isIPFS` has moved to a static export and should be accessed via `const { isIPFS } = require('ipfs-http-client'). The modules available under `ipfs.types.*` have also become static exports. `ipfs.util.crypto` has been removed as it is not a dependency of `ipfs-http-client` so reduces the bundle size. If you need to use libp2p crypto primitives then please see the [js-libp2p-crypto](https://github.com/libp2p/js-libp2p-crypto) project for info on how to use it in your project. Finally `ipfs.util.getEndpointConfig` is now a direct instance method, `ipfs.getEndpointConfig`

resolves #902

License: MIT
Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>
alanshaw added a commit that referenced this issue Mar 6, 2019
Allows users to access these additional types and utilities without having to create an instance of the client first.

resolves #902

BREAKING CHANGE: `ipfs.util.isIPFS` has moved to a static export and should be accessed via `const { isIPFS } = require('ipfs-http-client')`.

The modules available under `ipfs.types.*` have also become static exports.

`ipfs.util.crypto` has been removed as it is not a dependency of `ipfs-http-client` so reduces the bundle size. If you need to use libp2p crypto primitives then please see the [js-libp2p-crypto](https://github.com/libp2p/js-libp2p-crypto) project for info on how to use it in your project.

Finally `ipfs.util.getEndpointConfig` is now a direct instance method, `ipfs.getEndpointConfig`

License: MIT
Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>
@ghost ghost removed the in progress label Mar 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants