englercj / type-signals

Small and fast Signal library for Typescript.

Home Page:http://englercj.github.io/type-signals/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Perhaps adding an example without args?

alamboley opened this issue · comments

Hey, I'm not very familiar with TypeScript, it tooks me some time to figure that I needed this syntax: public onPhoneClicked = new Signal<() => void>(); for this to work this.onPhoneClicked.dispatch();. I thought public onPhoneClicked = new Signal(); would be enough.

We can make the template arg have a default of an empty function, it just doesn't currently so you always have to specify the generic argument.

Actually it does have that default, doing new Signal() should work fine.

Just released v1.1.0 which contains the default changes. Didn't realize I made those changes but didn't release them, sorry!

Thank you for the update 🚀

Hello, having a doubt with TypeScript syntax and one arg.

I dispatch the signal that way this._picture.on("pointerdown", () => this.onTakePicture.dispatch(new Point(this.x + this.width * 0.5, this.y + this.height * 0.5)));.
I thought I would declare: public onTakePicture = new Signal<Point>(); but it rises compiler issue, does public onTakePicture = new Signal<(p:Point) => void>(); is the correct format?

Thanks !

Yes just like the sample in the readme you give the type of the dispatch function.

Typescript doesn't have variable type arguments, so it can't just take the type of the arguments. I work around that by taking a function type and extracting the argument types.