Rozwiązania 9.12 #27
kewinzaq1
started this conversation in
Zadania i rozwiązania
Replies: 1 comment
-
export interface Tool {
init: () => void
update: () => void
dispose: () => void
}
const ERROR_MESSAGE_BEFORE_INIT =
'Cannot update any tools before initialization.'
export class Equipment<T extends Tool = Tool> {
tools: Array<T> = []
initIndexes = new Set<number>()
registerTools(tool: T) {
this.tools.push(tool)
}
initializeTools() {
this.tools.forEach((tool, index) => {
tool.init()
this.initIndexes.add(index)
})
}
updateTools() {
this.tools.forEach((tool, index) => {
if (!this.initIndexes.has(index)) {
throw new Error(ERROR_MESSAGE_BEFORE_INIT)
}
tool.update()
})
}
disposeTools() {
this.tools.forEach(tool => {
tool.dispose()
})
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Wasze rozwiązania 9.12.2023
Beta Was this translation helpful? Give feedback.
All reactions