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

docs/improve newcomers experience #723

Merged
merged 6 commits into from
Jan 25, 2017

Conversation

daviddias
Copy link
Member

No description provided.

@victorb
Copy link
Member

victorb commented Jan 25, 2017

➜  js-ipfs git:(docs/improve-newcomers-experience) ls
LICENSE      Makefile     README.md    ROADMAP.md   circle.yml   examples     gulpfile.js  img          node_modules package.json src          test
➜  js-ipfs git:(docs/improve-newcomers-experience) cd examples
➜  examples git:(docs/improve-newcomers-experience) ls
README.md         basics            bundle-browserify bundle-webpack    ipfm
➜  examples git:(docs/improve-newcomers-experience) cd basics
➜  basics git:(docs/improve-newcomers-experience) ls
hello.txt index.js
➜  basics git:(docs/improve-newcomers-experience) node index.js
{ version: '0.21.2', repo: '', commit: '' }
Error: no ipfs repo found
    at repo.exists (/Users/user/projects/ipfs/js-ipfs/src/core/utils.js:10:17)
    at /Users/user/projects/ipfs/js-ipfs/node_modules/fs-pull-blob-store/lib/index.js:67:9
    at FSReqWrap.oncomplete (fs.js:123:15)

Probably should init the ipfs repo by itself.

@daviddias
Copy link
Member Author

@victorbjelkholm great catch! completely escaped my eye

@daviddias
Copy link
Member Author

#723 (comment)
resolved

@daviddias
Copy link
Member Author

On the bundle-webpack example, after updating all the deps we get:

With alias of zlib-browserify-zlib-next

Uncaught TypeError: Cannot read property 'toString' of undefined
    at Object.eval (webpack:////Users/koruza/code/js-ipfs/~/browserify-zlib-next/lib/index.js?:9

Without alias of zlib-browserify-zlib-next

Uncaught TypeError: function Buffer(arg) {
  if (!(this instanceof Buffer)) {
    // Avoid going through an ArgumentsAdaptorTrampol...<omitted>...
} is not a function
    at Function.from (native)
    at toBn (webpack:////Users/koruza/code/js-ipfs/~/libp2p-crypto/src/crypto/util.js?:19:24)

@victorb
Copy link
Member

victorb commented Jan 25, 2017

@diasdavid just pushed a fix for this, to this branch.

We should probably put a note somewhere that we require ^webpack@2

@daviddias daviddias force-pushed the docs/improve-newcomers-experience branch from f5e24fc to b7ce4a7 Compare January 25, 2017 14:55
@daviddias
Copy link
Member Author

Thank you! Added a note of that to the Example and to the README.

@daviddias daviddias merged commit 88aeef4 into master Jan 25, 2017
@daviddias daviddias deleted the docs/improve-newcomers-experience branch January 25, 2017 14:59
@daviddias daviddias removed the status/in-progress In progress label Jan 25, 2017
const fs = require('fs')
const os = require('os')
const series = require('async/series')
const IPFS = require('../../src/core') // replace this by line below
Copy link
Member

Choose a reason for hiding this comment

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

"replace this by line below" should probably be expanded to "replace this by line below if you are running this example from outside the js-ipfs repository" just to be explicit about why you would replace it.

/*
* Create a new IPFS instance, using default repo (fs) on default path (~/.ipfs)
*/
const node = new IPFS(os.tmpDir() + '/' + new Date().toString())
Copy link
Member

Choose a reason for hiding this comment

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

Should use path.join instead of concatenating strings

* https://github.com/ipfs/interface-ipfs-core/tree/master/API/files
*/
(cb) => {
if (node.isOnline()) {
Copy link
Member

Choose a reason for hiding this comment

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

If the node is not online after doing goOnline, there must have been an error somewhere, no? We should either not need to have this here, or if we do, not add the file if we're not online.

Copy link
Member Author

@daviddias daviddias Jan 25, 2017

Choose a reason for hiding this comment

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

It's not mandatory to be online to add the files. But get what you say, I basically preserved this operation.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, sure, but in the previous step, we do go online, so either we're online here, or something bad happened.


console.log('\nAdded file:')
console.log(result[0])
fileMultihash = result[0].hash
Copy link
Member

Choose a reason for hiding this comment

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

Instead of doing mutation on the fileMultihash variable, you should be able to pass the value as a second parameter to the callback and then retrieve it in the next step, if I remember correctly.

Copy link
Member Author

@daviddias daviddias Jan 25, 2017

Choose a reason for hiding this comment

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

I know, I'm not a big fan of that, because then the tasks can't be easily swapped.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, all right, makes sense 👍

## Special note

In order to use js-ipfs in the browser, you need to replace the default `zlib` library by `browserify-zlib-next`, a full implementation of the native `zlib` package, full in Node.js.
See the package.json to learn how to do this and avoid this pitfall. More context on: https://github.com/ipfs/js-ipfs#use-in-the-browser-with-browserify-webpack-or-any-bundler
Copy link
Member

Choose a reason for hiding this comment

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

"see the package.json" for what? I'm not sure but probably you mean "see the webpack.config.js" for aliasing zlib to browserify-zlib-next no?

Copy link
Member Author

Choose a reason for hiding this comment

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

absolutely! 👍

@@ -0,0 +1,7 @@
'use strict'
Copy link
Member

Choose a reason for hiding this comment

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

If we're bundling this with webpack and stage-0 + react, files are already always running in strict mode.

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

Successfully merging this pull request may close these issues.

2 participants