Skip to content

Commit 0169045

Browse files
committed
feat(config): strongly typed config
fixes #15097
1 parent 6f2827a commit 0169045

File tree

5 files changed

+61
-17
lines changed

5 files changed

+61
-17
lines changed

core/src/components/refresher-content/refresher-content.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ export class RefresherContent {
3131

3232
protected componentDidLoad() {
3333
if (!this.pullingIcon) {
34-
this.pullingIcon = this.config.get('ionPullIcon', 'arrow-down');
34+
this.pullingIcon = this.config.get('refreshingIcon', 'arrow-down');
3535
}
3636
if (!this.refreshingSpinner) {
37-
this.refreshingSpinner = this.config.get('ionRefreshingSpinner', this.config.get('spinner', 'lines'));
37+
this.refreshingSpinner = this.config.get('refreshingSpinner', this.config.get('spinner', 'lines'));
3838
}
3939
}
4040

core/src/components/tabs/tabs.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Build, Component, Element, Event, EventEmitter, Listen, Method, Prop, State } from '@stencil/core';
22

3-
import { Color, Config, NavOutlet, RouteID, RouteWrite, TabbarLayout, TabbarPlacement } from '../../interface';
3+
import { Color, Config, IonicConfig, NavOutlet, RouteID, RouteWrite, TabbarLayout, TabbarPlacement } from '../../interface';
44
import { createColorClasses } from '../../utils/theme';
55

66
@Component({
@@ -99,7 +99,7 @@ export class Tabs implements NavOutlet {
9999
this.useRouter = !!this.doc.querySelector('ion-router') && !this.el.closest('[no-router]');
100100
}
101101

102-
this.loadConfig('tabbarLayout', 'bottom');
102+
this.loadConfig('tabbarPlacement', 'bottom');
103103
this.loadConfig('tabbarLayout', 'icon-top');
104104
this.loadConfig('tabbarHighlight', false);
105105

@@ -235,7 +235,7 @@ export class Tabs implements NavOutlet {
235235
}
236236
}
237237

238-
private loadConfig(attrKey: string, fallback: any) {
238+
private loadConfig(attrKey: keyof IonicConfig, fallback: any) {
239239
const val = (this as any)[attrKey];
240240
if (typeof val === 'undefined') {
241241
(this as any)[attrKey] = this.config.get(attrKey, fallback);

core/src/global/config.ts

Lines changed: 51 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,62 @@
11

2-
export class Config {
2+
export interface IonicConfig {
3+
isDevice?: boolean;
4+
statusbarPadding?: boolean;
5+
inputShims?: boolean;
6+
backButtonIcon?: string;
7+
backButtonText?: string;
8+
spinner?: string;
9+
loadingSpinner?: string;
10+
menuIcon?: string;
11+
animate?: boolean;
12+
pickerSpinner?: string;
13+
refreshingIcon?: string;
14+
refreshingSpinner?: string;
15+
mode?: string;
16+
menuType?: string;
17+
scrollPadding?: string;
18+
inputBlurring?: string;
19+
scrollAssist?: string;
20+
hideCaretOnScroll?: string;
21+
infiniteLoadingSpinner?: string;
22+
keyboardHeight?: number;
23+
swipeBackEnabled?: boolean;
24+
25+
tabbarPlacement?: string;
26+
tabbarLayout?: string;
27+
tabbarHighlight?: boolean;
28+
29+
actionSheetEnter?: string;
30+
alertEnter?: string;
31+
loadingEnter?: string;
32+
modalEnter?: string;
33+
popoverEnter?: string;
34+
toastEnter?: string;
35+
pickerEnter?: string;
336

4-
private m: Map<string, any>;
37+
actionSheetLeave?: string;
38+
alertLeave?: string;
39+
loadingLeave?: string;
40+
modalLeave?: string;
41+
popoverLeave?: string;
42+
toastLeave?: string;
43+
pickerLeave?: string;
44+
}
45+
46+
export class Config {
547

6-
constructor(configObj: {[key: string]: any}) {
7-
this.m = new Map<string, any>(Object.entries(configObj));
48+
private m: Map<keyof IonicConfig, any>;
849

50+
constructor(configObj: IonicConfig) {
51+
this.m = new Map<keyof IonicConfig, any>(Object.entries(configObj) as any);
952
}
1053

11-
get(key: string, fallback?: any): any {
54+
get(key: keyof IonicConfig, fallback?: any): any {
1255
const value = this.m.get(key);
1356
return (value !== undefined) ? value : fallback;
1457
}
1558

16-
getBoolean(key: string, fallback = false): boolean {
59+
getBoolean(key: keyof IonicConfig, fallback = false): boolean {
1760
const val = this.m.get(key);
1861
if (val === undefined) {
1962
return fallback;
@@ -24,12 +67,12 @@ export class Config {
2467
return !!val;
2568
}
2669

27-
getNumber(key: string, fallback?: number): number {
70+
getNumber(key: keyof IonicConfig, fallback?: number): number {
2871
const val = parseFloat(this.m.get(key));
2972
return isNaN(val) ? (fallback !== undefined ? fallback : NaN) : val;
3073
}
3174

32-
set(key: string, value: any) {
75+
set(key: keyof IonicConfig, value: any) {
3376
this.m.set(key, value);
3477
}
3578
}

core/src/utils/config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
import { IonicConfig } from '../interface';
12

2-
export function setupConfig(config: {[key: string]: any}) {
3+
export function setupConfig(config: IonicConfig) {
34
const win = window as any;
45
const Ionic = win.Ionic;
56
if (Ionic && Ionic.config && Ionic.config.constructor.name !== 'Object') {

core/src/utils/overlays.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AnimationBuilder, HTMLIonOverlayElement, OverlayInterface, OverlayMap } from '../interface';
1+
import { AnimationBuilder, HTMLIonOverlayElement, IonicConfig, OverlayInterface, OverlayMap } from '../interface';
22

33
let lastId = 1;
44

@@ -47,7 +47,7 @@ export function removeLastOverlay(overlays: OverlayMap) {
4747

4848
export async function present(
4949
overlay: OverlayInterface,
50-
name: string,
50+
name: keyof IonicConfig,
5151
iosEnterAnimation: AnimationBuilder,
5252
mdEnterAnimation: AnimationBuilder,
5353
opts?: any
@@ -72,7 +72,7 @@ export async function dismiss(
7272
overlay: OverlayInterface,
7373
data: any | undefined,
7474
role: string | undefined,
75-
name: string,
75+
name: keyof IonicConfig,
7676
iosLeaveAnimation: AnimationBuilder,
7777
mdLeaveAnimation: AnimationBuilder,
7878
opts?: any

0 commit comments

Comments
 (0)