octicon-rss(16/)
You've already forked ionic-framework
mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-11-10 22:44:13 +08:00
refactor(angular): enable TS strict
This commit is contained in:
octicon-git-branch(16/)
octicon-tag(16/)
octicon-diff(16/tw-mr-1) 11 changed files with 62 additions and 76 deletions
@@ -28,7 +28,7 @@ export class AngularFrameworkDelegate implements FrameworkDelegate {
|
||||
constructor(
|
||||
private resolver: ComponentFactoryResolver,
|
||||
private injector: Injector,
|
||||
private location: ViewContainerRef,
|
||||
private location: ViewContainerRef | undefined,
|
||||
private appRef: ApplicationRef,
|
||||
private zone: NgZone,
|
||||
) {}
|
||||
@@ -62,10 +62,10 @@ export class AngularFrameworkDelegate implements FrameworkDelegate {
|
||||
export function attachView(
|
||||
resolver: ComponentFactoryResolver,
|
||||
injector: Injector,
|
||||
location: ViewContainerRef|undefined,
|
||||
location: ViewContainerRef | undefined,
|
||||
appRef: ApplicationRef,
|
||||
elRefMap: WeakMap<HTMLElement, any>,
|
||||
container: any, component: any, params: any, cssClasses: string[]
|
||||
container: any, component: any, params: any, cssClasses: string[] | undefined
|
||||
) {
|
||||
const factory = resolver.resolveComponentFactory(component);
|
||||
const childInjector = Injector.create(getProviders(params), injector);
|
||||
@@ -78,8 +78,10 @@ export function attachView(
|
||||
if (params) {
|
||||
Object.assign(instance, params);
|
||||
}
|
||||
for (const clazz of cssClasses) {
|
||||
hostElement.classList.add(clazz);
|
||||
if (cssClasses) {
|
||||
for (const clazz of cssClasses) {
|
||||
hostElement.classList.add(clazz);
|
||||
}
|
||||
}
|
||||
bindLifecycleEvents(instance, hostElement);
|
||||
container.appendChild(hostElement);
|
||||
@@ -103,8 +105,8 @@ const LIFECYCLES = [
|
||||
|
||||
export function bindLifecycleEvents(instance: any, element: HTMLElement) {
|
||||
LIFECYCLES.forEach(eventName => {
|
||||
element.addEventListener(eventName, (ev: CustomEvent) => {
|
||||
if (typeof instance[eventName] === 'function') {
|
||||
element.addEventListener(eventName, (ev: any) => {
|
||||
if (typeof instance[eventName] === 'function' && ev.detail) {
|
||||
instance[eventName](ev.detail);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -18,7 +18,7 @@ export class Config {
|
||||
if (c) {
|
||||
return c.getBoolean(key, fallback);
|
||||
}
|
||||
return null;
|
||||
return false;
|
||||
}
|
||||
|
||||
getNumber(key: string, fallback?: number): number {
|
||||
@@ -26,7 +26,7 @@ export class Config {
|
||||
if (c) {
|
||||
return c.getNumber(key, fallback);
|
||||
}
|
||||
return null;
|
||||
return 0;
|
||||
}
|
||||
|
||||
set(key: string, value?: any) {
|
||||
@@ -39,7 +39,7 @@ export class Config {
|
||||
|
||||
export const ConfigToken = new InjectionToken<any>('USERCONFIG');
|
||||
|
||||
function getConfig(): CoreConfig {
|
||||
function getConfig(): CoreConfig | null {
|
||||
const win: IonicWindow = window as any;
|
||||
if (typeof win !== 'undefined') {
|
||||
const Ionic = win.Ionic;
|
||||
|
||||
@@ -3,7 +3,7 @@ import { Injectable } from '@angular/core';
|
||||
|
||||
@Injectable()
|
||||
export class Events {
|
||||
private c: {[topic: string]: Function[]} = [] as any;
|
||||
private c = new Map<string, Function[]>();
|
||||
|
||||
/**
|
||||
* Subscribe to an event topic. Events that get posted to that topic will trigger the provided handler.
|
||||
@@ -12,12 +12,11 @@ export class Events {
|
||||
* @param {function} handler the event handler
|
||||
*/
|
||||
subscribe(topic: string, ...handlers: Function[]) {
|
||||
if (!this.c[topic]) {
|
||||
this.c[topic] = [];
|
||||
let topics = this.c.get(topic);
|
||||
if (!topics) {
|
||||
topics = [];
|
||||
}
|
||||
handlers.forEach((handler) => {
|
||||
this.c[topic].push(handler);
|
||||
});
|
||||
topics.push(...handlers);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -28,34 +27,27 @@ export class Events {
|
||||
*
|
||||
* @return true if a handler was removed
|
||||
*/
|
||||
unsubscribe(topic: string, handler: Function = null) {
|
||||
const t = this.c[topic];
|
||||
if (!t) {
|
||||
// Wasn't found, wasn't removed
|
||||
return false;
|
||||
unsubscribe(topic: string, handler?: Function): boolean {
|
||||
if (!handler) {
|
||||
return this.c.delete(topic);
|
||||
}
|
||||
|
||||
if (!handler) {
|
||||
// Remove all handlers for this topic
|
||||
delete this.c[topic];
|
||||
return true;
|
||||
const topics = this.c.get(topic);
|
||||
if (!topics) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// We need to find and remove a specific handler
|
||||
const i = t.indexOf(handler);
|
||||
const index = topics.indexOf(handler);
|
||||
|
||||
if (i < 0) {
|
||||
if (index < 0) {
|
||||
// Wasn't found, wasn't removed
|
||||
return false;
|
||||
}
|
||||
|
||||
t.splice(i, 1);
|
||||
|
||||
// If the channel is empty now, remove it from the channel map
|
||||
if (!t.length) {
|
||||
delete this.c[topic];
|
||||
topics.splice(index, 1);
|
||||
if (topics.length === 0) {
|
||||
this.c.delete(topic);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -65,17 +57,12 @@ export class Events {
|
||||
* @param {string} topic the topic to publish to
|
||||
* @param {any} eventData the data to send as the event
|
||||
*/
|
||||
publish(topic: string, ...args: any[]) {
|
||||
const t = this.c[topic];
|
||||
if (!t) {
|
||||
publish(topic: string, ...args: any[]): any[] | null {
|
||||
const topics = this.c.get(topic);
|
||||
if (!topics) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const responses: any[] = [];
|
||||
t.forEach((handler: any) => {
|
||||
responses.push(handler(...args));
|
||||
});
|
||||
return responses;
|
||||
return topics.map((handler => handler(...args)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ export class ModalController extends OverlayBaseController<ModalOptions, HTMLIon
|
||||
super('ion-modal-controller');
|
||||
}
|
||||
|
||||
create(opts?: ModalOptions): Promise<HTMLIonModalElement> {
|
||||
create(opts: ModalOptions): Promise<HTMLIonModalElement> {
|
||||
return super.create({
|
||||
...opts,
|
||||
delegate: this.angularDelegate.create(this.resolver, this.injector)
|
||||
|
||||
@@ -21,17 +21,17 @@ export class NavController {
|
||||
|
||||
goForward(url: string | UrlTree, animated?: boolean, extras?: NavigationExtras) {
|
||||
this.setIntent(NavIntent.Forward, animated);
|
||||
return this.router.navigateByUrl(url, extras);
|
||||
return this.router!.navigateByUrl(url, extras);
|
||||
}
|
||||
|
||||
goBack(url: string | UrlTree, animated?: boolean, extras?: NavigationExtras) {
|
||||
this.setIntent(NavIntent.Back, animated);
|
||||
return this.router.navigateByUrl(url, extras);
|
||||
return this.router!.navigateByUrl(url, extras);
|
||||
}
|
||||
|
||||
goRoot(url: string | UrlTree, animated?: boolean, extras?: NavigationExtras) {
|
||||
this.setIntent(NavIntent.Root, animated);
|
||||
return this.router.navigateByUrl(url, extras);
|
||||
return this.router!.navigateByUrl(url, extras);
|
||||
}
|
||||
|
||||
setIntent(intent: NavIntent, animated?: boolean) {
|
||||
|
||||
@@ -49,7 +49,7 @@ export class Platform {
|
||||
readyResolve('cordova');
|
||||
}, {once: true});
|
||||
} else {
|
||||
readyResolve('dom');
|
||||
readyResolve!('dom');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -169,7 +169,7 @@ export class Platform {
|
||||
/**
|
||||
* Get the query string parameter
|
||||
*/
|
||||
getQueryParam(key: string): string {
|
||||
getQueryParam(key: string): string | null {
|
||||
return readQueryParam(window.location.href, key);
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ export class PopoverController extends OverlayBaseController<PopoverOptions, HTM
|
||||
super('ion-popover-controller');
|
||||
}
|
||||
|
||||
create(opts?: PopoverOptions): Promise<HTMLIonPopoverElement> {
|
||||
create(opts: PopoverOptions): Promise<HTMLIonPopoverElement> {
|
||||
return super.create({
|
||||
...opts,
|
||||
delegate: this.angularDelegate.create(this.resolver, this.injector)
|
||||
|
||||
Reference in New Issue
Block a user