-
Notifications
You must be signed in to change notification settings - Fork 16
feat: simplify block to only be data and cid #31
Conversation
ref ipfs/js-ipfs#787 |
@dignifiedquire do I need to say it again? no yarn.lock :( |
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.
- remove yarn.lock
- update to aegir 11 (I'm being fair 😇)
* @param {any} other | ||
* @returns {bool} | ||
*/ | ||
static isBlock (other) { |
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.
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.
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.
Declaring Block.isBlock = ...
doesn't seem to be any better to me in terms of understanding.
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.
also we started using this a while ago in modules like cid
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.
fine
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.
one bonus is that jsdoc picks up the right docs for this if we write it as static
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.
hm.....
src/index.js
Outdated
class Block { | ||
constructor (data, cid) { | ||
if (!data || !Buffer.isBuffer(data)) { | ||
throw new Error('data must be a buffer') |
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.
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') |
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.
second argument must be a CID
applied all cr except the static thing |
Ref ipfs/js-ipfs-repo#123