From 16ebcf70c994881f40b9852493698d2a0af9e609 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Fri, 31 Jul 2020 09:41:19 -0600 Subject: [PATCH 1/3] Clean up documentation of Whenable --- src/utils/Whenable.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils/Whenable.ts b/src/utils/Whenable.ts index afa220fe82..49f2571965 100644 --- a/src/utils/Whenable.ts +++ b/src/utils/Whenable.ts @@ -41,7 +41,7 @@ export abstract class Whenable implements IDestroyable { } /** - * Sets up a fall to `fn` *when* any of the `conditions` are met. + * Sets up a call to `fn` *when* any of the `conditions` are met. * @param conditions The conditions to match. * @param fn The function to call. * @returns This. @@ -64,7 +64,7 @@ export abstract class Whenable implements IDestroyable { } /** - * Notifies all the whenables of a given condition. + * Notifies all the listeners of a given condition. * @param condition The new condition that has been met. */ protected notifyCondition(condition: T) { From 7645fe6b236c9e1a5e0afdd9bbe21ea5c02f8071 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Fri, 31 Jul 2020 10:00:02 -0600 Subject: [PATCH 2/3] Update context transaction states --- .../views/dialogs/ServerOfflineDialog.tsx | 4 ++-- src/stores/local-echo/EchoContext.ts | 6 +++--- src/stores/local-echo/EchoTransaction.ts | 16 ++++++++-------- src/stores/local-echo/GenericEchoChamber.ts | 2 +- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/components/views/dialogs/ServerOfflineDialog.tsx b/src/components/views/dialogs/ServerOfflineDialog.tsx index 6d2aa5ac27..f6767dcb8d 100644 --- a/src/components/views/dialogs/ServerOfflineDialog.tsx +++ b/src/components/views/dialogs/ServerOfflineDialog.tsx @@ -56,10 +56,10 @@ export default class ServerOfflineDialog extends React.PureComponent { ); const entries = c.transactions - .filter(t => t.status === TransactionStatus.DoneError || t.didPreviouslyFail) + .filter(t => t.status === TransactionStatus.Error || t.didPreviouslyFail) .map((t, j) => { let button = ; - if (t.status === TransactionStatus.DoneError) { + if (t.status === TransactionStatus.Error) { button = ( t.run()}>{_t("Resend")} ); diff --git a/src/stores/local-echo/EchoContext.ts b/src/stores/local-echo/EchoContext.ts index 9ed5cf387f..55d6e8020a 100644 --- a/src/stores/local-echo/EchoContext.ts +++ b/src/stores/local-echo/EchoContext.ts @@ -38,7 +38,7 @@ export abstract class EchoContext extends Whenable impl } public get firstFailedTime(): Date { - const failedTxn = this.transactions.find(t => t.didPreviouslyFail || t.status === TransactionStatus.DoneError); + const failedTxn = this.transactions.find(t => t.didPreviouslyFail || t.status === TransactionStatus.Error); if (failedTxn) return failedTxn.startTime; return null; } @@ -57,7 +57,7 @@ export abstract class EchoContext extends Whenable impl // We have no intent to call the transaction again if it succeeds (in fact, it'll // be really angry at us if we do), so call that the end of the road for the events. - txn.when(TransactionStatus.DoneSuccess, () => txn.destroy()); + txn.when(TransactionStatus.Success, () => txn.destroy()); return txn; } @@ -65,7 +65,7 @@ export abstract class EchoContext extends Whenable impl private checkTransactions = () => { let status = ContextTransactionState.AllSuccessful; for (const txn of this.transactions) { - if (txn.status === TransactionStatus.DoneError || txn.didPreviouslyFail) { + if (txn.status === TransactionStatus.Error || txn.didPreviouslyFail) { status = ContextTransactionState.PendingErrors; break; } else if (txn.status === TransactionStatus.Pending) { diff --git a/src/stores/local-echo/EchoTransaction.ts b/src/stores/local-echo/EchoTransaction.ts index 543c3b4ccd..2e372136d0 100644 --- a/src/stores/local-echo/EchoTransaction.ts +++ b/src/stores/local-echo/EchoTransaction.ts @@ -20,8 +20,8 @@ export type RunFn = () => Promise; export enum TransactionStatus { Pending, - DoneSuccess, - DoneError, + Success, + Error, } export class EchoTransaction extends Whenable { @@ -46,25 +46,25 @@ export class EchoTransaction extends Whenable { } public run() { - if (this.status === TransactionStatus.DoneSuccess) { + if (this.status === TransactionStatus.Success) { throw new Error("Cannot re-run a successful echo transaction"); } this.setStatus(TransactionStatus.Pending); this.runFn() - .then(() => this.setStatus(TransactionStatus.DoneSuccess)) - .catch(() => this.setStatus(TransactionStatus.DoneError)); + .then(() => this.setStatus(TransactionStatus.Success)) + .catch(() => this.setStatus(TransactionStatus.Error)); } public cancel() { // Success basically means "done" - this.setStatus(TransactionStatus.DoneSuccess); + this.setStatus(TransactionStatus.Success); } private setStatus(status: TransactionStatus) { this._status = status; - if (status === TransactionStatus.DoneError) { + if (status === TransactionStatus.Error) { this.didFail = true; - } else if (status === TransactionStatus.DoneSuccess) { + } else if (status === TransactionStatus.Success) { this.didFail = false; } this.notifyCondition(status); diff --git a/src/stores/local-echo/GenericEchoChamber.ts b/src/stores/local-echo/GenericEchoChamber.ts index 7bedc9bde8..f2d4648e81 100644 --- a/src/stores/local-echo/GenericEchoChamber.ts +++ b/src/stores/local-echo/GenericEchoChamber.ts @@ -84,7 +84,7 @@ export abstract class GenericEchoChamber extends Ev this.cacheVal(key, targetVal, txn); // set the cache now as it won't be updated by the .when() ladder below. txn.when(TransactionStatus.Pending, () => this.cacheVal(key, targetVal, txn)) - .when(TransactionStatus.DoneError, () => revertFn()); + .when(TransactionStatus.Error, () => revertFn()); txn.run(); } From c888b1f40102b7e0fbebedd2bb15c880a0a876b3 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Fri, 31 Jul 2020 10:00:53 -0600 Subject: [PATCH 3/3] It's a Context Transaction (ctxn) now --- src/stores/local-echo/GenericEchoChamber.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/stores/local-echo/GenericEchoChamber.ts b/src/stores/local-echo/GenericEchoChamber.ts index f2d4648e81..7a2173f702 100644 --- a/src/stores/local-echo/GenericEchoChamber.ts +++ b/src/stores/local-echo/GenericEchoChamber.ts @@ -80,12 +80,12 @@ export abstract class GenericEchoChamber extends Ev this.cache.get(key).txn.cancel(); } - const txn = this.context.beginTransaction(auditName, runFn); - this.cacheVal(key, targetVal, txn); // set the cache now as it won't be updated by the .when() ladder below. + const ctxn = this.context.beginTransaction(auditName, runFn); + this.cacheVal(key, targetVal, ctxn); // set the cache now as it won't be updated by the .when() ladder below. - txn.when(TransactionStatus.Pending, () => this.cacheVal(key, targetVal, txn)) + ctxn.when(TransactionStatus.Pending, () => this.cacheVal(key, targetVal, ctxn)) .when(TransactionStatus.Error, () => revertFn()); - txn.run(); + ctxn.run(); } }