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

Embedded web components: allow the web component to fire custom DOM events #5272

Closed
ujoni opened this issue Mar 14, 2019 · 10 comments
Closed
Assignees
Labels
demo embedding flow Issues for embedding Flow applications enhancement tutorial
Milestone

Comments

@ujoni
Copy link
Contributor

ujoni commented Mar 14, 2019

Allow web components produced by WebComponentExporter implementations to fire custom DOM events on the client-side.

The API needs further discussion!

Proposed interface (delivered to InstanceConfigurator):

public interface WebComponent extends Serializable {
    void fireEvent(String eventName);

    void fireEvent(String eventName, JsonValue objectData);

    void fireEvent(String eventName, JsonValue objectData,
                   EventOptions options);
}
@pleku
Copy link
Contributor

pleku commented Mar 14, 2019

Acceptance Criteria

The embedded application should be able to notify the embedding application about certain changes. These events are a part of the public API of the embedded application, and thus help decouple the embedding and the embedded application from each other.
The tutorial should be updated with an example of firing an event when e.g. a form has been saved.
The PetClinic example should be updated to fire an event when the form is saved, instead of updating the URL. (the Spring MVC app catches the event and then triggers the correct action)

@pleku
Copy link
Contributor

pleku commented Mar 14, 2019

Start with the API usage example and tutorial before going into the implementation.

@pleku pleku changed the title Embedded web components: allow the web component to publish custom DOM events Embedded web components: allow the web component to fire custom DOM events Mar 14, 2019
@pleku pleku added this to the 1.5.0.alpha2 milestone Mar 14, 2019
@Legioth
Copy link
Member

Legioth commented Mar 15, 2019

The issue description currently uses both "fire" and "publish" interchangeably for the same concept. Could we agree to always use the same word? Furthermore, can we agree to use the word "fire"?

@denis-anisimov denis-anisimov self-assigned this Mar 21, 2019
@denis-anisimov
Copy link
Contributor

denis-anisimov commented Mar 21, 2019

PetClinic example via firing a client side event on save (not working since the feature implementation is not available yet):
https://github.com/denis-anisimov/spring-petclinic/tree/fire-event

@denis-anisimov
Copy link
Contributor

@ujoni
Copy link
Contributor Author

ujoni commented Mar 21, 2019

As the #5259 is now in review, it provides the wiring that should make the implementation of this feature quite straight forward (soon).

But: we should probably run DX for the current web component thing before tacking this on or at least have small discourse about the current proposal.

Personally I find the example code in pet clinic to be pretty easy to follow but then again, I am super biased by now.

@denis-anisimov should I pick up the implementation portion of this, or do you fancy it?

@denis-anisimov
Copy link
Contributor

I'm OK if you take the implementation. Just assign yourself then.

If you are able to run DX somehow soon then please do it.

I personally see the current API a bit cumbersome: you need to set one more callback inside a callback. And I'm not event sure in fireEvent methods : I would do it just via calling JS directly than via API (may be we still should have API do "declare" that it's possible).

I will write here a sketch of the usage which I would prefer instead of the current one.

@denis-anisimov
Copy link
Contributor

So this code looks a bit complicated to me:

public class LoginFormExporter implements WebComponentExporter<LoginForm> {

    @Override
    public void define(WebComponentDefinition<LoginForm> definition) {
        definition.addProperty("userlbl", "")
                .onChange(LoginForm::setUserNameLabel);
        definition.addProperty("pwdlbl", "")
                .onChange(LoginForm::setPasswordLabel);

        definition.setInstanceConfigurator(this::initialize);
    }

    private void initialize(WebComponent<LoginForm> webComponent,
            LoginForm form) {
        form.addLoginListener(() -> webComponent.fireEvent("logged-in"));
    }
}

WebComponentExporter is SPI here. We require to set another callback (~ SPI) here : definition.setInstanceConfigurator.
It's too many callbacks for me.
I would prefer to have :

  • either WebComponentExporter implements InstanceConfigurator right away with no-op accept default impl.
  • or make it possible to implement InstanceConfigurator by the WebComponentExporter implementation (optionally).
    In the latest case instead of using the setInstanceConfigurator a developer may just implement InstanceConfigurator and our code will consider the WebComponentExporter impl as a InstanceConfigurator out of the box and use it.
    So one method call less.

