Skip to content

Commit

Permalink
feat: remove dead catching of exceptions
Browse files Browse the repository at this point in the history
BREAKING CHANGE: The dead catching of exceptions has been removed.
This may lead to unhandled exceptions in your code.
  • Loading branch information
atheck committed Aug 26, 2022
1 parent f717f5c commit 5caaf04
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 31 deletions.
8 changes: 1 addition & 7 deletions src/Common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,7 @@ function modelHasChanged<TModel> (currentModel: TModel, model: Partial<TModel>):
}

function execCmd<TMessage> (cmd: Cmd<TMessage>, dispatch: Dispatch<TMessage>): void {
cmd.forEach(call => {
try {
call(dispatch);
} catch (ex: unknown) {
Services.logger?.error(ex);
}
});
cmd.forEach(call => call(dispatch));
}

export {
Expand Down
22 changes: 9 additions & 13 deletions src/ElmComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,19 +96,15 @@ abstract class ElmComponent<TModel, TMessage extends Message, TProps> extends Re
while (nextMsg) {
logMessage(this.componentName, nextMsg);

try {
const [model, cmd] = this.update(this.currentModel, nextMsg, this.props);

if (modelHasChanged(this.currentModel, model)) {
this.currentModel = { ...this.currentModel, ...model };
modified = true;
}

if (cmd) {
execCmd(cmd, this.dispatch);
}
} catch (ex: unknown) {
Services.logger?.error(ex);
const [model, cmd] = this.update(this.currentModel, nextMsg, this.props);

if (modelHasChanged(this.currentModel, model)) {
this.currentModel = { ...this.currentModel, ...model };
modified = true;
}

if (cmd) {
execCmd(cmd, this.dispatch);
}

nextMsg = this.buffer.shift();
Expand Down
18 changes: 7 additions & 11 deletions src/useElmish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,20 +91,16 @@ function useElmish<TProps, TModel, TMessage extends MessageBase> ({ name, props,
while (nextMsg) {
logMessage(name, nextMsg);

try {
const [newModel, cmd] = callUpdate(update, nextMsg, { ...initializedModel, ...currentModel }, propsRef.current);
const [newModel, cmd] = callUpdate(update, nextMsg, { ...initializedModel, ...currentModel }, propsRef.current);

if (modelHasChanged(currentModel, newModel)) {
currentModel = { ...currentModel, ...newModel };
if (modelHasChanged(currentModel, newModel)) {
currentModel = { ...currentModel, ...newModel };

modified = true;
}
modified = true;
}

if (cmd) {
execCmd(cmd, dispatch);
}
} catch (ex: unknown) {
Services.logger?.error(ex);
if (cmd) {
execCmd(cmd, dispatch);
}

nextMsg = buffer.shift();
Expand Down

0 comments on commit 5caaf04

Please sign in to comment.