I`m trying to make a game MVC library in typescript. My language is typescript and I struggle with reflection and decorators. Also I playing a lot with Nestjs and I like that style of decorating.
I thing I can solve problem in my library with reflection and decorators.
The problem
The method "reduce" is invoked when something like button clicked or animation completed happening. So when something like that happened I want somehow to pass "diceAnimation.playing" to "reduce" method. Or to serialize diceAnimation.playing with reducer.dicePlaying and than call "reduce" method.
The code example
export class DiceAnimation {
private _playing: boolean
set playing(val: boolean) {
this._playing = val
}
// Here I want to export information to be used in other system. Is that even possible ?
@animProp
get playing(): boolean {
return this._playing
}
}
export class Reducer {
// Variant 1.
// Here I want to import information from DiceAnimation instance. Is that even possible?
@getAnimProp("DiceAnimation", "playing")
dicePlaying: boolean
// Variant 2.
// Here I want to import information from DiceAnimation instance. Is that even possible?
reduce(@getAnimProp("DiceAnimation", "playing") dicePlaying: boolean,): any {
// logic
}
}
// Decorator functions.
export function animProp() {
}
export function getAnimProp() {
}
So is that possible and how ?
Thank you very much !
Aucun commentaire:
Enregistrer un commentaire