Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(atomic): add explicit types for different types of store #2190

Merged
merged 4 commits into from
Jul 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 26 additions & 26 deletions packages/atomic-angular/projects/atomic-angular/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 26 additions & 26 deletions packages/atomic-react/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 17 additions & 17 deletions packages/atomic/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions packages/atomic/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { ResultRenderingFunction } from "./components/search/result-lists/result
import { Section } from "./components/search/atomic-layout-section/sections";
import { RecommendationEngine } from "@coveo/headless/recommendation";
import { i18n } from "i18next";
import { AtomicStore } from "./components/search/atomic-search-interface/store";
import { InitializationOptions } from "./components/search/atomic-search-interface/atomic-search-interface";
import { StandaloneSearchBoxData } from "./utils/local-storage-utils";
import { InsightEngine } from "@coveo/headless/insight";
Expand Down Expand Up @@ -656,7 +657,7 @@ export namespace Components {
/**
* Global state for Atomic.
*/
"store"?: ReturnType<typeof createAtomicStore>;
"store"?: AtomicStore;
}
interface AtomicResultBadge {
/**
Expand Down Expand Up @@ -2479,7 +2480,7 @@ declare namespace LocalJSX {
/**
* Global state for Atomic.
*/
"store"?: ReturnType<typeof createAtomicStore>;
"store"?: AtomicStore;
}
interface AtomicResultBadge {
/**
Expand Down
12 changes: 11 additions & 1 deletion packages/atomic/src/components/common/interface/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,19 @@ export type AtomicCommonStoreData = {
iconAssetsPath: string;
};

export interface AtomicCommonStore<StoreData extends AtomicCommonStoreData>
extends CommonStencilStore<StoreData> {
setLoadingFlag(flag: string): void;
unsetLoadingFlag(loadingFlag: string): void;
hasLoadingFlag(loadingFlag: string): boolean;
waitUntilAppLoaded(callback: () => void): void;
isAppLoaded(): boolean;
getUniqueIDFromEngine(engine: AnyEngineType): string;
}

export function createAtomicCommonStore<
StoreData extends AtomicCommonStoreData
>(initialStoreData: StoreData) {
>(initialStoreData: StoreData): AtomicCommonStore<StoreData> {
const stencilStore = createStore(
initialStoreData
) as CommonStencilStore<StoreData>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ import {
BaseAtomicInterface,
CommonAtomicInterfaceHelper,
} from '../../common/interface/interface-common';
import {createAtomicSvcInsightStore} from './store';
import {AtomicSvcInsightStore, createAtomicSvcInsightStore} from './store';
import {getAnalyticsConfig} from './analytics-config';

const FirstInsightRequestExecutedFlag = 'firstInsightRequestExecuted';
export type InitializationOptions = InsightEngineConfiguration;
export type Bindings = CommonBindings<
InsightEngine,
ReturnType<typeof createAtomicSvcInsightStore>,
AtomicSvcInsightStore,
HTMLAtomicSvcInsightInterfaceElement
>;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import {InsightEngine} from '@coveo/headless/insight';
import {
AtomicCommonStore,
AtomicCommonStoreData,
createAtomicCommonStore,
} from '../../common/interface/store';

export interface AtomicSvgInsightStoreData extends AtomicCommonStoreData {}
export interface AtomicSvcInsightStoreData extends AtomicCommonStoreData {}

export function createAtomicSvcInsightStore() {
const commonStore = createAtomicCommonStore<AtomicSvgInsightStoreData>({
export interface AtomicSvcInsightStore
extends AtomicCommonStore<AtomicSvcInsightStoreData> {}

export function createAtomicSvcInsightStore(): AtomicSvcInsightStore {
const commonStore = createAtomicCommonStore<AtomicSvcInsightStoreData>({
loadingFlags: [],
iconAssetsPath: '',
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ import {
BaseAtomicInterface,
CommonAtomicInterfaceHelper,
} from '../../common/interface/interface-common';
import {createAtomicRecsStore} from './store';
import {createAtomicRecsStore, AtomicRecsStore} from './store';

const FirstRecommendationExecutedFlag = 'firstRecommendationExecuted';
export type Bindings = CommonBindings<
RecommendationEngine,
ReturnType<typeof createAtomicRecsStore>,
AtomicRecsStore,
HTMLAtomicRecsInterfaceElement
>;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import {RecommendationEngine} from '@coveo/headless/recommendation';
import {
AtomicCommonStore,
AtomicCommonStoreData,
createAtomicCommonStore,
} from '../../common/interface/store';

export interface AtomicRecsStoreData extends AtomicCommonStoreData {}
export interface AtomicRecsStore
extends AtomicCommonStore<AtomicRecsStoreData> {}

export function createAtomicRecsStore() {
export function createAtomicRecsStore(): AtomicRecsStore {
const commonStore = createAtomicCommonStore<AtomicRecsStoreData>({
loadingFlags: [],
iconAssetsPath: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
ResultContextEvent,
} from '../result-template-components/result-template-decorators';
import {ResultRenderingFunction} from '../result-lists/result-list-common';
import {createAtomicStore} from '../atomic-search-interface/store';
import {AtomicStore} from '../atomic-search-interface/store';

const resultSectionTags = [
'atomic-result-section-visual',
Expand Down Expand Up @@ -55,7 +55,7 @@ export class AtomicResult {
* Global state for Atomic.
* @internal
*/
@Prop() store?: ReturnType<typeof createAtomicStore>;
@Prop() store?: AtomicStore;

/**
* The result content to display.
Expand Down
Loading