remove unused method
This commit is contained in:
@@ -1,22 +1,21 @@
|
||||
import { UmbControllerHostInterface } from "./controller-host.mixin";
|
||||
import { UmbControllerInterface } from "./controller.interface";
|
||||
import { UmbControllerHostInterface } from './controller-host.mixin';
|
||||
import { UmbControllerInterface } from './controller.interface';
|
||||
|
||||
export abstract class UmbController implements UmbControllerInterface {
|
||||
protected _host?: UmbControllerHostInterface;
|
||||
|
||||
protected _host?: UmbControllerHostInterface
|
||||
constructor(host: UmbControllerHostInterface) {
|
||||
this._host = host;
|
||||
this._host.addController(this);
|
||||
}
|
||||
|
||||
constructor(host: UmbControllerHostInterface) {
|
||||
this._host = host;
|
||||
this._host.addController(this);
|
||||
}
|
||||
abstract hostConnected(): void;
|
||||
abstract hostDisconnected(): void;
|
||||
|
||||
abstract hostConnected(): void;
|
||||
abstract hostDisconnected(): void;
|
||||
|
||||
public destroy() {
|
||||
if(this._host) {
|
||||
this._host.removeController(this);
|
||||
}
|
||||
delete this._host;
|
||||
}
|
||||
}
|
||||
public destroy() {
|
||||
if (this._host) {
|
||||
this._host.removeController(this);
|
||||
}
|
||||
delete this._host;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ import { ApiError, CancelablePromise, ProblemDetails } from '@umbraco-cms/backen
|
||||
import { UmbNotificationOptions, UmbNotificationService } from 'src/backoffice/core/services/notification';
|
||||
import { UmbNotificationDefaultData } from 'src/backoffice/core/services/notification/layouts/default';
|
||||
|
||||
|
||||
/**
|
||||
* Extract the ProblemDetails object from an ApiError.
|
||||
*
|
||||
@@ -26,45 +25,37 @@ function toProblemDetails(error: unknown): ProblemDetails | undefined {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
|
||||
export class UmbResourceController extends UmbController {
|
||||
|
||||
|
||||
#promise: Promise<any>;
|
||||
|
||||
#notificationService?: UmbNotificationService;
|
||||
|
||||
|
||||
constructor(host: UmbControllerHostInterface, promise: Promise<any>) {
|
||||
super(host);
|
||||
|
||||
this.#promise = promise;
|
||||
|
||||
new UmbContextConsumerController(host, 'umbNotificationService',
|
||||
(_instance: UmbNotificationService) => {
|
||||
this.#notificationService = _instance;
|
||||
}
|
||||
);
|
||||
new UmbContextConsumerController(host, 'umbNotificationService', (_instance: UmbNotificationService) => {
|
||||
this.#notificationService = _instance;
|
||||
});
|
||||
}
|
||||
|
||||
hostConnected() {
|
||||
// TODO: Make sure we do the right thing here, as connected can be called multiple times without disconnected invoked.
|
||||
//this.#promises.length = 0;
|
||||
this.hostConnected();
|
||||
}
|
||||
|
||||
hostDisconnected() {
|
||||
this.cancel();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Wrap the {execute} function in a try/catch block and return a tuple with the result and the error.
|
||||
*/
|
||||
async tryExecute<T>(): Promise<{data?: T, error?:ProblemDetails}> {
|
||||
async tryExecute<T>(): Promise<{ data?: T; error?: ProblemDetails }> {
|
||||
try {
|
||||
return {data: await this.#promise};
|
||||
return { data: await this.#promise };
|
||||
} catch (e) {
|
||||
return {error: toProblemDetails(e)};
|
||||
return { error: toProblemDetails(e) };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,8 +63,8 @@ export class UmbResourceController extends UmbController {
|
||||
* Wrap the {execute} function in a try/catch block and return the result.
|
||||
* If the executor function throws an error, then show the details in a notification.
|
||||
*/
|
||||
async tryExecuteAndNotify<T>(options?: UmbNotificationOptions<any>): Promise<{data?: T, error?:ProblemDetails}> {
|
||||
const {data, error} = await this.tryExecute<T>();
|
||||
async tryExecuteAndNotify<T>(options?: UmbNotificationOptions<any>): Promise<{ data?: T; error?: ProblemDetails }> {
|
||||
const { data, error } = await this.tryExecute<T>();
|
||||
|
||||
if (error) {
|
||||
const data: UmbNotificationDefaultData = {
|
||||
@@ -90,10 +81,9 @@ export class UmbResourceController extends UmbController {
|
||||
}
|
||||
}
|
||||
|
||||
return {data, error};
|
||||
return { data, error };
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Cancel all resources that are currently being executed by this controller if they are cancelable.
|
||||
*
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
import { UmbControllerHostInterface } from "../controller/controller-host.mixin";
|
||||
import type { ProblemDetails } from "../backend-api/models/ProblemDetails";
|
||||
import { UmbResourceController } from "./resource.controller";
|
||||
import { UmbNotificationOptions } from "src/backoffice/core/services/notification";
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import { UmbControllerHostInterface } from '../controller/controller-host.mixin';
|
||||
import type { ProblemDetails } from '../backend-api/models/ProblemDetails';
|
||||
import { UmbResourceController } from './resource.controller';
|
||||
import { UmbNotificationOptions } from 'src/backoffice/core/services/notification';
|
||||
|
||||
export async function tryExecuteAndNotify<T>(host:UmbControllerHostInterface, resource:Promise<T>, options?: UmbNotificationOptions<any>): Promise<{data?: T, error?:ProblemDetails}> {
|
||||
return await new UmbResourceController(host, resource).tryExecuteAndNotify<T>(options);
|
||||
}
|
||||
export async function tryExecuteAndNotify<T>(
|
||||
host: UmbControllerHostInterface,
|
||||
resource: Promise<T>,
|
||||
options?: UmbNotificationOptions<any>
|
||||
): Promise<{ data?: T; error?: ProblemDetails }> {
|
||||
return await new UmbResourceController(host, resource).tryExecuteAndNotify<T>(options);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user