-
Notifications
You must be signed in to change notification settings - Fork 299
Conversation
src/api/bitswap.js
Outdated
const promisify = require('promisify-es6') | ||
|
||
module.exports = (send) => { | ||
module.exports = (arg) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might be nicer to rename to bitswap/index.js
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initially I had some problems when I structured it like you are saying. But I don´t remember what was the problem. I will try again 😃
src/api/bitswap/stat.js
Outdated
send = requestAPI(arg) | ||
} else { | ||
throw new Error('Argument must be a send function or a config object.') | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems like the above boilerplate should be extracted into its own file and be reused, rather than copied into each file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I was thinking in extracting the config processing part in the IpfsAPI
function, and use it in all modules.
test/bitswap.spec.js
Outdated
@@ -50,13 +68,39 @@ describe('.bitswap', () => { | |||
}) | |||
}) | |||
|
|||
it('.stat (modular)', (done) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to find a way to not duplicate the tests, but rather reuse them and just pass in the two different versions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have any idea of how this could be done?
@nunofmn I like this approach, it builds nicely. Follow @dignifiedquire suggesting, making it modular should be about importing only what you need but also avoiding code duplication. Thanks! 🌟 |
Hi @nunofmn, any hopes of getting this PR finished? This will make the life so much easier for everyone and I would love to get this merged before other PR's are made :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lot's of good progress here @nunofmn !! :D I'm super excited about this PR (as you know :D)
README.md
Outdated
@@ -224,7 +224,12 @@ This means: | |||
- [`ipfs.id([callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/API/generic#id) | |||
- [`ipfs.version([callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/API/generic#version) | |||
- [`ipfs.ping()`](https://github.com/ipfs/interface-ipfs-core/tree/master/API/generic#ping) | |||
- [`ipfs.log()`](https://github.com/ipfs/interface-ipfs-core/tree/master/API/generic#log) | |||
|
|||
#### [log](https://github.com/ipfs/interface-ipfs-core/tree/master/API/generic) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove these headings.
See how it is done in line 212
README.md
Outdated
|
||
- [`ipfs.log.ls([callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/API/generic) | ||
- [`ipfs.log.tail([callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/API/generic) | ||
- [`ipfs.log.level(subsystem, level, [options, callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/API/generic) | ||
|
||
#### [key](https://github.com/ipfs/interface-ipfs-core/tree/master/API/key) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove these headings.
See how it is done in line 212
src/api/bitswap/index.js
Outdated
stat: require('./stat')(arg), | ||
unwant: require('./unwant')(arg) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be bubbled up.
src/bitswap/index.js
and not src/api/bitswap/index.js
src/api/bitswap/stat.js
Outdated
const moduleConfig = require('../../module-config') | ||
|
||
module.exports = (arg) => { | ||
const send = moduleConfig(arg) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do this step at the index.js
level. Otherwise, you are creating a 'send' instance for every API call.
And also, at the index.js, you should check if the arg
is already a send
instance, for when the user uses ipfs-api directly and not a subapi.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The main problem of doing this step at index.js
level is that will lose the capability of require individual sub-modules (for example, require('ipfs-api/bitswap/unwant')(config)
)
The moduleConfig
already checks if the arg
is a send
instance, or if is necessary to init one.
src/api/block/get.js
Outdated
} | ||
} catch (err) { | ||
return callback(err) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you refactor this into a function?
|
src/module-config.js
Outdated
} else { | ||
throw new Error('Argument must be a send function or a config object.') | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't seem to be correct. What if a user does const node = ipfsApi('/ip4/127.0.0.1/tcp/5001')
?
@nunofmn almost there :) |
examples/sub-module/package.json
Outdated
"babel-preset-babili": "^0.1.4", | ||
"babel-preset-env": "^1.5.2", | ||
"babili": "^0.1.4", | ||
"babili-webpack-plugin": "^0.1.1", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why so much babel? Shouldn't this module require any babel at all?
@@ -5,7 +5,7 @@ const promisify = require('promisify-es6') | |||
module.exports = (send) => { | |||
return promisify((callback) => { | |||
send({ | |||
path: 'commands' | |||
path: 'bitswap/stat' | |||
}, callback) | |||
}) | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting that git thinks this was a rename from commands.js
c67c760
to
4d810a0
Compare
Good results! Once we get ipfs/kubo#4008 it will even be better! :) |
repo - 684.56 - 232.02 | ||
swarm - 1324.18 - 527.03 | ||
update - 684.45 - 231.96 | ||
version - 684.21 - 231.88 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use commas in the comma separated values files :)
Also, add the units to the top.
d1dedc6
to
75f532d
Compare
75f532d
to
34d95a8
Compare
@@ -0,0 +1,25 @@ | |||
#!/bin/sh | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should have at least set -e
so it exits the entire script if there is a error
This has been an impressive refactor! Thank you @nunofmn for pulling this off. There is one failing test, not related with the changes itself. Needs to be investigated separately. Merging! |
Related to #544.
The structure will be similar to the
async
module structure, but to do this with minimal changes to the current structure, is necessary a "module init" step where the config is passed to therequest-api
inner module.The usage will be similar to the following:
dag