Conversation
WebFreak001
commented
Apr 7, 2020
- removed some dead/untested code for UDAs
- documented the UDAs in spasm.types
| * Supports 2 kinds of overloads: | ||
| * `@connect!"someMember.someEvent"` with an arbitrary string to add this | ||
| * function into. Most commonly some kind of `"button.click"` string. | ||
| * `@connect!("someMember", "someEvent")` which is the same as using a single |
There was a problem hiding this comment.
This second form is used when you want to connect to slots from elements that are in a List.
Note the idx it receives.
struct Item {
mixin Node!"li";
mixin Slot!"click";
@prop string innerText;
@callback void onClick(MouseEvent event) {
this.emit(click);
}
}
struct App {
mixin Node!"div";
@child UnorderedList!Item list;
@connect!("list.items","click") void itemClick(size_t idx) {
}
}
mixin Spa!App;There was a problem hiding this comment.
but if you look at the implementation it is really nothing else than
mixin("t."~a~"."~replace!(b,'.','_')~".add(del);");so basically the same as the single overload, which is why I documented it that way. Should there maybe be some more constraints on this?
There was a problem hiding this comment.
There is an implicit contract between this line and the ArrayItemEvents mixin which generates the functions that handles these.
An assert that "list.items" is of type Array!(T) would help a bit.
There was a problem hiding this comment.
shouldn't that much rather use a new other UDA than @connect?
Currently this also uses some magic ".items" suffix in the connect string, which is confusing for beginners
There was a problem hiding this comment.
Sure, if you can come up with a good name. I am stuck at @connectList or @connectItem...
There was a problem hiding this comment.
I think @connectItem or @connectItems would make sense, visible to auto completion and very easy to migrate