Better warnings and more column accessor freedom

This commit is contained in:
Tanner Linsley
2016-10-26 00:43:42 -06:00
parent 0bb3f2421e
commit 5351f79293
3 changed files with 28 additions and 14 deletions

File diff suppressed because one or more lines are too long

2
react-table.js vendored

File diff suppressed because one or more lines are too long

View File

@@ -96,17 +96,20 @@ export default React.createClass({
}
const makeDecoratedColumn = (column) => {
const dcol = Object.assign({}, this.props.column, column)
if (typeof dcol.accessor === 'string') {
dcol.id = dcol.id || dcol.accessor
const accessorString = dcol.accessor
dcol.accessor = row => _.get(row, accessorString)
return dcol
}
if (!dcol.id) {
console.warn('No column ID found for column: ', dcol)
}
if (!dcol.accessor) {
console.warn('No column accessor found for column: ', dcol)
if (dcol.accessor && !dcol.id) {
console.warn(dcol)
throw new Error('A column id is required if using a non-string accessor for column above.')
}
dcol.accessor = d => undefined
return dcol
}