From 9adef31dcbc42b47e81bc1ee1f304fc3b99c9ead Mon Sep 17 00:00:00 2001 From: Ryan Goree Date: Fri, 22 Dec 2023 12:18:35 -0600 Subject: [PATCH] Polish context.execute result mgmt --- packages/clide-js/src/core/context.ts | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/packages/clide-js/src/core/context.ts b/packages/clide-js/src/core/context.ts index d91f7db..6561d13 100644 --- a/packages/clide-js/src/core/context.ts +++ b/packages/clide-js/src/core/context.ts @@ -300,15 +300,17 @@ export class Context { let _initialData = initialData; let skip = false; + let newResult = initialData; await this.hooks.call('preExecute', { initialData, state, setInitialData: (data) => { _initialData = data; + newResult = data; }, setResultAndSkip: (result) => { - this._result = result; + newResult = result; skip = true; }, skip: () => { @@ -330,25 +332,21 @@ export class Context { if (!skip) { try { await state.start(_initialData); + newResult = state.data; } catch (error) { await this.throw(error); } } - let didOverrideResult = false; - await this.hooks.call('postExecute', { - result: this._result, + result: newResult, state, setResult: (result) => { - this._result = result; - didOverrideResult = true; + newResult = result; }, }); - // Only set the result to the state's data if it wasn't overridden by the - // postExecute hook and the command wasn't skipped - if (!didOverrideResult && !skip) this._result = state.data; + this._result = newResult; }; /**