Permalink
Browse files

perf(id mixin): make localId_ a computed field

  • Loading branch information...
pi0 committed Jan 25, 2018
1 parent 74df54e commit 873b0e7164a834cb5cc4f62696e453c37dcf0ce0
Showing with 8 additions and 11 deletions.
  1. +8 −11 src/mixins/id.js
@@ -10,24 +10,21 @@ export default {
default: null
}
},
data () {
return {
localId_: null
}
},
mounted () {

This comment has been minimized.

@tmorehouse

tmorehouse Nov 12, 2018

Member

we needed this in mount, so that the ID would be generated on client side after mount (and after ssr rehydration), and needed the ID in data() to trigger reactive rendering of the ID once we know the client side Vue uid.

if (!this.$isServer && !this.id && typeof this._uid !== 'undefined') {
this.localId_ = `__BVID__${this._uid}_`
}
},
methods: {
safeId (suffix = '') {
const id = this.id || this.localId_ || null
if (!id) {
return null
}
suffix = String(suffix).replace(/\s+/g, '_')
return suffix ? `${id}_${suffix}` : id
return suffix ? id + '_' + suffix : id
}
},
computed: {
localId_ () {
if (!this.$isServer && !this.id && typeof this._uid !== 'undefined') {
return '__BVID__' + this._uid
}
}
}
}

0 comments on commit 873b0e7

Please sign in to comment.