-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.ts
30 lines (24 loc) · 863 Bytes
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { configurable, origin, provide, tag, utils, Events, Selectors, Store, Tag } from '@storefront/core';
@configurable
@provide('didYouMean')
@origin('dym')
@tag('gb-did-you-mean', require('./index.html'))
class DidYouMean {
state: DidYouMean.State = {
didYouMeans: [],
};
init() {
this.subscribe(Events.DID_YOU_MEANS_UPDATED, this.updateDidYouMeans);
this.updateDidYouMeans(this.select(Selectors.didYouMean));
}
updateDidYouMeans = (didYouMeans: string[]) =>
!(didYouMeans.length === 0 && this.state.didYouMeans.length === 0) &&
this.set({ didYouMeans: utils.mapToSearchActions(didYouMeans, <any>this.actions) });
}
interface DidYouMean extends Tag<any, DidYouMean.State> {}
namespace DidYouMean {
export interface State {
didYouMeans: Array<{ value: string; onClick: () => void }>;
}
}
export default DidYouMean;