-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathdata-service.js
More file actions
41 lines (34 loc) · 1.12 KB
/
data-service.js
File metadata and controls
41 lines (34 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { isFunction } from '../BootstrapBlazor/modules/utility.js'
export default class DataService {
static name = 'DataService';
registerUniverSheet(sheet) {
sheet.firstPush = true;
sheet.pushData = data => {
sheet.firstPush = false;
this._checkReceiveDataCallback();
return this._callback(data);
};
this._sheet = sheet;
}
registerReceiveDataCallback(callback) {
this._callback = callback;
}
getUniverSheet() {
this._checkUniverSheet();
return this._sheet;
}
async getDataAsync(data) {
this._checkUniverSheet();
return await this._sheet.invoke.invokeMethodAsync('TriggerPostData', data);
}
_checkUniverSheet() {
if (this._sheet === void 0) {
throw new Error('UniverSheet is not registered. Please call registerUniverSheet first');
}
}
_checkReceiveDataCallback() {
if (isFunction(this._callback) === false) {
throw new Error('Receive data callback is not registered. Please call registerReceiveDataCallback first');
}
}
}