Skip to content

Commit

Permalink
fix(types): improve UiState types (#3763)
Browse files Browse the repository at this point in the history
  • Loading branch information
francoischalifour authored May 13, 2019
1 parent 2808b52 commit e8ea57b
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/lib/RoutingManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class RoutingManager implements Widget {
const widgets = this.instantSearchInstance.widgets;
const helper = this.instantSearchInstance.helper!;

return widgets.reduce((state, widget) => {
return widgets.reduce<UiState>((state, widget) => {
if (!widget.getWidgetState) {
return state;
}
Expand Down
8 changes: 4 additions & 4 deletions src/lib/__tests__/RoutingManager-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ describe('RoutingManager', () => {
});

const widgetState = {
some: 'values',
query: 'query',
};
const widget = {
render: () => {},
Expand All @@ -107,7 +107,7 @@ describe('RoutingManager', () => {
search.addWidget(widget);

const actualInitialState = {
some: 'values',
query: 'query',
};

search.start();
Expand Down Expand Up @@ -149,7 +149,7 @@ describe('RoutingManager', () => {
search.start();

const actualInitialState = {
some: 'values',
query: 'query',
};

const router = new RoutingManager({
Expand Down Expand Up @@ -182,7 +182,7 @@ describe('RoutingManager', () => {
search.addWidget(widget);

const actualInitialState = {
some: 'values',
query: 'query',
};

search.start();
Expand Down
40 changes: 39 additions & 1 deletion src/types/widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,45 @@ interface DisposeOptions {
}

export type UiState = {
[stateKey: string]: any;
query?: string;
menu?: {
[attribute: string]: string;
};
/**
* The list of hierarchical menus.
* Nested levels must contain the record separator.
*
* @example ['Audio', 'Audio > Headphones']
*/
hierarchicalMenu?: {
[attribute: string]: string[];
};
refinementList?: {
[attribute: string]: string[];
};
numericRefinementList?: {
[attribute: string]: number;
};
numericSelector?: {
[attribute: string]: number;
};
/**
* The range as a tuple.
*
* @example '100:500'
*/
range?: {
[attribute: string]: string;
};
starRating?: {
[attribute: string]: number;
};
toggle?: {
[attribute: string]: boolean;
};
sortBy?: string;
page?: number;
hitsPerPage?: number;
};

export interface Widget {
Expand Down

0 comments on commit e8ea57b

Please sign in to comment.