Skip to content

Commit

Permalink
feat!(plugin): Remove SubscriptionCallback type (#259)
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven0351 authored Feb 13, 2024
1 parent 4948edc commit c42a783
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 14 deletions.
10 changes: 1 addition & 9 deletions plugin/src/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface PortalsPlugin {
): Promise<void>;
addListener<T = unknown>(
eventName: string,
listenerFunc: SubscriptionCallback<T>,
listenerFunc: (result: PortalMessage<T>) => void,
): Promise<PluginListenerHandle> & PluginListenerHandle;
}

Expand All @@ -31,11 +31,3 @@ export interface PortalMessage<TData = any> {
topic: string;
data?: TData;
}

/**
* The type definition from the callback running Portals.subscribe()
*/
export type SubscriptionCallback<T = unknown> = (result: {
topic: string;
data: T;
}) => void;
8 changes: 4 additions & 4 deletions plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import type {
InitialContext,
PortalMessage,
PortalsPlugin,
SubscriptionCallback,
} from './definitions';

const Portals = registerPlugin<PortalsPlugin>('Portals', {
Expand All @@ -20,17 +19,18 @@ const Portals = registerPlugin<PortalsPlugin>('Portals', {
export function getInitialContext<T = unknown>():
| InitialContext<T>
| undefined {
if (Capacitor.getPlatform() === "android") {
if (Capacitor.getPlatform() === 'android') {
// eslint-disable-next-line
//@ts-ignore
return JSON.parse(AndroidInitialContext.initialContext())
return JSON.parse(AndroidInitialContext.initialContext());
} else {
return (window as any).portalInitialContext;
}
}

export function subscribe<T = unknown>(
topic: string,
callback: SubscriptionCallback<T>,
callback: (result: PortalMessage<T>) => void,
): Promise<PluginListenerHandle> {
return Portals.addListener(topic, callback);
}
Expand Down
2 changes: 1 addition & 1 deletion plugin/src/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ import type { PortalMessage, PortalsPlugin } from './definitions';

export class PortalsWeb extends WebPlugin implements PortalsPlugin {
// eslint-disable-next-line
async publishNative(_message: PortalMessage): Promise<void> { }
async publishNative(_message: PortalMessage): Promise<void> {}
}

0 comments on commit c42a783

Please sign in to comment.