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 Header from './header';
|
||||||
import Body from './body';
|
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) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.validateProps();
|
this.validateProps();
|
||||||
|
this.store = new Store(props);
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
@ -34,7 +36,7 @@ class BootstrapTable extends storeBase(Component) {
|
|||||||
<table className={ tableClass }>
|
<table className={ tableClass }>
|
||||||
<Header columns={ columns } />
|
<Header columns={ columns } />
|
||||||
<Body
|
<Body
|
||||||
data={ this.data }
|
data={ this.store.data }
|
||||||
keyField={ keyField }
|
keyField={ keyField }
|
||||||
columns={ columns }
|
columns={ columns }
|
||||||
/>
|
/>
|
||||||
|
|||||||
@ -1,3 +1,6 @@
|
|||||||
export function columnSize(columns) {
|
export default ExtendBase =>
|
||||||
return columns.length;
|
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 =>
|
export default ExtendBase =>
|
||||||
class TableResolver extends ExtendBase {
|
class TableResolver extends ColumnResolver(ExtendBase) {
|
||||||
validateProps() {
|
validateProps() {
|
||||||
const { columns, keyField } = this.props;
|
const { columns, keyField } = this.props;
|
||||||
if (!keyField) {
|
if (!keyField) {
|
||||||
throw new Error('Please specify a field as key via 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');
|
throw new Error('No any visible columns detect');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,10 +1,6 @@
|
|||||||
import TableResolver from '../props-resolver';
|
export default class Store {
|
||||||
|
|
||||||
export default ExtendBase =>
|
|
||||||
class Store extends TableResolver(ExtendBase) {
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
const { data } = props;
|
||||||
const { data } = this.props;
|
|
||||||
this.data = data ? data.slice() : [];
|
this.data = data ? data.slice() : [];
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user