Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.

Commit

Permalink
chore: test bundle code rather than all of ipfs (#15)
Browse files Browse the repository at this point in the history
its very mock heavy, but our code depends on _all_ the possible
ways of connecting to ipfs, our tests become horrible without some
judicious mocking out of dependencies.

It means we can now focus our tests on the logic of this module
rather than elaborate ipfs init tests. Also our tests no longer
fail if you happen to be running an ipfs daemon which is nice.

Also adds option to try accessing ipfs directly from companion
seperate from window.ipfs, and will try js-ipfs-api on the current
origin before trying the default value


License: MIT
Signed-off-by: Oli Evans <oli@tableflip.io>
  • Loading branch information
olizilla authored Oct 4, 2018
1 parent bb63d09 commit 4c5e520
Show file tree
Hide file tree
Showing 17 changed files with 4,623 additions and 8,274 deletions.
8 changes: 8 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"presets": [
["env", {
"modules": false
}],
"react-app"
]
}
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@

See https://reduxbundler.com for more info on the wonders of redux bundles.

This will try to use `window.ipfs` from [IPFS Companion](https://github.com/ipfs-shipyard/ipfs-companion). If not available, tries to connect to `js-ipfs-api`. The developer can also enable `js-ipfs` as a fallback.
This module tries to connect to IPFS via multiple providers, in order:

- `ipfs-companion` the IPFS instance from [IPFS Companion](https://github.com/ipfs-shipyard/ipfs-companion) directly.
- `window.ipfs` in the current page via [IPFS Companion](https://github.com/ipfs-shipyard/ipfs-companion).
- `js-ipfs-api` with either a user provided `apiAddress`, the current origin, or the default `/ip4/127.0.0.1/tcp/5001` address.
- `js-ipfs` **disabled by default**. Pass `tryJsIpfs: true, getJsIpfs: () => Promise` to enable it. See [Enable js-ipfs](#enable-js-ipfs)

## Usage

Expand All @@ -22,6 +27,7 @@ import ipfsBundle from 'ipfs-redux-bundle'
export default composeBundles(
ipfsBundle({
// These are the defaults:
tryCompanion: true, // set false to bypass ipfs-companion verification
tryWindow: true, // set false to bypass window.ipfs verification
tryApi: true, // set false to bypass js-ipfs-api verification. Uses data from ipfsApi variable in localStorage
tryJsIpfs: false, // set true to attempt js-ipfs initialisation.
Expand Down Expand Up @@ -54,6 +60,20 @@ export default connect(
)
```

### Enable js-ipfs

To enable js-ipfs, intialise the bundle with the following opts

```js
ipfsBundle({
tryJsIpfs: true,
getJsIpfs: () => import('ipfs')
})
```

- `tryJsIpfs` should be set to `true`
- `getJsIpfs` should be a function that returns a promise that resolves with a `JsIpfs` constructor. This works well with [dynamic `import()`](https://developers.google.com/web/updates/2017/11/dynamic-import), so you can lazily load js-ipfs when it is needed.

## API

Adds the following methods to the redux store.
Expand Down
301 changes: 0 additions & 301 deletions index.js

This file was deleted.

Loading

0 comments on commit 4c5e520

Please sign in to comment.