-
Notifications
You must be signed in to change notification settings - Fork 0
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
[WIP] Services can trace programs. #48
Conversation
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@taisii キャラクタ変数とそれ以外の変数を分ける部分についてコメントしましたー
JSON.stringify(traceList); | ||
`.replaceAll(/\s+/g, ' '); | ||
const ret: Trace[] = JSON.parse(eval(codeForTracing)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ここのタイミングでJSON化とパースを経由しているため、variableValue
はクラスのインスタンスではなく、ただのオブジェクトになっていますね。
const { variableName, variableValue } = traceList[index]; | ||
const variablesIndex = variables.findIndex((variable) => variable.name === variableName); | ||
if (variablesIndex === -1) { | ||
if (variableValue instanceof CharacterClass) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
variableValue.constructor.name
-> Object
になるので True にならなさそうです。
オブジェクトのまま検証する場合、ユーザー定義型ガード?のようなもので型を使って検証すればうまくいくかもしれません。
e.g.
const isCharacter = (value: unknown): value is Character => {
const characterValue = value as Character;
return typeof characterValue.name === 'string' &&
typeof characterValue.x === 'number' &&
typeof characterValue.y === 'number' &&
typeof characterValue.direction === 'string' &&
typeof characterValue.color === 'string' &&
typeof characterValue.penDown === 'boolean';
}
別の方法でトレースを実現したので閉じます。 |
Close #46
Self Check
All checks have passed
on PR page. (You may leave this box unchecked due to long workflows.)WIP:
.yarn test
) is passed.yarn lint
) is passed.