Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(table): improve provide/inject performance (addresses #4155) #4164

Merged
merged 57 commits into from Sep 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
4bd5d1c
perf(table): improve provide/inject performance
tmorehouse Sep 28, 2019
82d6946
Update thead.js
tmorehouse Sep 28, 2019
edecfed
Update tfoot.js
tmorehouse Sep 28, 2019
da8b269
Update tr.js
tmorehouse Sep 28, 2019
467c18f
Update td.js
tmorehouse Sep 28, 2019
a0977d5
Update td.js
tmorehouse Sep 28, 2019
ff1364a
Update tr.js
tmorehouse Sep 28, 2019
6117f67
Update tbody.js
tmorehouse Sep 28, 2019
c1c633d
Update thead.js
tmorehouse Sep 28, 2019
b5733e2
Update tfoot.js
tmorehouse Sep 28, 2019
62c8695
Update tfoot.js
tmorehouse Sep 28, 2019
d29eea5
Update tr.js
tmorehouse Sep 28, 2019
7be1cd5
Update td.js
tmorehouse Sep 28, 2019
5706b57
Update tr.js
tmorehouse Sep 28, 2019
2b06c4c
Update td.js
tmorehouse Sep 28, 2019
3eda218
Update td.js
tmorehouse Sep 28, 2019
ea5bf89
Update thead.js
tmorehouse Sep 28, 2019
6b71e01
Update tbody.js
tmorehouse Sep 28, 2019
f3e0a69
Update tfoot.js
tmorehouse Sep 28, 2019
0d9b095
Update tr.js
tmorehouse Sep 28, 2019
7a1b572
Update tr.js
tmorehouse Sep 28, 2019
f096f8c
Update tbody.js
tmorehouse Sep 28, 2019
19b9c67
Update tfoot.js
tmorehouse Sep 28, 2019
7b5e3fb
Update thead.js
tmorehouse Sep 28, 2019
590f543
Update tr.js
tmorehouse Sep 28, 2019
f996e61
Update thead.js
tmorehouse Sep 28, 2019
185423e
Update td.js
tmorehouse Sep 28, 2019
c94fbfe
Update td.js
tmorehouse Sep 28, 2019
532903b
Update tr.js
tmorehouse Sep 28, 2019
4ce291f
Update td.js
tmorehouse Sep 28, 2019
e826b17
Update tr.js
tmorehouse Sep 28, 2019
18d8e30
Update td.js
tmorehouse Sep 28, 2019
dce051e
Update tr.js
tmorehouse Sep 28, 2019
fc542c6
Update thead.js
tmorehouse Sep 28, 2019
63434fd
Update tbody.js
tmorehouse Sep 28, 2019
08ca596
Update tfoot.js
tmorehouse Sep 28, 2019
1a13562
Update td.js
tmorehouse Sep 28, 2019
1ee5cb6
Update tr.js
tmorehouse Sep 28, 2019
44e916b
Update tbody.js
tmorehouse Sep 28, 2019
df677e2
Update tfoot.js
tmorehouse Sep 28, 2019
bf62ad8
Update thead.js
tmorehouse Sep 28, 2019
f4bafcc
Update thead.js
tmorehouse Sep 28, 2019
6f4b9fb
Update tfoot.js
tmorehouse Sep 28, 2019
b9f8786
Update tbody.js
tmorehouse Sep 28, 2019
8da2044
Update thead.js
tmorehouse Sep 28, 2019
95a6ba6
Update tfoot.js
tmorehouse Sep 28, 2019
5d0538b
Update tbody.js
tmorehouse Sep 28, 2019
fe62da1
Update tbody.js
tmorehouse Sep 28, 2019
3ef45ef
Update tfoot.js
tmorehouse Sep 28, 2019
4b5e064
Update td.js
tmorehouse Sep 28, 2019
bcc6c2b
Update td.js
tmorehouse Sep 28, 2019
ea60ae2
Update tfoot.js
tmorehouse Sep 28, 2019
c1b53f1
Update thead.js
tmorehouse Sep 28, 2019
467fd3f
Update tbody.js
tmorehouse Sep 28, 2019
d5b08c3
Merge branch 'dev' into tmorehouse/table-perf
tmorehouse Sep 28, 2019
d9d85b6
Merge branch 'dev' into tmorehouse/table-perf
tmorehouse Sep 29, 2019
a646f33
Merge branch 'dev' into tmorehouse/table-perf
tmorehouse Sep 30, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 30 additions & 2 deletions src/components/table/tbody.js
Expand Up @@ -19,16 +19,44 @@ export const BTbody = /*#__PURE__*/ Vue.extend({
inheritAttrs: false,
provide() {
return {
bvTableTbody: this
bvTableRowGroup: this
}
},
inject: {
bvTable: {
default: null
// Sniffed by <b-tr> / <b-td> / <b-th>
default() /* istanbul ignore next */ {
return {}
}
}
},
props,
computed: {
isTbody() {
// Sniffed by <b-tr> / <b-td> / <b-th>
return true
},
isDark() {
// Sniffed by <b-tr> / <b-td> / <b-th>
return this.bvTable.dark
},
isStacked() {
// Sniffed by <b-tr> / <b-td> / <b-th>
return this.bvTable.isStacked
},
isResponsive() {
// Sniffed by <b-tr> / <b-td> / <b-th>
return this.bvTable.isResponsive
},
isStickyHeader() {
// Sniffed by <b-tr> / <b-td> / <b-th>
// Sticky headers are only supported in thead
return false
},
tableVariant() /* istanbul ignore next: Not currently sniffed in tests */ {
// Sniffed by <b-tr> / <b-td> / <b-th>
return this.bvTable.tableVariant
},
isTransitionGroup() {
return this.tbodyTransitionProps || this.tbodyTransitionHandlers
},
Expand Down
81 changes: 40 additions & 41 deletions src/components/table/td.js
Expand Up @@ -45,21 +45,10 @@ export const BTd = /*#__PURE__*/ Vue.extend({
mixins: [normalizeSlotMixin],
inheritAttrs: false,
inject: {
// Injections for feature / attribute detection
bvTable: {
default: null
},
bvTableTbody: {
default: null
},
bvTableThead: {
default: null
},
bvTableTfoot: {
default: null
},
bvTableTr: {
default: null
default() /* istanbul ignore next */ {
return {}
}
}
},
props,
Expand All @@ -68,72 +57,82 @@ export const BTd = /*#__PURE__*/ Vue.extend({
// Overridden by <b-th>
return 'td'
},
inTbody() {
return this.bvTableTr.inTbody
},
inThead() {
return this.bvTableTr.inThead
},
inTfoot() {
return this.bvTableTr.inTfoot
},
isDark() {
return this.bvTable && this.bvTable.dark
return this.bvTableTr.isDark
},
isStacked() {
return this.bvTable && this.bvTable.isStacked
return this.bvTableTr.isStacked
},
isStackedCell() {
// We only support stacked-heading in tbody in stacked mode
return this.bvTableTbody && this.isStacked
return this.inTbody && this.isStacked
},
isResponsive() {
return this.bvTable && this.bvTable.isResponsive && !this.isStacked
return this.bvTableTr.isResponsive
},
isStickyHeader() {
// Needed to handle header background classes, due to lack of
// background color inheritance with Bootstrap v4 table CSS
// Sticky headers only apply to cells in table `thead`
return (
!this.isStacked &&
this.bvTable &&
this.bvTableThead &&
this.bvTableTr &&
this.bvTable.stickyHeader
)
return this.bvTableTr.isStickyHeader
},
isStickyColumn() {
// Needed to handle header background classes, due to lack of
// background color inheritance with Bootstrap v4 table CSS
// Sticky column cells are only available in responsive
// mode (horizontal scrolling) or when sticky header mode
// Applies to cells in `thead`, `tbody` and `tfoot`
return (
(this.isResponsive || this.isStickyHeader) &&
this.stickyColumn &&
!this.isStacked &&
this.bvTable &&
this.bvTableTr
)
return !this.isStacked && (this.isResponsive || this.isStickyHeader) && this.stickyColumn
},
rowVariant() {
return this.bvTableTr.variant
},
headVariant() {
return this.bvTableTr.headVariant
},
footVariant() /* istanbul ignore next: need to add in tests for footer variant */ {
return this.bvTableTr.footVariant
},
tableVariant() {
return this.bvTableTr.tableVariant
},
computedColspan() {
return parseSpan(this.colspan)
},
computedRowspan() {
return parseSpan(this.rowspan)
},
cellClasses() {
// We use computed props here for improved performance by caching
// the results of the string interpolation
// TODO: need to add handling for footVariant
let variant = this.variant
if (
(!variant && this.isStickyHeader && !this.bvTableThead.headVariant) ||
(!variant && this.isStickyHeader && !this.headVariant) ||
(!variant && this.isStickyColumn)
) {
// Needed for sticky-header mode as Bootstrap v4 table cells do
// not inherit parent's background-color. Boo!
variant = this.bvTableTr.variant || this.bvTable.tableVariant || 'b-table-default'
variant = this.rowVariant || this.tableVariant || 'b-table-default'
}
return [
variant ? `${this.isDark ? 'bg' : 'table'}-${variant}` : null,
this.isStickyColumn ? 'b-table-sticky-column' : null
]
},
computedColspan() {
return parseSpan(this.colspan)
},
computedRowspan() {
return parseSpan(this.rowspan)
},
cellAttrs() {
// We use computed props here for improved performance by caching
// the results of the object spread (Object.assign)
const headOrFoot = this.bvTableThead || this.bvTableTfoot
const headOrFoot = this.inThead || this.inTfoot
// Make sure col/rowspan's are > 0 or null
const colspan = this.computedColspan
const rowspan = this.computedRowspan
Expand Down
32 changes: 30 additions & 2 deletions src/components/table/tfoot.js
Expand Up @@ -15,16 +15,44 @@ export const BTfoot = /*#__PURE__*/ Vue.extend({
inheritAttrs: false,
provide() {
return {
bvTableTfoot: this
bvTableRowGroup: this
}
},
inject: {
bvTable: {
default: null
// Sniffed by <b-tr> / <b-td> / <b-th>
default() /* istanbul ignore next */ {
return {}
}
}
},
props,
computed: {
isTfoot() {
// Sniffed by <b-tr> / <b-td> / <b-th>
return true
},
isDark() /* istanbul ignore next: Not currently sniffed in tests */ {
// Sniffed by <b-tr> / <b-td> / <b-th>
return this.bvTable.dark
},
isStacked() {
// Sniffed by <b-tr> / <b-td> / <b-th>
return this.bvTable.isStacked
},
isResponsive() {
// Sniffed by <b-tr> / <b-td> / <b-th>
return this.bvTable.isResponsive
},
isStickyHeader() {
// Sniffed by <b-tr> / <b-td> / <b-th>
// Sticky headers are only supported in thead
return false
},
tableVariant() /* istanbul ignore next: Not currently sniffed in tests */ {
// Sniffed by <b-tr> / <b-td> / <b-th>
return this.bvTable.tableVariant
},
tfootClasses() {
return [this.footVariant ? `thead-${this.footVariant}` : null]
},
Expand Down
35 changes: 33 additions & 2 deletions src/components/table/thead.js
Expand Up @@ -3,6 +3,7 @@ import normalizeSlotMixin from '../../mixins/normalize-slot'

export const props = {
headVariant: {
// Also sniffed by <b-tr> / <b-td> / <b-th>
type: String, // supported values: 'lite', 'dark', or null
default: null
}
Expand All @@ -15,16 +16,46 @@ export const BThead = /*#__PURE__*/ Vue.extend({
inheritAttrs: false,
provide() {
return {
bvTableThead: this
bvTableRowGroup: this
}
},
inject: {
bvTable: {
default: null
// Sniffed by <b-tr> / <b-td> / <b-th>
default() /* istanbul ignore next */ {
return {}
}
}
},
props,
computed: {
isThead() {
// Sniffed by <b-tr> / <b-td> / <b-th>
return true
},
isDark() {
// Sniffed by <b-tr> / <b-td> / <b-th>
return this.bvTable.dark
},
isStacked() {
// Sniffed by <b-tr> / <b-td> / <b-th>
return this.bvTable.isStacked
},
isResponsive() {
// Sniffed by <b-tr> / <b-td> / <b-th>
return this.bvTable.isResponsive
},
isStickyHeader() {
// Sniffed by <b-tr> / <b-td> / <b-th>
// Needed to handle header background classes, due to lack of
// background color inheritance with Bootstrap v4 table CSS
// Sticky headers only apply to cells in table `thead`
return !this.isStacked && this.bvTable.stickyHeader
},
tableVariant() {
// Sniffed by <b-tr> / <b-td> / <b-th>
return this.bvTable.tableVariant
},
theadClasses() {
return [this.headVariant ? `thead-${this.headVariant}` : null]
},
Expand Down
42 changes: 39 additions & 3 deletions src/components/table/tr.js
Expand Up @@ -19,14 +19,50 @@ export const BTr = /*#__PURE__*/ Vue.extend({
}
},
inject: {
bvTable: {
default: null
bvTableRowGroup: {
defaut() /* istanbul ignore next */ {
return {}
}
}
},
props,
computed: {
inTbody() {
// Sniffed by <b-td> / <b-th>
return this.bvTableRowGroup.isTbody
},
inThead() {
// Sniffed by <b-td> / <b-th>
return this.bvTableRowGroup.isThead
},
inTfoot() {
// Sniffed by <b-td> / <b-th>
return this.bvTableRowGroup.isTfoot
},
isDark() {
return this.bvTable && this.bvTable.dark
// Sniffed by <b-td> / <b-th>
return this.bvTableRowGroup.isDark
},
isStacked() {
// Sniffed by <b-td> / <b-th>
return this.bvTableRowGroup.isStacked
},
isResponsive() {
// Sniffed by <b-td> / <b-th>
return this.bvTableRowGroup.isResponsive
},
isStickyHeader() {
// Sniffed by <b-td> / <b-th>
// Sticky headers are only supported in thead
return this.bvTableRowGroup.isStickyHeader
},
tableVariant() {
// Sniffed by <b-td> / <b-th>
return this.bvTableRowGroup.tableVariant
},
headVariant() {
// Sniffed by <b-td> / <b-th>
return this.bvTableRowGroup.headVariant
},
trClasses() {
return [this.variant ? `${this.isDark ? 'bg' : 'table'}-${this.variant}` : null]
Expand Down