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

version #43

Merged
merged 6 commits into from
Jan 8, 2016
Merged

version #43

merged 6 commits into from
Jan 8, 2016

Conversation

daviddias
Copy link
Member

  • cli
  • http-api
  • core
  • tests cli
  • tests http-api
  • tests core

exports.start = function (callback) {
// start IPFS and exports.ipfs = new IPFS()

exports.ipfs = new IPFS()
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, this looks like asking for trouble when the export is only available after start was called, also what will happen to module caching plus calling start twice?

Copy link
Member Author

Choose a reason for hiding this comment

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

the .ipfs is to be used by the http-api resources, which are only loaded after start is called (from routes), so there is no conflict. Did I get your question right?

Copy link
Member

Choose a reason for hiding this comment

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

Kind of, but why not just pass these resources through explicitly, this could easily break, or be miss used by someone not understanding these exports

@daviddias
Copy link
Member Author

going to make it all es6'ish before merging it :)

})

// load routes
require('./routes/version.js')
Copy link
Member

Choose a reason for hiding this comment

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

This could be much cleaner:

server.route(require('./routes/version.js')

// version.js
var resources = require('./../resources')

module.exports = {
  method: 'GET',
  path: '/api/v0/version',
  handler: resources.version.get
}

Copy link
Member Author

Choose a reason for hiding this comment

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

why is that "much" cleaner? If there was more than one route on that file I would have to go and

server.route(require('./routes/version.js').routeA)
server.route(require('./routes/version.js').routeB)
// etc

Meaning that I have to alter the route file and index.js, the way I have, I only have to open and modify one file. Also, having the server object available means I always have server methods at my hand.

Copy link
Member

Choose a reason for hiding this comment

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

It's not about that, could also change it to

require('./routes/version.js').forEach(server.route.bind(server)

// version.js
module.exports = [
  // my routes
]

The main issue I have your current implementation is that it introduces a circular dependency from this file to the routes files.

If you want to have the server object be available make it like this:

require('./routes/version.js')(server)

// version.js
server.route({...})

that way the circular dependency is removed

Copy link
Member Author

Choose a reason for hiding this comment

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

we could DI the server obj (and the IPFS core object), but I kind of like making available by knowing where to pick it from other then move it around. I've been doing this for a while, if it becomes complicated over time, I will reconsider your suggestion :)

const Command = require('ronin').Command
const IPFS = require('../../ipfs-core')
const debug = require('debug')
let log = debug('cli:id')
Copy link
Member

Choose a reason for hiding this comment

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

Can be const

@daviddias
Copy link
Member Author

Thank you for the CR @dignifiedquire :)

var repo = new IPFSRepo(config.repoPath)

self.daemon = function (callback) {
this.daemon = (callback) => {
Copy link
Member

Choose a reason for hiding this comment

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

You can drop the parens around callback

var self = this

if (!(self instanceof IPFS)) {
if (!(this instanceof IPFS)) {
Copy link
Member

Choose a reason for hiding this comment

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

If you do this check anyway, why not go class IPFS instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

I was not sure how classes worked underneath, was afraid that it would cause the same problem of method allocation during object initialisation and take a lot of unnecessary memory, but after checking, it seems there is no reason why to be concerned since it moves all the methods to .prototype of class.

@dignifiedquire
Copy link
Member

Thank you for the CR @dignifiedquire :)

I see code, I review

@daviddias daviddias force-pushed the feat/version/api+cli+core+tests branch from 35dee30 to b4fede0 Compare January 7, 2016 17:51
@daviddias daviddias force-pushed the feat/version/api+cli+core+tests branch from b4fede0 to a4e210f Compare January 7, 2016 17:52
daviddias added a commit that referenced this pull request Jan 8, 2016
@daviddias daviddias merged commit 8bf3da8 into master Jan 8, 2016
@daviddias daviddias deleted the feat/version/api+cli+core+tests branch January 8, 2016 13:22
MicrowaveDev pushed a commit to galtproject/js-ipfs that referenced this pull request May 22, 2020
fix: validate and coerce count param for read in HTTP API
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