Skip to content

Commit 0f70965

Browse files
authored
chore: update JSDoc to use fetch in the data provider (#3098) (#3099)
1 parent 230206c commit 0f70965

2 files changed

Lines changed: 32 additions & 50 deletions

File tree

‎packages/grid/src/vaadin-grid.d.ts‎

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -253,38 +253,29 @@ export interface GridEventMap<TItem> extends HTMLElementEventMap, GridCustomEven
253253
* in the second argument of the data provider callback:__
254254
*
255255
* ```javascript
256-
* grid.dataProvider = function(params, callback) {
257-
* const url = 'https://api.example/data' +
258-
* '?page=' + params.page + // the requested page index
259-
* '&per_page=' + params.pageSize; // number of items on the page
260-
* const xhr = new XMLHttpRequest();
261-
* xhr.onload = function() {
262-
* const response = JSON.parse(xhr.responseText);
263-
* callback(
264-
* response.employees, // requested page of items
265-
* response.totalSize // total number of items
266-
* );
267-
* };
268-
* xhr.open('GET', url, true);
269-
* xhr.send();
256+
* grid.dataProvider = ({page, pageSize}, callback) => {
257+
* // page: the requested page index
258+
* // pageSize: number of items on one page
259+
* const url = `https://api.example/data?page=${page}&per_page=${pageSize}`;
260+
*
261+
* fetch(url)
262+
* .then((res) => res.json())
263+
* .then(({ employees, totalSize }) => {
264+
* callback(employees, totalSize);
265+
* });
270266
* };
271267
* ```
272268
*
273269
* __Alternatively, you can use the `size` property to set the total number of items:__
274270
*
275271
* ```javascript
276272
* grid.size = 200; // The total number of items
277-
* grid.dataProvider = function(params, callback) {
278-
* const url = 'https://api.example/data' +
279-
* '?page=' + params.page + // the requested page index
280-
* '&per_page=' + params.pageSize; // number of items on the page
281-
* const xhr = new XMLHttpRequest();
282-
* xhr.onload = function() {
283-
* const response = JSON.parse(xhr.responseText);
284-
* callback(response.employees);
285-
* };
286-
* xhr.open('GET', url, true);
287-
* xhr.send();
273+
* grid.dataProvider = ({page, pageSize}, callback) => {
274+
* const url = `https://api.example/data?page=${page}&per_page=${pageSize}`;
275+
*
276+
* fetch(url)
277+
* .then((res) => res.json())
278+
* .then((resJson) => callback(resJson.employees));
288279
* };
289280
* ```
290281
*

‎packages/grid/src/vaadin-grid.js‎

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -139,38 +139,29 @@ import { StylingMixin } from './vaadin-grid-styling-mixin.js';
139139
* in the second argument of the data provider callback:__
140140
*
141141
* ```javascript
142-
* grid.dataProvider = function(params, callback) {
143-
* const url = 'https://api.example/data' +
144-
* '?page=' + params.page + // the requested page index
145-
* '&per_page=' + params.pageSize; // number of items on the page
146-
* const xhr = new XMLHttpRequest();
147-
* xhr.onload = function() {
148-
* const response = JSON.parse(xhr.responseText);
149-
* callback(
150-
* response.employees, // requested page of items
151-
* response.totalSize // total number of items
152-
* );
153-
* };
154-
* xhr.open('GET', url, true);
155-
* xhr.send();
142+
* grid.dataProvider = ({page, pageSize}, callback) => {
143+
* // page: the requested page index
144+
* // pageSize: number of items on one page
145+
* const url = `https://api.example/data?page=${page}&per_page=${pageSize}`;
146+
*
147+
* fetch(url)
148+
* .then((res) => res.json())
149+
* .then(({ employees, totalSize }) => {
150+
* callback(employees, totalSize);
151+
* });
156152
* };
157153
* ```
158154
*
159155
* __Alternatively, you can use the `size` property to set the total number of items:__
160156
*
161157
* ```javascript
162158
* grid.size = 200; // The total number of items
163-
* grid.dataProvider = function(params, callback) {
164-
* const url = 'https://api.example/data' +
165-
* '?page=' + params.page + // the requested page index
166-
* '&per_page=' + params.pageSize; // number of items on the page
167-
* const xhr = new XMLHttpRequest();
168-
* xhr.onload = function() {
169-
* const response = JSON.parse(xhr.responseText);
170-
* callback(response.employees);
171-
* };
172-
* xhr.open('GET', url, true);
173-
* xhr.send();
159+
* grid.dataProvider = ({page, pageSize}, callback) => {
160+
* const url = `https://api.example/data?page=${page}&per_page=${pageSize}`;
161+
*
162+
* fetch(url)
163+
* .then((res) => res.json())
164+
* .then((resJson) => callback(resJson.employees));
174165
* };
175166
* ```
176167
*

0 commit comments

Comments
 (0)