Skip to content
This repository has been archived by the owner on Aug 11, 2021. It is now read-only.

Commit

Permalink
fix: replace constructor.name with instanceof
Browse files Browse the repository at this point in the history
This is part of ongoing effort to properly fix ipfs/js-ipfs#1131.
  • Loading branch information
ya7ya authored and vmx committed Mar 8, 2018
1 parent 2b1c188 commit 881d572
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/dag-link/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const DAGLink = require('./index')

function isDagLink (link) {
return link && link.constructor && link.constructor.name === 'DAGLink'
return link && link.constructor && link instanceof DAGLink
}

function createDagLinkFromB58EncodedHash (link) {
Expand Down
5 changes: 3 additions & 2 deletions src/dag-node/addLink.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ const cloneData = dagNodeUtil.cloneData
const toDAGLink = dagNodeUtil.toDAGLink
const DAGLink = require('./../dag-link')
const create = require('./create')
const DAGNode = require('./index')

function addLink (node, link, callback) {
const links = cloneLinks(node)
const data = cloneData(node)

if ((link.constructor && link.constructor.name === 'DAGLink')) {
if ((link.constructor && link instanceof DAGLink)) {
// It's a DAGLink instance
// no need to do anything
} else if (link.constructor && link.constructor.name === 'DAGNode') {
} else if (link.constructor && link instanceof DAGNode) {
// It's a DAGNode instance
// convert to link
link = toDAGLink(link)
Expand Down
2 changes: 1 addition & 1 deletion src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function serialize (node, callback) {
let serialized

// If the node is not an instance of a DAGNode, the link.hash might be a Base58 encoded string; decode it
if (node.constructor.name !== 'DAGNode' && node.links) {
if (!(node instanceof DAGNode) && node.links) {
node.links = node.links.map((link) => {
return DAGLink.util.isDagLink(link) ? link : DAGLink.util.createDagLinkFromB58EncodedHash(link)
})
Expand Down

0 comments on commit 881d572

Please sign in to comment.