Skip to content

Commit

Permalink
chore: prepare for TS defs generation [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
web-padawan committed Mar 31, 2020
1 parent f31e4ca commit 5b35538
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 0 deletions.
14 changes: 14 additions & 0 deletions gen-tsd.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"excludeFiles": [
"index.html",
"wct.conf.js",
"demo/**/*",
"theme/**/*",
"test/**/*"
],
"autoImport": {
"./src/vaadin-combo-box-data-provider.d.ts": [
"ComboBoxDataProvider"
]
}
}
40 changes: 40 additions & 0 deletions magi-p3-post.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const tsDep = `"scripts": {
"generate-typings": "gen-typescript-declarations --outDir ."
},
"devDependencies": {
"@polymer/gen-typescript-declarations": "^1.6.2",`;

const rootExport = `import './theme/lumo/vaadin-combo-box.js';
export * from './src/vaadin-combo-box.js';
`;

module.exports = {
files: [
'package.json',
'src/vaadin-combo-box.js',
'src/vaadin-combo-box-light.js',
'vaadin-combo-box.js'
],
from: [
'"devDependencies": {',
'@mixes Vaadin.ElementMixin',
'@mixes Vaadin.ControlStateMixin',
'@mixes Vaadin.ComboBoxDataProviderMixin',
'@mixes Vaadin.ComboBoxMixin',
'@mixes Vaadin.ThemableMixin',
'@mixes Vaadin.ThemePropertyMixin',
'@memberof Vaadin',
`import './theme/lumo/vaadin-combo-box.js';`
],
to: [
tsDep,
'@mixes ElementMixin',
'@mixes ControlStateMixin',
'@mixes ComboBoxDataProviderMixin',
'@mixes ComboBoxMixin',
'@mixes ThemableMixin',
'@mixes ThemePropertyMixin',
'@extends PolymerElement',
rootExport
]
};
36 changes: 36 additions & 0 deletions src/vaadin-combo-box-data-provider-mixin.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,27 @@
Vaadin.ComboBoxDataProviderMixin = superClass => class DataProviderMixin extends superClass {

static get properties() {
/**
* @typedef DataProviderParams
* @type {object}
* @property {number} page
* @property {number} pageSize
* @property {string} filter
*/

/**
* @typedef DataProviderCallback
* @type {function}
* @param {unknown[]} items
* @param {number} size
*/

/**
* @typedef DataProvider
* @type {function}
* @param {DataProvideParams} params
* @param {DataProvideCallback} callback
*/
return {

/**
Expand Down Expand Up @@ -44,6 +65,8 @@
* `callback(items, size)` Callback function with arguments:
* - `items` Current page of items
* - `size` Total number of items.
*
* @type {ComboBoxDataProvider?}
*/
dataProvider: {
type: Object,
Expand Down Expand Up @@ -72,6 +95,11 @@
];
}

/**
* @param {ComboBoxDataProvider?} dataProvider
* @param {boolean} opened
* @param {string} value
*/
_dataProviderClearFilter(dataProvider, opened, value) {
// Can't depend on filter in this obsever as we don't want
// to clear the filter whenever it's set
Expand Down Expand Up @@ -207,6 +235,10 @@
this.clearCache();
}

/**
* @param {ComboBoxDataProvider?} dataProvider
* @param {ComboBoxDataProvider?} oldDataProvider
*/
_dataProviderChanged(dataProvider, oldDataProvider) {
this._ensureItemsOrDataProvider(() => {
this.dataProvider = oldDataProvider;
Expand All @@ -222,6 +254,10 @@
}
}

/**
* @param {ComboBoxDataProvider?} dataProvider
* @param {string?} value
*/
_warnDataProviderValue(dataProvider, value) {
if (dataProvider && value !== '' && (this.selectedItem === undefined || this.selectedItem === null)) {
const valueIndex = this._indexOfValue(value, this.filteredItems);
Expand Down
11 changes: 11 additions & 0 deletions src/vaadin-combo-box-data-provider.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export type ComboBoxDataProviderCallback = (items: Array<unknown>, size: number) => void;

export type ComboBoxDataProviderParams = {
page: number;

pageSize: number;

filter: string;
}

export type ComboBoxDataProvider = (params: ComboBoxDataProviderParams, callback: ComboBoxDataProviderCallback) => void;

0 comments on commit 5b35538

Please sign in to comment.