Code Monkey home page Code Monkey logo

Comments (6)

mshabarov avatar mshabarov commented on June 12, 2024

We can create a new interface and move there the functionality from ReactAdapterComponent, and then keep the ReactAdapterComponent abstract class as a shortcut for simple cases that implements this new interface and extends Component. What do you think?

Also, maybe a separate docs issue - we need an example of how to wrap a React component as a Flow field, e.g. to be able to use it with the Binder on a form.

from flow.

jcgueriaud1 avatar jcgueriaud1 commented on June 12, 2024

As long as we can have an interface to avoid the boilerplate, I'm not against a abstract class in addition. I don't know if that will make things easier.

With ReactAdapterComponent class:

@JsModule("./react-component.tsx")
@Tag("react-component")
public class ReactMonthYearField
        extends ReactAdapterComponent {

With the interface:

@JsModule("./react-component.tsx")
@Tag("react-component")
public class ReactMonthYearField
        extends Component
        implements IReactAdapter {

Also, maybe a separate docs issue - we need an example of how to wrap a React component as a Flow field, e.g. to be able to use it with the Binder on a form.

Or a blog post, it depends a bit of what you want to implement (HasTooltip, HasLabel, HasHelper, HasValidation,...), that can be tough.
And that could be done for Lit or a webcomponent also :).

But at least in the repository I linked (https://github.com/jcgueriaud1/vaadin-react-field/), you have an example for both React and Lit.

from flow.

Legioth avatar Legioth commented on June 12, 2024

I don't think an interface is the right option since interfaces define the public API of a class and you wouldn't want to make methods like setState part of the API that users of your component would see.

Instead, there might be an opportunity for a "connector" that you can use from your component. A simple example could thus look like this:

@Tag("some-tag")
@JsModule("./someModule")
public class MyComponent extends SomeOtherComponent {
  private final ReactComponentConnector connector = new ReactComponentConnector(this);
  public void setValue(String value) {
    connector.setState("value", value);
  }
}

from flow.

jcgueriaud1 avatar jcgueriaud1 commented on June 12, 2024

I've just noticed that I'm not using the interface at all, since I'm using getElement().setProperty("invalid", invalid); and not setState("invalid",invalid);

I think the connector could handle the other case and leave everything protected. (I'm not sure if everything can be handled with properties)

from flow.

Legioth avatar Legioth commented on June 12, 2024

The implementation of ReactAdapterComponent is basically just some helpers around Element::setPropertyJson, Element::getPropertyRaw and Element::addPropertyChangeListener. All of the actual magic is handled by Flow and/or the client-side base class for the custom element.

from flow.

knoobie avatar knoobie commented on June 12, 2024

thumbs up for the connector idea This would allow the usage of AbstractSinglePropertyField and other important classes without cluttering the public interface.

from flow.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.