Skip to content

Commit 226f77d

Browse files
author
Dominik Decker
committed
Fixed typos and cleanup
1 parent 69f71e2 commit 226f77d

File tree

4 files changed

+18
-17
lines changed

4 files changed

+18
-17
lines changed

src/common.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ export interface EntrySetting {
1919
settings: FinalShowOptions;
2020
}
2121

22-
interface OverlayOptions {
22+
export interface OverlayOptions {
2323
show: boolean;
2424
closeOnClick: boolean;
2525
}
2626

27-
interface BaseShowOptions {
27+
export interface BaseShowOptions {
2828
component: string | Vue;
2929
closeOnEscape?: boolean;
3030
timeout?: number;
@@ -33,7 +33,7 @@ interface BaseShowOptions {
3333
};
3434
}
3535

36-
interface FinalShowOptions extends BaseShowOptions {
36+
export interface FinalShowOptions extends BaseShowOptions {
3737
overlay: OverlayOptions;
3838
}
3939

src/lib.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { Store } from 'vuex';
22

3-
import { PluginSettings, OverlayHostState } from './common';
3+
import { PluginSettings, NAMESPACE_NAME } from './common';
44
import OverlayHost from './components/OverlayHost.vue';
55
import { createModule } from './store';
66

77
export * from './common';
88
export { OverlayHost };
99
export function OverlayHostPlugin(store: Store<any>, settings: PluginSettings) {
10-
store.registerModule('overlay-host', createModule(settings));
10+
store.registerModule(NAMESPACE_NAME, createModule(settings));
1111
}

src/store.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { Store, StoreOptions, Module, ActionTree } from 'vuex';
2-
import { ShowOptions, RemoveRequest, OverlayHostState, EntrySetting, PluginSettings, ShowResponse } from '@/common';
1+
import { Module, Store } from 'vuex';
32

4-
function validateShowOptions(options: ShowOptions, defaultTimeout: number): ShowOptions {
3+
import { EntrySetting, OverlayHostState, PluginSettings, RemoveRequest, ShowOptions, ShowResponse, FinalShowOptions } from './common';
4+
5+
function validateShowOptions(options: ShowOptions, defaultTimeout: number): FinalShowOptions {
56
if (options == null || typeof options !== 'object') {
67
throw new TypeError('The Settings have to be specified!');
78
}
@@ -33,7 +34,12 @@ function validateShowOptions(options: ShowOptions, defaultTimeout: number): Show
3334
options.timeout = defaultTimeout;
3435
}
3536

36-
return options;
37+
// Default the closeOnEscape to true
38+
if (typeof options.closeOnEscape !== 'boolean') {
39+
options.closeOnEscape = true;
40+
}
41+
42+
return options as FinalShowOptions;
3743
}
3844

3945
function validateRemoveRequest(payload: number | RemoveRequest): RemoveRequest {
@@ -95,8 +101,6 @@ export function createModule(pluginSettings: PluginSettings): Module<OverlayHost
95101

96102
const actions = {
97103
show(store: Store<OverlayHostState>, options: ShowOptions): Promise<ShowResponse> {
98-
options = validateShowOptions(options, defaultTimeout);
99-
100104
let resolve = () => {};
101105
let reject = () => {};
102106
const promise = new Promise<RemoveRequest>((re, rj) => {
@@ -110,11 +114,7 @@ export function createModule(pluginSettings: PluginSettings): Module<OverlayHost
110114
id,
111115
resolver: resolve,
112116
rejector: reject,
113-
settings: {
114-
timeout: defaultTimeout,
115-
closeOnEscape: true,
116-
...options
117-
}
117+
settings: validateShowOptions(options, defaultTimeout),
118118
};
119119

120120
if (item.settings.timeout != null && item.settings.timeout > 0) {
@@ -148,7 +148,7 @@ export function createModule(pluginSettings: PluginSettings): Module<OverlayHost
148148
didRemoveElement.resolver({ value: payload.value, origin: payload.origin });
149149
return Promise.resolve(true);
150150
},
151-
abor(store: Store<OverlayHostState>, payload: RemoveRequest): Promise<boolean> {
151+
abort(store: Store<OverlayHostState>, payload: RemoveRequest): Promise<boolean> {
152152
payload = validateRemoveRequest(payload);
153153
const didRemoveElement = removeEntryFromStore(store, payload.id);
154154

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"target": "esnext",
44
"module": "esnext",
55
"strict": false,
6+
"strictPropertyInitialization": false,
67
"jsx": "preserve",
78
"importHelpers": true,
89
"moduleResolution": "node",

0 commit comments

Comments
 (0)