Skip to content

Commit 390b34f

Browse files
committed
remove Promise.done() since onunhandledrejection does it authomatically
1 parent a359d8c commit 390b34f

File tree

5 files changed

+26
-11
lines changed

5 files changed

+26
-11
lines changed

Signum.React/Scripts/Globals.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ declare global {
44
escape(s: string): string;
55
}
66

7-
interface Promise<T> {
8-
done(this: Promise<T>): void;
9-
}
10-
117
interface Window {
128
__allowNavigatorWithoutUser?: boolean;
139
__baseUrl: string;
@@ -906,10 +902,6 @@ String.prototype.repeat = function (this: string, n: number) {
906902
return result;
907903
};
908904

909-
Promise.prototype.done = function () {
910-
this.catch(error => setTimeout(() => { throw error; }, 0));
911-
};
912-
913905
export module Dic {
914906

915907
var simplesTypes = ["number", "boolean", "string"];

Signum.React/Scripts/Modals/ErrorModal.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,14 @@ export default function ErrorModal(p: ErrorModalProps) {
103103

104104
ErrorModal.register = () => {
105105

106+
window.onunhandledrejection = p => {
107+
var error = p.reason;
108+
if (Modals.isStarted())
109+
ErrorModal.showErrorModal(error).done();
110+
else
111+
console.error("Unhandled promise rejection:", error);
112+
};
113+
106114
var oldOnError = window.onerror;
107115
window.onerror = (message: Event | string, filename?: string, lineno?: number, colno?: number, error?: Error) => {
108116

Signum.React/Scripts/Services.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ export function wrapRequest(options: AjaxOptions, makeCall: () => Promise<Respon
131131

132132
const promise = makeCall();
133133

134-
if (!(promise as any).__proto__.done)
135-
(promise as any).__proto__.done = Promise.prototype.done;
134+
if (!(promise as any).__proto__)
135+
(promise as any).__proto__ = Promise.prototype;
136136

137137
return promise;
138138

Signum.Upgrade/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ static void Main(string[] args)
2121
Console.Write(" ApplicationName = "); SafeConsole.WriteLineColor(ConsoleColor.DarkGray, uctx.ApplicationName);
2222

2323

24-
//UpgradeContext.DefaultIgnoreDirectories = UpgradeContext.DefaultIgnoreDirectories.Where(a => a != "Framework").ToArray();
24+
UpgradeContext.DefaultIgnoreDirectories = UpgradeContext.DefaultIgnoreDirectories.Where(a => a != "Framework").ToArray();
2525

2626
new CodeUpgradeRunner(autoDiscover: true).Run(uctx);
2727
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
namespace Signum.Upgrade.Upgrades;
2+
3+
class Upgrade_20220805_DoneIsDone : CodeUpgradeBase
4+
{
5+
public override string Description => "Remove .done() (rejectionhandled does it)";
6+
7+
public static Regex DoneRegex = new Regex(@"\s*\.done\(\)");
8+
public override void Execute(UpgradeContext uctx)
9+
{
10+
uctx.ForeachCodeFile(@"*.tsx, *.ts", file =>
11+
{
12+
file.Replace(DoneRegex, "");
13+
});
14+
}
15+
}

0 commit comments

Comments
 (0)