Skip to content

Commit

Permalink
chore(plugin): Fix typescript errors and consolidate to single file
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven0351 committed Apr 24, 2024
1 parent eb14aad commit 622f021
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 51 deletions.
2 changes: 1 addition & 1 deletion plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"rimraf": "^3.0.2",
"rollup": "^2.32.0",
"swiftlint": "^1.0.1",
"typescript": "~4.0.3"
"typescript": "~5.0.2"
},
"peerDependencies": {
"@capacitor/core": "^6.0.0"
Expand Down
33 changes: 0 additions & 33 deletions plugin/src/definitions.ts

This file was deleted.

49 changes: 40 additions & 9 deletions plugin/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,47 @@
import { Capacitor, registerPlugin } from '@capacitor/core';
import { Capacitor, WebPlugin, registerPlugin } from '@capacitor/core';
import type { PluginListenerHandle } from '@capacitor/core';

import type {
InitialContext,
PortalMessage,
PortalsPlugin,
} from './definitions';
/**
*
* A type definining the `InitialContext` from the native application that you can pass into your web application.
*/
export interface InitialContext<T = unknown> {
name: string;
value?: T;
assets?: {
[key: string]: string;
};
}

/**
* A message that you can publish to a topic using Portals.publish()
*/
export interface PortalMessage<TData = any> {
topic: string;
data?: TData;
}

interface PortalsPlugin {
publishNative<TMessage extends PortalMessage>(
message: TMessage,
): Promise<void>;
addListener<T = unknown>(
eventName: string,
listenerFunc: (result: PortalMessage<T>) => void,
): Promise<PluginListenerHandle>
}

class PortalsWeb extends WebPlugin implements PortalsPlugin {
async publishNative(_message: PortalMessage): Promise<void> {
return Promise.resolve();
}
addListener<T = unknown>(_eventName: string, _listenerFunc: (result: PortalMessage<T>) => void): Promise<PluginListenerHandle> {
return Promise.reject('Method not implemented on web.')
}
}

const Portals = registerPlugin<PortalsPlugin>('Portals', {
web: () => import('./web').then(m => new m.PortalsWeb()),
web: () => new PortalsWeb(),
});

/**
Expand Down Expand Up @@ -40,5 +73,3 @@ export function publish<TMessage extends PortalMessage>(
): Promise<void> {
return Portals.publishNative(message);
}

export * from './definitions';
8 changes: 0 additions & 8 deletions plugin/src/web.ts

This file was deleted.

0 comments on commit 622f021

Please sign in to comment.