Skip to content

Improve docs#49

Open
WebFreak001 wants to merge 4 commits intoskoppe:masterfrom
WebFreak001:improve-docs
Open

Improve docs#49
WebFreak001 wants to merge 4 commits intoskoppe:masterfrom
WebFreak001:improve-docs

Conversation

@WebFreak001
Copy link
Contributor

  • 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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, if you can come up with a good name. I am stuck at @connectList or @connectItem...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think @connectItem or @connectItems would make sense, visible to auto completion and very easy to migrate

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Singular item would work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants