core icon indicating copy to clipboard operation
core copied to clipboard

offer @Decorator usage for events

Open bennsm opened this issue 2 years ago • 2 comments

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

bennsm avatar Feb 23 '23 21:02 bennsm

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'))
	}

}

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.

Fireboltofdeath avatar Sep 01 '23 15:09 Fireboltofdeath