Skip to content

Commit f84a92e

Browse files
committed
chore: use await for React15Tabulator also
1 parent c19b624 commit f84a92e

File tree

5 files changed

+69
-22
lines changed

5 files changed

+69
-22
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## [0.12.6] - 2020-04-29
1+
## [0.12.7] - 2020-04-29
22
- upgraded tabulator to 4.6.2
33
- fixed: use ReactDOM.render instead of renderToString
44

lib/React15Tabulator.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export default class extends React.Component<IProps, Partial<IState>> {
1010
htmlProps: any;
1111
mainId: string;
1212
table: any;
13-
componentDidMount(): void;
13+
componentDidMount(): Promise<void>;
1414
componentWillUnmount(): void;
1515
componentWillReceiveProps(props: IProps): void;
1616
pickValidHTMLProps: () => void;

lib/React15Tabulator.js

Lines changed: 64 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,42 @@ var __assign = (this && this.__assign) || function () {
2323
};
2424
return __assign.apply(this, arguments);
2525
};
26+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
27+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
28+
return new (P || (P = Promise))(function (resolve, reject) {
29+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
30+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
31+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
32+
step((generator = generator.apply(thisArg, _arguments || [])).next());
33+
});
34+
};
35+
var __generator = (this && this.__generator) || function (thisArg, body) {
36+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
37+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
38+
function verb(n) { return function (v) { return step([n, v]); }; }
39+
function step(op) {
40+
if (f) throw new TypeError("Generator is already executing.");
41+
while (_) try {
42+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
43+
if (y = 0, t) op = [op[0] & 2, t.value];
44+
switch (op[0]) {
45+
case 0: case 1: t = op; break;
46+
case 4: _.label++; return { value: op[1], done: false };
47+
case 5: _.label++; y = op[1]; op = [0]; continue;
48+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
49+
default:
50+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
51+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
52+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
53+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
54+
if (t[2]) _.ops.pop();
55+
_.trys.pop(); continue;
56+
}
57+
op = body.call(thisArg, _);
58+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
59+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
60+
}
61+
};
2662
exports.__esModule = true;
2763
var React = require("react");
2864
var ReactDOM = require("react-dom");
@@ -54,23 +90,34 @@ var default_1 = /** @class */ (function (_super) {
5490
return _this;
5591
}
5692
default_1.prototype.componentDidMount = function () {
57-
var domEle = ReactDOM.findDOMNode(this.ref); // mounted DOM element
58-
var that = this;
59-
var _a = this.props, columns = _a.columns, data = _a.data, options = _a.options;
60-
var propOptions = ConfigUtils_1.propsToOptions(this.props);
61-
new Tabulator(domEle, __assign(__assign(__assign(__assign({ columns: columns }, propOptions), { layout: 'fitColumns', // fit columns to width of table (optional)
62-
tableBuilding: function () {
63-
that.table = this; // keep table instance
64-
that.props.tableBuilding ? that.props.tableBuilding() : '';
65-
},
66-
dataLoaded: function () {
67-
that.props.dataLoaded ? that.props.dataLoaded() : '';
68-
}, invalidOptionWarnings: false }), options), { data: data }));
69-
// await table.setData(data);
70-
// console.log('- componentDidMount');
71-
if (data && data.length > 0) {
72-
this.setState({ data: data });
73-
}
93+
return __awaiter(this, void 0, void 0, function () {
94+
var domEle, that, _a, columns, data, options, propOptions;
95+
return __generator(this, function (_b) {
96+
switch (_b.label) {
97+
case 0:
98+
domEle = ReactDOM.findDOMNode(this.ref);
99+
that = this;
100+
_a = this.props, columns = _a.columns, data = _a.data, options = _a.options;
101+
return [4 /*yield*/, ConfigUtils_1.propsToOptions(this.props)];
102+
case 1:
103+
propOptions = _b.sent();
104+
new Tabulator(domEle, __assign(__assign(__assign(__assign({ columns: columns }, propOptions), { layout: 'fitColumns', // fit columns to width of table (optional)
105+
tableBuilding: function () {
106+
that.table = this; // keep table instance
107+
that.props.tableBuilding ? that.props.tableBuilding() : '';
108+
},
109+
dataLoaded: function () {
110+
that.props.dataLoaded ? that.props.dataLoaded() : '';
111+
}, invalidOptionWarnings: false }), options), { data: data }));
112+
// await table.setData(data);
113+
// console.log('- componentDidMount');
114+
if (data && data.length > 0) {
115+
this.setState({ data: data });
116+
}
117+
return [2 /*return*/];
118+
}
119+
});
120+
});
74121
};
75122
default_1.prototype.componentWillUnmount = function () {
76123
this.table.destroy();

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-tabulator",
3-
"version": "0.12.6",
3+
"version": "0.12.7",
44
"description": "React Tabulator is based on tabulator - a JS table library with many advanced features.",
55
"main": "lib/index.js",
66
"types": "lib/index.d.ts",

src/React15Tabulator.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ export default class extends React.Component<IProps, Partial<IState>> {
2323
mainId = `tabulator-${+new Date()}-${Math.floor(Math.random() * 9999999)}`; // random id
2424
table: any = null; // will be set once Tabulator instantiated
2525

26-
componentDidMount() {
26+
async componentDidMount() {
2727
const domEle: any = ReactDOM.findDOMNode(this.ref); // mounted DOM element
2828
const that = this;
2929
const { columns, data, options } = this.props;
30-
const propOptions = propsToOptions(this.props);
30+
const propOptions = await propsToOptions(this.props);
3131

3232
new Tabulator(domEle, {
3333
columns,

0 commit comments

Comments
 (0)