Skip to content

Commit

Permalink
fix(vuex): "_isBuffer" is not defined on the instance warning from Vue,
Browse files Browse the repository at this point in the history
closes #955
  • Loading branch information
Guillaume Chau committed Apr 5, 2019
1 parent cfee9f6 commit 2ff9785
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/backend/clone.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,21 @@ try {
NativePromise = function () {}
}

export default function clone (parent, { circular = true, depth = Infinity, prototype, includeNonEnumerable } = {}) {
export default function clone (parent, {
circular = true,
depth = Infinity,
prototype,
includeNonEnumerable
} = {}) {
// maintain two arrays for circular references, where corresponding parents
// and children have the same index
var allParents = []
var allChildren = []

var useBuffer = typeof Buffer !== 'undefined' && typeof Buffer.isBuffer === 'function'

const isBuffer = typeof window !== 'undefined' ? browserIsBuffer : Buffer.isBuffer

// recurse this function so we don't reset allParents and allChildren
function _clone (parent, depth) {
// cloning null always returns null
Expand Down Expand Up @@ -64,7 +71,7 @@ export default function clone (parent, { circular = true, depth = Infinity, prot
if (parent.lastIndex) child.lastIndex = parent.lastIndex
} else if (clone.__isDate(parent)) {
child = new Date(parent.getTime())
} else if (useBuffer && Buffer.isBuffer(parent)) {
} else if (useBuffer && isBuffer(parent)) {
if (Buffer.from) {
// Node.js >= 5.10.0
child = Buffer.from(parent)
Expand Down Expand Up @@ -191,3 +198,7 @@ clone.__getRegExpFlags = __getRegExpFlags
function _instanceof (obj, type) {
return type != null && obj instanceof type
}

function browserIsBuffer (b) {
return !!(b != null && '_isBuffer' in b && b._isBuffer)
}

3 comments on commit 2ff9785

@natesire
Copy link

Choose a reason for hiding this comment

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

How do you feel about changing the error from "on the instance warning" to something else... Ideas are the following... Instance and Warning make me think of Object Instances or Server Instances.

  1. undefined on component
  2. undefined in template
  3. undefined inside <script>

@Akryum
Copy link
Member

@Akryum Akryum commented on 2ff9785 Apr 5, 2019

Choose a reason for hiding this comment

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

What are you talking about? 😸

@natesire
Copy link

Choose a reason for hiding this comment

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

We were on Slack today. And I wasn't sure what that error meant, right away. Someone explained it to me. So I suggested that we rewrite the error to be a little more friendly to the newbies like myself.

Please sign in to comment.