Skip to content

Commit

Permalink
refactor: do not allow to set active state on search source initiation
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinCupela committed Jan 31, 2025
1 parent a2c8fec commit e145dae
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
6 changes: 2 additions & 4 deletions src/search_controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,11 @@ export type SearchSourceState<T = any> = {
export type SearchSourceOptions = {
/** The number of milliseconds to debounce the search query. The default interval is 300ms. */
debounceMs?: number;
isActive?: boolean;
pageSize?: number;
};

const DEFAULT_SEARCH_SOURCE_OPTIONS: Required<SearchSourceOptions> = {
debounceMs: 300,
isActive: false,
pageSize: 10,
} as const;

Expand All @@ -79,9 +77,9 @@ export abstract class BaseSearchSource<T> implements SearchSource<T> {
searchDebounced!: DebouncedExecQueryFunction;

protected constructor(options?: SearchSourceOptions) {
const { debounceMs, isActive, pageSize } = { ...DEFAULT_SEARCH_SOURCE_OPTIONS, ...options };
const { debounceMs, pageSize } = { ...DEFAULT_SEARCH_SOURCE_OPTIONS, ...options };
this.pageSize = pageSize;
this.state = new StateStore<SearchSourceState<T>>({ ...this.initialState, isActive });
this.state = new StateStore<SearchSourceState<T>>(this.initialState);
this.setDebounceOptions({ debounceMs });
}

Expand Down
3 changes: 1 addition & 2 deletions test/unit/search_controller.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,8 @@ describe('BaseSearchSource and implementations', () => {
});

it('initializes with custom options', () => {
searchSource = new TestSearchSource({ pageSize: 20, isActive: true });
searchSource = new TestSearchSource({ pageSize: 20 });
expect(searchSource.pageSize).to.equal(20);
expect(searchSource.isActive).to.be.true;
});

describe('activate/deactivate', () => {
Expand Down

0 comments on commit e145dae

Please # to comment.