-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement typescript loaders and use example module
- Loading branch information
Showing
8 changed files
with
363 additions
and
244 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
type sendRequestParams = { | ||
method: string, | ||
path: string, | ||
body: any | ||
} | ||
|
||
export function sendRequest(params: sendRequestParams): Promise<{ | ||
settings: { | ||
[key: string]: { | ||
userValue?: any | ||
value?: any | ||
type?: string | ||
} | ||
} | ||
}> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { sendRequest } from './send_request'; | ||
|
||
type Changes = { | ||
values: { | ||
[name: string]: any | ||
}, | ||
callback: (err: null, response?: any) => void | ||
} | ||
|
||
type UiSettingsApiResponse = { | ||
settings: { | ||
[key: string]: { | ||
userValue?: any | ||
value?: any | ||
type?: string | ||
} | ||
} | ||
} | ||
|
||
const NOOP_CHANGES: Changes = { | ||
values: {}, | ||
callback: () => {}, | ||
}; | ||
|
||
export class UiSettingsApi { | ||
private pendingChanges: Changes | null = null; | ||
private sendInProgress = false; | ||
|
||
private async flushPendingChanges() { | ||
if (!this.pendingChanges) { | ||
return; | ||
} | ||
|
||
if (this.sendInProgress) { | ||
return; | ||
} | ||
|
||
const changes = this.pendingChanges; | ||
this.pendingChanges = null; | ||
|
||
try { | ||
this.sendInProgress = true; | ||
changes.callback(null, await sendRequest({ | ||
method: 'POST', | ||
path: '/api/kibana/settings', | ||
body: { | ||
changes: changes.values | ||
}, | ||
})); | ||
} catch (error) { | ||
changes.callback(error); | ||
} finally { | ||
this.sendInProgress = false; | ||
this.flushPendingChanges(); | ||
} | ||
} | ||
|
||
batchSet(key: string, value: any): Promise<UiSettingsApiResponse> { | ||
return new Promise((resolve, reject) => { | ||
const prev = this.pendingChanges || NOOP_CHANGES; | ||
|
||
this.pendingChanges = { | ||
values: { | ||
...prev.values, | ||
[key]: value, | ||
}, | ||
|
||
callback(error, resp) { | ||
prev.callback(error, resp); | ||
|
||
if (error) { | ||
reject(error); | ||
} else { | ||
resolve(resp); | ||
} | ||
}, | ||
}; | ||
|
||
this.flushPendingChanges(); | ||
}); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.