Files
react-native-devtools-frontend/front_end/component_docs/data_grid/adding-data.ts
T
Tim van der Lippe 868a2f738a Use top level await in component_docs
This cleans up the promise chaining and removes the need for nesting
the implementation in a separate function.

R=jacktfranklin@chromium.org

Change-Id: I76f1fcd7443a7673e1166cec2d7379543b811cef
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2618259
Reviewed-by: Jack Franklin <jacktfranklin@chromium.org>
Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org>
2021-01-08 16:21:37 +00:00

40 lines
1.3 KiB
TypeScript

// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import * as ComponentHelpers from '../../component_helpers/component_helpers.js';
import * as Components from '../../ui/components/components.js';
await ComponentHelpers.ComponentServerSetup.setup();
const component = new Components.DataGrid.DataGrid();
component.data = {
columns: [
{id: 'key', title: 'Key', widthWeighting: 1, visible: true, hideable: false},
{id: 'value', title: 'Value', widthWeighting: 1, visible: true, hideable: false},
],
rows: [{cells: [{columnId: 'key', value: 'foo', title: 'foo'}, {columnId: 'value', value: 'bar', title: 'bar'}]}],
activeSort: null,
};
document.getElementById('container')?.appendChild(component);
document.querySelector('#add')?.addEventListener('click', (event: Event) => {
event.preventDefault();
const key = Math.floor(Math.random() * 10);
const value = Math.floor(Math.random() * 10);
const randomDataRow = {
cells: [
{columnId: 'key', value: `Key: ${key}`, title: `Key: ${key}`},
{columnId: 'value', value: `Value: ${value}`, title: `Value: ${value}`},
],
};
component.data = {
...component.data,
rows: [...component.data.rows, randomDataRow],
};
});