Skip to content
This repository has been archived by the owner on Dec 6, 2022. It is now read-only.

feat: simplify block to only be data and cid #31

Merged
merged 4 commits into from
Mar 20, 2017
Merged

feat: simplify block to only be data and cid #31

merged 4 commits into from
Mar 20, 2017

Conversation

dignifiedquire
Copy link
Member

@dignifiedquire
Copy link
Member Author

dignifiedquire commented Mar 15, 2017

ref ipfs/js-ipfs#787

@daviddias
Copy link
Member

@dignifiedquire do I need to say it again? no yarn.lock :(

Copy link
Member

@daviddias daviddias left a comment

Choose a reason for hiding this comment

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

  • remove yarn.lock
  • update to aegir 11 (I'm being fair 😇)

* @param {any} other
* @returns {bool}
*/
static isBlock (other) {
Copy link
Member

Choose a reason for hiding this comment

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

Still making my mind over this, but currently, I strongly feel that public module methods shouldn't be encapsulated in Class objects and made public with static.

I've seen a lot of cases of people starting to use static and then forgetting what it really means and start mutating the state.

Plus, it is way more understandable from a Node.js/CJS user if the "module.exports" is the only place that tells me what gets exported.

Copy link
Member Author

Choose a reason for hiding this comment

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

Declaring Block.isBlock = ... doesn't seem to be any better to me in terms of understanding.

Copy link
Member Author

Choose a reason for hiding this comment

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

also we started using this a while ago in modules like cid

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

fine

Copy link
Member Author

Choose a reason for hiding this comment

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

one bonus is that jsdoc picks up the right docs for this if we write it as static

Copy link
Member

Choose a reason for hiding this comment

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

hm.....

src/index.js Outdated
class Block {
constructor (data, cid) {
if (!data || !Buffer.isBuffer(data)) {
throw new Error('data must be a buffer')
Copy link
Member

Choose a reason for hiding this comment

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

first argument must be a Buffer

src/index.js Outdated
throw new Error('Block must be constructed with data')
}
if (!cid || !CID.isCID(cid)) {
throw new Error('cid must be a CID')
Copy link
Member

Choose a reason for hiding this comment

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

second argument must be a CID

@dignifiedquire
Copy link
Member Author

applied all cr except the static thing

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