Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

event decorator for components #115

Merged
merged 13 commits into from
Jul 5, 2022
Merged

Conversation

muratcorlu
Copy link
Contributor

@muratcorlu muratcorlu commented May 20, 2022

@event decorator implementation.

Usage:

class EventCustomNameComp extends LitElement {
  @event('bl-test') test: EventDispatcher<string>;

  render() {
    return html`<button
      @click=${() => this.test('test event')}
    ></button>`;
  }
}

With a custom event data type:

class MyFile {
  constructor(public file: string, public size: number) {}
}

class EventCustomTypeComp extends LitElement {
  @event() uploadDone: EventDispatcher<MyFile>;

  render() {
    const file = new MyFile('abc.js', 21312312);
    return html`<button
      @click=${() => this.uploadDone(file)}
    ></button>`;
  }
}

@muratcorlu muratcorlu linked an issue May 20, 2022 that may be closed by this pull request
2 tasks
@muratcorlu
Copy link
Contributor Author

I'm considering changing EventDispatcher as a simpler function instead of a class. So I'm holding this for now.

@muratcorlu
Copy link
Contributor Author

I changed EventDispatcher as a function so triggering an event is not just calling this function. Outcomes of this work:

  • Less crowded event dispatching in components.
  • Easy to read and notice event definitions.
  • Setting and documenting types of event data.
  • We are able to write event descriptions inline like we can for properties.

Also currently Storybook show a wrong event definition in next branch like below:

image

This PR fixes this too.

I simplified how we document our properties in our component classes by moving description comments to top of every property. Like:

  /**
   * Adds help text
   */
  @property({ type: String, attribute: 'help-text' })
  helpText?: string;

  /**
   * Fires when an alteration to the element's value is committed by the user. Unlike the input event, the change event is not necessarily fired for each alteration to an element's value.
   */
  @event('bl-change') private onChange: EventDispatcher<string>;

@leventozen Please have a look again if this is still good.

@muratcorlu muratcorlu changed the title 113 event decorator for components event decorator for components Jul 4, 2022
Copy link
Member

@leventozen leventozen left a comment

Choose a reason for hiding this comment

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

Great job!

@sonarcloud
Copy link

sonarcloud bot commented Jul 5, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

100.0% 100.0% Coverage
0.0% 0.0% Duplication

@muratcorlu muratcorlu merged commit 120deea into next Jul 5, 2022
@muratcorlu muratcorlu deleted the 113-event-decorator-for-components branch July 5, 2022 21:47
mehmetranas pushed a commit that referenced this pull request Jul 19, 2022
* chore: testing utilities fine tuned

* feat: event decorator draft

* test: event decorator test coverage increase

* fix: linter fixes

* feat: event decorator as simple function

* refactor: some cleanup

* refactor: fix redeclared variable name issue
@github-actions
Copy link

🎉 This PR is included in version 2.0.0-beta.13 🎉

The release is available on:

Your semantic-release bot 📦🚀

@github-actions
Copy link

github-actions bot commented Apr 6, 2023

🎉 This PR is included in version 2.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

event decorator for components
3 participants