Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BattlePreview has fatal error due to not recognizing scored battles as abstract battles. #245

Open
JasonReed-2 opened this issue Sep 5, 2023 · 0 comments · May be fixed by #246
Open

BattlePreview has fatal error due to not recognizing scored battles as abstract battles. #245

JasonReed-2 opened this issue Sep 5, 2023 · 0 comments · May be fixed by #246

Comments

@JasonReed-2
Copy link
Contributor

JasonReed-2 commented Sep 5, 2023

Issue
When clicking on "Multiplayer" tab, I receive this error:
image

Impact
Users can't open the custom battle list browser. Also: letting this error sit with the electron app open will cause a massive slowdown as it eats up all the computers memory :(

Investigation
Looking at this code:
image

When debugged: props.battle.contenders is actually ComputedRefImpl object. To access the value, it should be "props.battle.contenders.value".

So the code is recognizing the battle as a Replay when it actually should recognized as an AbstractBattle and enter the if block where the ComputedRefImpl objects are handled appropriately.

So why is the battle being treated as a replay and not a battle?

Looking in type-checkers.ts:
image

So we only recognize a battle as an abstract battle if instanceof abstract battle. Explanation of instanceof from stackoverflow: https://stackoverflow.com/questions/2449254/what-is-the-instanceof-operator-in-javascript

tldr: instanceof checks that the object has the constructor for the given class.

So that means that an object must be instantiated using the constructor of the class [or subclass] to be recognized by instanceof.

Looking at custom.vue in scoreBattle function:
image

So while typescript recognizes this as a scoredSpadsBattle: instanceof will not because the object wasn't created used the constructor of a subclass of AbstractBattle.

Solution
Fold the scored battles data into the SpadsBattle class. Have the custom.vue component interact with the scored battles data that is stored within the SpadsBattle.

@JasonReed-2 JasonReed-2 linked a pull request Sep 5, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant