rbxts-flamework / core

Flamework is an extensible game framework. It requires typescript and offers many useful features.
MIT License
101 stars 8 forks source link

offer @Decorator usage for events #77

Open bennsm opened 1 year ago

bennsm commented 1 year ago

current required code:

runEvent(){
    // handle event
}

onStart() {
        Events.testEvent.connect(() => {
            this.runEvent()
        });
       // other code
}

potential required code:

@testEvent()
runEvent(){
    // handle event
}

onStart(){
    // other code
}

it's so much cleaner

Sakyce commented 12 months ago

That's a really cool idea, it would be cool to see it added!

The decorator should be applied to components or services and have maid task automatically given to the connection.

@Component({})
export class TimeGui extends BaseComponent {

    @Connect(workspaceAttribs.getChangedSignal('TimeLeft')) // support for every signals
    private updateTime() {
        this.instance.Text = tostring(workspaceAttribs.get('TimeLeft'))
    }

}
Fireboltofdeath commented 12 months ago

That's a really cool idea, it would be cool to see it added!

The decorator should be applied to components or services and have maid task automatically given to the connection.

@Component({})
export class TimeGui extends BaseComponent {

  @Connect(workspaceAttribs.getChangedSignal('TimeLeft')) // support for every signals
  private updateTime() {
      this.instance.Text = tostring(workspaceAttribs.get('TimeLeft'))
  }

}

This is for @flamework/networking and not signals. Something like that would be out of scope for Flamework and could be implemented using the modding API or a custom decorator.