Skip to content

Commit

Permalink
fix: suggest ipfs-provider for window.ipfs fallback (#207)
Browse files Browse the repository at this point in the history
  • Loading branch information
lidel authored May 10, 2020
1 parent 24da7fb commit 296b3aa
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions docs/how-to/companion-window-ipfs.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ Learn about exposing IPFS API in IPFS Companion via "window.ipfs".

IPFS Companion 2.11 stopped injecting `window.ipfs`. It will be restored after the [move to JS API with async await and async iterables](https://github.com/ipfs-shipyard/ipfs-companion/issues/843), with a likely ETA of Q3 2020. This page is provided for reference only.

:::

<!-- below disclaimer will be restored when window.ipfs injection resumes
### Disclaimer
There is a substantial amount of [ongoing work for this interface](https://github.com/ipfs-shipyard/ipfs-companion/issues/589). Want to help with shaping it? See [#589](https://github.com/ipfs-shipyard/ipfs-companion/issues/589) and [issues with the `area/window-ipfs` label](https://github.com/ipfs-shipyard/ipfs-companion/labels/area%2Fwindow-ipfs).
The interface is experimental and might change: there is a substantial amount of [ongoing work](https://github.com/ipfs-shipyard/ipfs-companion/issues/589). Want to help with shaping it? See [#589](https://github.com/ipfs-shipyard/ipfs-companion/issues/589) and [issues with the `area/window-ipfs` label](https://github.com/ipfs-shipyard/ipfs-companion/labels/area%2Fwindow-ipfs).
-->

The interface is experimental and might change. Use [window.ipfs-fallback](https://www.npmjs.com/package/window.ipfs-fallback) to ensure your app follows any future changes
:::

## Background

Expand All @@ -45,6 +45,10 @@ if (window.ipfs && window.ipfs.enable) {

To add and get content, you could update the above example to do something like this:

<!-- TODO: update below example to use async iterators:
https://blog.ipfs.io/2020-02-01-async-await-refactor/
-->

```js
if (window.ipfs && window.ipfs.enable) {
try {
Expand All @@ -67,6 +71,12 @@ if (window.ipfs && window.ipfs.enable) {
}
```

::: tip

Use [ipfs-provider](https://github.com/ipfs-shipyard/ipfs-provider) to ensure your app follows any future changes of this interface. It reduces amount of code needed to implement a robust fallback to HTTP API or embedded js-ipfs when `window.ipfs` is not available.

:::

### Error codes

Errors returned by IPFS proxy can be identified by the value of the `code` attribute.
Expand Down

0 comments on commit 296b3aa

Please sign in to comment.