Another thing is: form.addLoginListener(() -> webComponent.fireEvent("logged-in")).
It's good to have fireEvent method declared as API may be (it shows that this is possible).

But I personally would try this :

form.addLoginListener(() -> form.getElement().executeJavaScript("this.dispatchEvent( new CustomEvent ('logged-in'));"));

Yes, this code contains extra lines but it's strait-forward.
By the way: is it possible at all ? Is fireEvent method do the same as form.getElement().executeJavaScript("this.dispatchEvent( new CustomEvent (' ?
I would like to be able to reuse Element API in this way.

@denis-anisimov denis-anisimov removed their assignment Mar 22, 2019
@denis-anisimov
Copy link
Contributor

Preparations for this are done: tutorial and example code are updated.
Implementation requires changes from PR for #5259.
So let's wait for it to proceed with this ticket.

@ujoni ujoni self-assigned this Mar 25, 2019
@ujoni
Copy link
Contributor Author

ujoni commented Mar 26, 2019

Couple of questions about the interface:

  • The plan is to accept JsonValues as parameter, if any data is given - should this be expanded to accept the same primitives as the properties
  • Do we want to enforce some naming conventions, like converting camelCamel into kebab-case?

@pleku pleku added the embedding flow Issues for embedding Flow applications label Mar 26, 2019
denis-anisimov pushed a commit that referenced this issue Mar 27, 2019
denis-anisimov pushed a commit to vaadin/flow-and-components-documentation that referenced this issue Mar 28, 2019
@pleku pleku closed this as completed Apr 1, 2019
manolo pushed a commit that referenced this issue Apr 8, 2019
* Send service URL to the client side for Web Components UI (#5031)

Fixes #5044
Fixes #5027

* Remove dependency from data to html-components (#5050)

Fixes #5025

* Clarify StreamResource JavaDoc (#4981)

* 1.5-SNAPSHOT (#5055)

* Fix flow-component-renderer for Chrome 72 (#5060)

Fixes #5025, vaadin/vaadin-grid-flow#502

* Make the java doc return say the correct thing. (#5063)

* Shortcuts: change click shortcut's default behavior (#5058) (#5065)

* Deprecated @VaadinServletConfiguration (#5052)

* Update chrome driver version (#5020)

* Update byte buddy version (#5026)

* Update byte buddy version

Fixes #4956

* Fix version id in drivers (#5083)

* Deprecate getBodyAttributes and replace it with getHtmlAttributes (#5019) Fixes #4765

* Add IT test for push in embedded web components (#5059) Fixes #5006

* Add m2e lifecycle mapping for maven-antrun-plugin (#5087)

* Add m2e lifecycle mapping for maven-antrun-plugin

* Catch Throwable during maps sync handling (#5077)

* Shortcuts no longer work, when element is disabled (#5099)

* Shortcuts no longer work, when element is disabled

* Fix getChildCount to always use filter  (#5101) (Fixes vaadin-grid-flow/issues/464)

* Fix invalid null check (#5132)

* Javadoc - Add a component already added to a parent. (#5137)

* Document the fact that a component with a parent will be added to a new parent and removed from the previous one.

* Added Thread.sleeps to make sure Enter key is registered (#5139)

* flow-component-renderer: set focus-target attribute to the first focusable node (#5142)

Fixes #4191

Defining focus-target is necessary for the grid cell delegating focus to the first focusable component within it when Enter key is used (tests available from another PR on vaadin-grid-flow repo)

* Add some configuration for surefire plugin (#5144)

* Add some configuration for surefire plugin

Due to issues with tests run under Windows 10 we need to
add the trimStackTrace and reuseForks configurations also
to the surefire plugin

* Also update the surefire and failsafe plugins.

* Register push static web resources (#5112)

* Avoid for..of loop in renderer (#5171)

* Add DOM listeners before attaching the element (#5195)

Fixes #5152

* Add a generic mechanism for passing values back to the server (#5093)

This is an enabler for #1724 and #4925.

Fixes #4927

* Register superclass in case of route target collision (#5218)

Fixes #5114

* Introduce ValueChangeMode#LAZY, and #TIMEOUT (#4945)

Introduces ValueChangeMode#LAZY, and #TIMEOUT for delayed value synchronization to the server and makes Input implement HasValueChangeMode.

* Check the function presence before calling it (#5208)

Check the function presence before calling it and take care about children property as well.

Fixes #5206

* enable TrackMessageSizeInterceptor to deal with multiple messages in same response

* test for _trackMessageSize responsible to handle multiple messages coming from a single response

* refactor imports

* refactor TrackMessageSize test

* using IOUtils to read from InputStream

* Test for Long Polling when multiple threads run within a short period

* Enhanced code

* refactor getFileContent to use full path to retrieve vaadinPush.js

* Correct javadocs for DomEvent (#5215)

Fixes #5211

* Update jsoup version (#5253)

Fixes #4127

* Avoid indeterministic behavior in tests. (#5283)

Set locale explicitly in the tests.

Fixes #3500

* Handle empty attribute values properly in HTML element (#5255)

Fixes #5220

* Update chrome version in tests (#5295)

* Remove redundant words form javadocs (#5294)

Fixes #2770

* Update chromedriver version (#5297)

* Exporter-based embeddable web component impl. (#5260)

WebComponent is currently named IWebComponent to avoid naming collisions with
the existing classes - this will be fixed once the functionality has been
transferred over to the new components.

* Fixed a NPE problem in WebComponentConfigurationRegistry (#5304)

* Implement open and setLocation method to Page. (#4869) (#5166)

* Fix navigate back to main view don't work in FF and Safari . (#5113) (#5291)

* Register a servlet automatically if WCs present (#5331)

Fixes #5070

* EWC: push property updates to client (#5324)

* Apply theme for web component exporters (#5341)

Fix for #4984

* Only make banner the target of pointer events (#5343)

Currently the prompt consists of a full width transparent `#pwa-ip` div which is preventing click in elements behind it, and a `.banner` div which should be clickable

* WebComponent fireEvent implementation (#5340)

Implements #5272

* Fixes #5351 (#5358)

* Detect Push from WebComponentExporter classes (#5369), Fix for #4984

* Make exported web components work on hosts where https is proxied to http (#5374)

* Update config and generated class for rich-text-editor (#4754)

* Merge InstanceConfigurator with exporter (#5376) (Fixes #5332)

Also: Ignore abstract class in exporters discovering logic

* Use "create" semantic for the createComponent method (#5379)

Fixes #4634

* Avoid "web context" in web component module generation (#5391)

* Avoid "web context" in web component module generation

Fixes #5382

* Correct unit test

* Improve JS code

* Extract web component config factory (#5403)

Fixes #5402

* Correct generated template to work properly in production mode (#5421)

* Generate web component module file in the maven plugin to be able to transpile it (#5419)

* Initial preparation for web component module files generation

* Generate web component module content and add it into the bundle for
transpilation

* Generate web component module content and add the generated file into
the bundle file

* Hide common generation method

* Correct typos.

* Merge master into 2.0

Resolve the merge conflicts.

* Remove empty @SInCE javadocs

* Remove unused class

* Fix the test
manolo pushed a commit to vaadin/flow-and-components-documentation that referenced this issue Apr 26, 2019
* Updated to 14.0-SNAPSHOT (#546)

* Avoid linking to a third party web site (#537)

* use reserved example.com domain as example
 * use backslash to avoid displaying that as link

* Remove the unnecessary tutorial module (#545)

* Theming embedded components (#554)

* Theming embedded components

Part of flow#4984

* Add file extension (#556)

Fixes #550

* Extend the SSWC tutorial with fireEvent example. (#538)

Part of vaadin/flow#5272

* Add a note to the tutorial about automatic servlet registration (#540)

Part of vaadin/flow#5070

* Embedding web components: update properties and fire events tutorial (#555), completes #5259 and #5272

* Use relative link on doc reference (#558)

* Resolve jetty-server vulnerability (#561)

* Retrieving User Input Using the Element API (#495)

* Retrieving User Input Using the Element API

Edited content

* removed obsolete line (breaks build)

* Update documentation/element-api/tutorial-user-input.asciidoc

Co-Authored-By: ruthstocks <44681145+ruthstocks@users.noreply.github.com>

* Update tutorial-user-input.asciidoc

typo

* Add link to properties, update page number for ewc theming (#562)

* Document Push configuration for SSWC (#560) (Part of flow#5194)

* Dynamic Styling Using the Element API (#496)

* Dynamic Styling Using the Element API

Edited content

* Update documentation/element-api/tutorial-dynamic-styling.asciidoc

Co-Authored-By: ruthstocks <44681145+ruthstocks@users.noreply.github.com>

* Update documentation/element-api/tutorial-dynamic-styling.asciidoc

Co-Authored-By: ruthstocks <44681145+ruthstocks@users.noreply.github.com>

* Update documentation/element-api/tutorial-dynamic-styling.asciidoc

Co-Authored-By: ruthstocks <44681145+ruthstocks@users.noreply.github.com>

* Update tutorial-dynamic-styling.asciidoc

- Merged overlap content from Element Properties and Attributes

* Update tutorial-properties-attributes.asciidoc

- Deleted Using classLists and classNames and Using the Style Object sections (moved to Dynamic Styling page

* Update tutorial-dynamic-styling.asciidoc

minor edits

* moved source code to right file

* Update tutorial-flow-shortcut.asciidoc (#504)

* Update tutorial-flow-shortcut.asciidoc

- Edited content
- Moved the page higher in the page order

* Update documentation/components/tutorial-flow-shortcut.asciidoc

Co-Authored-By: ruthstocks <44681145+ruthstocks@users.noreply.github.com>

* Update documentation/components/tutorial-flow-shortcut.asciidoc

Co-Authored-By: ruthstocks <44681145+ruthstocks@users.noreply.github.com>

* Update documentation/components/tutorial-flow-shortcut.asciidoc

Co-Authored-By: ruthstocks <44681145+ruthstocks@users.noreply.github.com>

* Update documentation/components/tutorial-flow-shortcut.asciidoc

Co-Authored-By: ruthstocks <44681145+ruthstocks@users.noreply.github.com>

* Update documentation/components/tutorial-flow-shortcut.asciidoc

Co-Authored-By: ruthstocks <44681145+ruthstocks@users.noreply.github.com>

* Update documentation/components/tutorial-flow-shortcut.asciidoc

Co-Authored-By: ruthstocks <44681145+ruthstocks@users.noreply.github.com>

* Update tutorial-flow-shortcut.asciidoc

minor language edit

* Update tutorial-flow-shortcut.asciidoc

minor edits

* Update tutorial-router-dynamic-routes.asciidoc (#531)

Edited content

* Update tutorial-routing-lifecycle.asciidoc (#532)

- Edited the new Forward section.
- Added internal page links
- Other minor edits.

* Fix invalid link in the tutorial (#541)

Fixes #539

* Update tutorial with the recent API changes (#563)

* correct reference syntax (#559)

* Correct doc layout format (#557) (Fixes #551)

* Fix ParentPrefix -> RoutePrefix (#569)

* Add a tutorial about embedded wc in production mode

* Add verification file

* Correct sentences

* Update tutorial to match abstract WebComponentExporter approach

* Review fixes: dot + isAdultProperty

* Describe how to secure embedded component (#584)

* Add a tutorial about security in embedded web applications

* Add HTML verification file

* Correct wordings

* Update jetty.version to solve the vulnerability alert

* Merge branch 'master' into bu/2.0-merge-master

* Fix validation.
mehdi-vaadin pushed a commit to vaadin/flow-and-components-documentation that referenced this issue Jun 4, 2019
* Updated to 14.0-SNAPSHOT (#546)

* Avoid linking to a third party web site (#537)

* use reserved example.com domain as example
 * use backslash to avoid displaying that as link

* Remove the unnecessary tutorial module (#545)

* Theming embedded components (#554)

* Theming embedded components

Part of flow#4984

* Add file extension (#556)

Fixes #550

* Extend the SSWC tutorial with fireEvent example. (#538)

Part of vaadin/flow#5272

* Add a note to the tutorial about automatic servlet registration (#540)

Part of vaadin/flow#5070

* Embedding web components: update properties and fire events tutorial (#555), completes #5259 and #5272

* Use relative link on doc reference (#558)

* Resolve jetty-server vulnerability (#561)

* Retrieving User Input Using the Element API (#495)

* Retrieving User Input Using the Element API

Edited content

* removed obsolete line (breaks build)

* Update documentation/element-api/tutorial-user-input.asciidoc

Co-Authored-By: ruthstocks <44681145+ruthstocks@users.noreply.github.com>

* Update tutorial-user-input.asciidoc

typo

* Add link to properties, update page number for ewc theming (#562)

* Document Push configuration for SSWC (#560) (Part of flow#5194)

* Dynamic Styling Using the Element API (#496)

* Dynamic Styling Using the Element API

Edited content

* Update documentation/element-api/tutorial-dynamic-styling.asciidoc

Co-Authored-By: ruthstocks <44681145+ruthstocks@users.noreply.github.com>

* Update documentation/element-api/tutorial-dynamic-styling.asciidoc

Co-Authored-By: ruthstocks <44681145+ruthstocks@users.noreply.github.com>

* Update documentation/element-api/tutorial-dynamic-styling.asciidoc

Co-Authored-By: ruthstocks <44681145+ruthstocks@users.noreply.github.com>

* Update tutorial-dynamic-styling.asciidoc

- Merged overlap content from Element Properties and Attributes

* Update tutorial-properties-attributes.asciidoc

- Deleted Using classLists and classNames and Using the Style Object sections (moved to Dynamic Styling page

* Update tutorial-dynamic-styling.asciidoc

minor edits

* moved source code to right file

* Update tutorial-flow-shortcut.asciidoc (#504)

* Update tutorial-flow-shortcut.asciidoc

- Edited content
- Moved the page higher in the page order

* Update documentation/components/tutorial-flow-shortcut.asciidoc

Co-Authored-By: ruthstocks <44681145+ruthstocks@users.noreply.github.com>

* Update documentation/components/tutorial-flow-shortcut.asciidoc

Co-Authored-By: ruthstocks <44681145+ruthstocks@users.noreply.github.com>

* Update documentation/components/tutorial-flow-shortcut.asciidoc

Co-Authored-By: ruthstocks <44681145+ruthstocks@users.noreply.github.com>

* Update documentation/components/tutorial-flow-shortcut.asciidoc

Co-Authored-By: ruthstocks <44681145+ruthstocks@users.noreply.github.com>

* Update documentation/components/tutorial-flow-shortcut.asciidoc

Co-Authored-By: ruthstocks <44681145+ruthstocks@users.noreply.github.com>

* Update documentation/components/tutorial-flow-shortcut.asciidoc

Co-Authored-By: ruthstocks <44681145+ruthstocks@users.noreply.github.com>

* Update tutorial-flow-shortcut.asciidoc

minor language edit

* Update tutorial-flow-shortcut.asciidoc

minor edits

* Update tutorial-router-dynamic-routes.asciidoc (#531)

Edited content

* Update tutorial-routing-lifecycle.asciidoc (#532)

- Edited the new Forward section.
- Added internal page links
- Other minor edits.

* Fix invalid link in the tutorial (#541)

Fixes #539

* Update tutorial with the recent API changes (#563)

* correct reference syntax (#559)

* Correct doc layout format (#557) (Fixes #551)

* Fix ParentPrefix -> RoutePrefix (#569)

* Add a tutorial about embedded wc in production mode

* Add verification file

* Correct sentences

* Update tutorial to match abstract WebComponentExporter approach

* Review fixes: dot + isAdultProperty

* Describe how to secure embedded component (#584)

* Add a tutorial about security in embedded web applications

* Add HTML verification file

* Correct wordings

* Update jetty.version to solve the vulnerability alert

* Merge branch 'master' into bu/2.0-merge-master

* Fix validation.
mehdi-vaadin pushed a commit to vaadin/flow-and-components-documentation that referenced this issue Jun 5, 2019
* Updated to 14.0-SNAPSHOT (#546)

* Avoid linking to a third party web site (#537)

* use reserved example.com domain as example
 * use backslash to avoid displaying that as link

* Remove the unnecessary tutorial module (#545)

* Theming embedded components (#554)

* Theming embedded components

Part of flow#4984

* Add file extension (#556)

Fixes #550

* Extend the SSWC tutorial with fireEvent example. (#538)

Part of vaadin/flow#5272

* Add a note to the tutorial about automatic servlet registration (#540)

Part of vaadin/flow#5070

* Embedding web components: update properties and fire events tutorial (#555), completes #5259 and #5272

* Use relative link on doc reference (#558)

* Resolve jetty-server vulnerability (#561)

* Retrieving User Input Using the Element API (#495)

* Retrieving User Input Using the Element API

Edited content

* removed obsolete line (breaks build)

* Update documentation/element-api/tutorial-user-input.asciidoc

Co-Authored-By: ruthstocks <44681145+ruthstocks@users.noreply.github.com>

* Update tutorial-user-input.asciidoc

typo

* Add link to properties, update page number for ewc theming (#562)

* Document Push configuration for SSWC (#560) (Part of flow#5194)

* Dynamic Styling Using the Element API (#496)

* Dynamic Styling Using the Element API

Edited content

* Update documentation/element-api/tutorial-dynamic-styling.asciidoc

Co-Authored-By: ruthstocks <44681145+ruthstocks@users.noreply.github.com>

* Update documentation/element-api/tutorial-dynamic-styling.asciidoc

Co-Authored-By: ruthstocks <44681145+ruthstocks@users.noreply.github.com>

* Update documentation/element-api/tutorial-dynamic-styling.asciidoc

Co-Authored-By: ruthstocks <44681145+ruthstocks@users.noreply.github.com>

* Update tutorial-dynamic-styling.asciidoc

- Merged overlap content from Element Properties and Attributes

* Update tutorial-properties-attributes.asciidoc

- Deleted Using classLists and classNames and Using the Style Object sections (moved to Dynamic Styling page

* Update tutorial-dynamic-styling.asciidoc

minor edits

* moved source code to right file

* Update tutorial-flow-shortcut.asciidoc (#504)

* Update tutorial-flow-shortcut.asciidoc

- Edited content
- Moved the page higher in the page order

* Update documentation/components/tutorial-flow-shortcut.asciidoc

Co-Authored-By: ruthstocks <44681145+ruthstocks@users.noreply.github.com>

* Update documentation/components/tutorial-flow-shortcut.asciidoc

Co-Authored-By: ruthstocks <44681145+ruthstocks@users.noreply.github.com>

* Update documentation/components/tutorial-flow-shortcut.asciidoc

Co-Authored-By: ruthstocks <44681145+ruthstocks@users.noreply.github.com>

* Update documentation/components/tutorial-flow-shortcut.asciidoc

Co-Authored-By: ruthstocks <44681145+ruthstocks@users.noreply.github.com>

* Update documentation/components/tutorial-flow-shortcut.asciidoc

Co-Authored-By: ruthstocks <44681145+ruthstocks@users.noreply.github.com>

* Update documentation/components/tutorial-flow-shortcut.asciidoc

Co-Authored-By: ruthstocks <44681145+ruthstocks@users.noreply.github.com>

* Update tutorial-flow-shortcut.asciidoc

minor language edit

* Update tutorial-flow-shortcut.asciidoc

minor edits

* Update tutorial-router-dynamic-routes.asciidoc (#531)

Edited content

* Update tutorial-routing-lifecycle.asciidoc (#532)

- Edited the new Forward section.
- Added internal page links
- Other minor edits.

* Fix invalid link in the tutorial (#541)

Fixes #539

* Update tutorial with the recent API changes (#563)

* correct reference syntax (#559)

* Correct doc layout format (#557) (Fixes #551)

* Fix ParentPrefix -> RoutePrefix (#569)

* Add a tutorial about embedded wc in production mode

* Add verification file

* Correct sentences

* Update tutorial to match abstract WebComponentExporter approach

* Review fixes: dot + isAdultProperty

* Describe how to secure embedded component (#584)

* Add a tutorial about security in embedded web applications

* Add HTML verification file

* Correct wordings

* Update jetty.version to solve the vulnerability alert

* Merge branch 'master' into bu/2.0-merge-master

* Fix validation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
demo embedding flow Issues for embedding Flow applications enhancement tutorial
Projects
None yet
Development

No branches or pull requests

4 participants