Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

Only hash #717

Merged
merged 2 commits into from
Mar 15, 2018
Merged

Only hash #717

merged 2 commits into from
Mar 15, 2018

Conversation

daviddias
Copy link
Contributor

No description provided.

@ghost ghost assigned daviddias Mar 15, 2018
@ghost ghost added the in progress label Mar 15, 2018
@daviddias
Copy link
Contributor Author

Tested things locally, outstanding issues are related to #713

@daviddias daviddias merged commit 1137401 into master Mar 15, 2018
@ghost ghost removed the in progress label Mar 15, 2018
@daviddias daviddias deleted the only-hash branch March 15, 2018 15:52
@JonKrone
Copy link
Contributor

@disdavid Woohoo! Thanks a ton for the merge! 🎆 I'll go ahead and update any related work.

qs['cid-version'] = propOrProp(options, 'cid-version', 'cidVersion')
qs['raw-leaves'] = propOrProp(options, 'raw-leaves', 'rawLeaves')
qs['only-hash'] = propOrProp(options, 'only-hash', 'onlyHash')
qs.hash = propOrProp(options, 'hash', 'hashAlg')
Copy link

@AtkinsChang AtkinsChang Mar 23, 2018

Choose a reason for hiding this comment

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

Please don't directly assign qs which is a function parameters in API.
This will cause error if user pass read only object as option.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks @AtkinsChang. Did this break something that used to work? We've been assigning to qs like this for a few months now so perhaps it is not just the assignment if you've used any of those versions.

which is a function parameters in API

I'm sorry, I don't get what you mean here. Can you give a clear example?

Copy link

@AtkinsChang AtkinsChang Mar 24, 2018

Choose a reason for hiding this comment

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

@JonKrone
For example, in src/files/add.js:voptions is passed directly to createAddStream({ qs: options }).
In src/utils/send-files-stream:
line 34 options = options ? Object.assign({}, options, options.qs) : {}
line 76 const qs = options.qs || {}
So basically the qs is the options user pass to the api.

Copy link
Contributor

Choose a reason for hiding this comment

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

Because of line 34 like you mention, it looks like qs here is actually a copy of the options passed. I think that this avoids problems with a read-only options object. For example, the below doesn't cause any problems:

const obj = {}
Object.defineProperty(obj, 'color', {
  writable: false,
  value: 'red'
})
const options = Object.assign({}, obj)
options.color= 'rouge'
console.log(options.color) // prints 'rouge'

Did this break something that worked for you before?

Choose a reason for hiding this comment

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

Yes this is the currently workaround I use.
But I think the internal ipfs api should use a copy of user's option instead of modifying it directly. It is a good practice to avoid reassigning function arguments, which may cause user hard to debug in some situation, for example: shared options between different apis.

Copy link
Contributor

Choose a reason for hiding this comment

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

@AtkinsChang ipfs-api internally does use a copy of the user's options because of line 34 and does not mutate the options you pass in. Given that, I'm not sure this is the source of the problem you were having.

If you can reproduce it in some code please let me know or submit a PR with your proposed changes.

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.

3 participants