Skip to content

Commit

Permalink
simplify naming
Browse files Browse the repository at this point in the history
  • Loading branch information
daniellacosse committed Oct 13, 2023
1 parent 9772ebf commit 13cc497
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
17 changes: 8 additions & 9 deletions x/examples/outline-connectivity-app/app_mobile/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ import { registerPlugin } from "@capacitor/core";
// Capacitor requires passing in a root object to each native call,
// that is then accessed via APIs like `call.getString("objectKey")`.
const MobileBackend = registerPlugin<{
Request(request: { resourceName: string; parameters: string}): Promise<{ error: string; body: string}>;
Request(request: { resourceName: string; parameters: string }): Promise<{ error: string; body: string }>;
}>("MobileBackend");

async function requestBackend<T, K>(resourceName: string, parameters: T): Promise<K> {
const response = await MobileBackend.Request({
resourceName, parameters: JSON.stringify(parameters)
const response = await MobileBackend.Request({
resourceName, parameters: JSON.stringify(parameters)
});

if (response.error) {
throw new Error(response.error);
}

return JSON.parse(response.body);
}

Expand All @@ -47,12 +47,11 @@ SharedFrontend.registerAllElements();
export class AppMain extends LitElement {
render() {
return html`<connectivity-test-page
.resolvePlatform=${() => requestBackend<void, SharedFrontend.PlatformMetadata>("PlatformMetadata", void 0)}
.onSubmit=${
(parameters: ConnectivityTestRequest) =>
.loadPlatform=${() => requestBackend<void, SharedFrontend.PlatformMetadata>("Platform", void 0)}
.onSubmit=${(parameters: ConnectivityTestRequest) =>
requestBackend<ConnectivityTestRequest, ConnectivityTestResponse>(
"ConnectivityTest", parameters
"ConnectivityTest", parameters
)
} />`;
} />`;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,19 @@ const Localization = configureLocalization({
@localized()
export class ConnectivityTestPage extends LitElement {
@property({ type: Function })
resolvePlatform?: () => Promise<PlatformMetadata>;

@property({ type: Function })
onSubmit?: (request: ConnectivityTestRequest) => Promise<ConnectivityTestResponse>;
loadPlatform?: () => Promise<PlatformMetadata>;

@property({ attribute: false })
platform?: PlatformMetadata;

@property({ type: Function })
onSubmit?: (request: ConnectivityTestRequest) => Promise<ConnectivityTestResponse>;

@property({ attribute: false })
isSubmitting = false;

@property({ attribute: false })
testResponse?: ConnectivityTestResponse;
response?: ConnectivityTestResponse;

get locale() {
return Localization.getLocale();
Expand Down Expand Up @@ -91,8 +91,8 @@ export class ConnectivityTestPage extends LitElement {
}

protected async performUpdate() {
if (!this.platform && this.resolvePlatform) {
this.platform = await this.resolvePlatform();
if (!this.platform && this.loadPlatform) {
this.platform = await this.loadPlatform();
}

super.performUpdate();
Expand All @@ -108,9 +108,9 @@ export class ConnectivityTestPage extends LitElement {
this.isSubmitting = true;

try {
this.testResponse = (await this.onSubmit?.(this.formData)) ?? null;
this.response = (await this.onSubmit?.(this.formData)) ?? null;
} catch (error) {
this.testResponse = new Error(error as string);
this.response = new Error(error as string);
} finally {
this.isSubmitting = false;
}
Expand Down Expand Up @@ -772,7 +772,7 @@ export class ConnectivityTestPage extends LitElement {
}

renderResults() {
if (!this.testResponse) {
if (!this.response) {
return nothing;
}

Expand All @@ -781,12 +781,12 @@ export class ConnectivityTestPage extends LitElement {
<h2 class="results-header-text">${msg("Test Results")}</h2>
<button
class="results-header-close"
@click=${() => (this.testResponse = null)}
@click=${() => (this.response = null)}
>
</button>
</header>
${this.renderResultsList(this.testResponse)}
${this.renderResultsList(this.response)}
</dialog>`;
}

Expand Down

0 comments on commit 13cc497

Please sign in to comment.