mirror of
https://github.com/gosticks/react-bootstrap-table2.git
synced 2025-10-16 11:55:39 +00:00
refine the relation for props resolver and internal store
This commit is contained in:
parent
6f45ae7886
commit
47e807672f
@ -4,12 +4,14 @@ import cs from 'classnames';
|
||||
|
||||
import Header from './header';
|
||||
import Body from './body';
|
||||
import storeBase from './store/base';
|
||||
import Store from './store/base';
|
||||
import PropsBaseResolver from './props-resolver';
|
||||
|
||||
class BootstrapTable extends storeBase(Component) {
|
||||
class BootstrapTable extends PropsBaseResolver(Component) {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.validateProps();
|
||||
this.store = new Store(props);
|
||||
}
|
||||
|
||||
render() {
|
||||
@ -34,7 +36,7 @@ class BootstrapTable extends storeBase(Component) {
|
||||
<table className={ tableClass }>
|
||||
<Header columns={ columns } />
|
||||
<Body
|
||||
data={ this.data }
|
||||
data={ this.store.data }
|
||||
keyField={ keyField }
|
||||
columns={ columns }
|
||||
/>
|
||||
|
||||
@ -1,3 +1,6 @@
|
||||
export function columnSize(columns) {
|
||||
return columns.length;
|
||||
}
|
||||
export default ExtendBase =>
|
||||
class ColumnResolver extends ExtendBase {
|
||||
columnSize() {
|
||||
return this.props.columns.length;
|
||||
}
|
||||
};
|
||||
|
||||
@ -1,13 +1,13 @@
|
||||
import { columnSize } from './column-resolver';
|
||||
import ColumnResolver from './column-resolver';
|
||||
|
||||
export default ExtendBase =>
|
||||
class TableResolver extends ExtendBase {
|
||||
class TableResolver extends ColumnResolver(ExtendBase) {
|
||||
validateProps() {
|
||||
const { columns, keyField } = this.props;
|
||||
if (!keyField) {
|
||||
throw new Error('Please specify a field as key via keyField');
|
||||
}
|
||||
if (columnSize(columns) <= 0) {
|
||||
if (this.columnSize(columns) <= 0) {
|
||||
throw new Error('No any visible columns detect');
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,10 +1,6 @@
|
||||
import TableResolver from '../props-resolver';
|
||||
|
||||
export default ExtendBase =>
|
||||
class Store extends TableResolver(ExtendBase) {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
const { data } = this.props;
|
||||
this.data = data ? data.slice() : [];
|
||||
}
|
||||
};
|
||||
export default class Store {
|
||||
constructor(props) {
|
||||
const { data } = props;
|
||||
this.data = data ? data.slice() : [];
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user