vaadin / hilla

Build better business applications, faster. No more juggling REST endpoints or deciphering GraphQL queries. Hilla seamlessly connects Spring Boot and React to accelerate application development.
https://hilla.dev
Apache License 2.0
904 stars 57 forks source link

feat: add NumberSignal basic support #2502

Closed taefi closed 2 months ago

taefi commented 4 months ago

Description

Add basic support for full-stack NumberSignal type to be returned by endpoints as a shared signal instance that supports number value operations. The client-side user code (for now) need to do manual wrapping of the needed metadata about the endpoint method(s) that return shared signal instance(s).

Assuming a simple endpoint returning a NumberSignal instance like this:

import com.vaadin.hilla.signals.NumberSignal;
import com.vaadin.flow.server.auth.AnonymousAllowed;
import com.vaadin.hilla.BrowserCallable;

@AnonymousAllowed
@BrowserCallable
public class SharedCounterService {
    private final NumberSignal counter = new NumberSignal(0);

    public NumberSignal counter() {
        return counter;
    }
}

The needed manually written user code is like this (this will be generated later):

import { NumberSignalQueue } from "@vaadin/hilla-react-signals";
import client_1 from "Frontend/generated/connect-client.default";

export class CounterServiceWrapper {
  static counter() {
    const signalChannel = new NumberSignalChannel('SharedCounterService.counter', client_1);
    return signalChannel.signal;
  }
}

Then then usage of this wrapping service in views could be similar to what is described in the related issue:

const counter = CounterServiceWrapper.counter();

export default function NumberSignalView() {
  return (
    <Button onClick={() => counter.value++}>
       Click count: { counter }
    </Button>
  );
}

NOTE: Since the Full-stack signals are experimental for now, please don't forget to enable the fullstackSignals feature flag in your applications (by adding the following in src/main/resources/vaadin-featureflags.properties):

com.vaadin.experimental.fullstackSignals=true

Fixes #2429

Type of change

Checklist

Additional for Feature type of change

Legioth commented 4 months ago

Why is package-lock.json changed without any corresponding change to package.json?

taefi commented 4 months ago

Why is package-lock.json changed without any corresponding change to package.json?

Good catch. That was unintentionally committed/pushed. Reverted.

codecov[bot] commented 4 months ago

Codecov Report

Attention: Patch coverage is 92.85714% with 2 lines in your changes missing coverage. Please review.

Project coverage is 92.58%. Comparing base (03d9b0f) to head (fd70ae0).

Files Patch % Lines
packages/ts/react-crud/src/autogrid-columns.tsx 0.00% 0 Missing and 1 partial :warning:
packages/ts/react-signals/src/Signals.ts 87.50% 1 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #2502 +/- ## ========================================== + Coverage 92.56% 92.58% +0.02% ========================================== Files 69 71 +2 Lines 2245 2265 +20 Branches 590 591 +1 ========================================== + Hits 2078 2097 +19 - Misses 120 121 +1 Partials 47 47 ``` | [Flag](https://app.codecov.io/gh/vaadin/hilla/pull/2502/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=vaadin) | Coverage Δ | | |---|---|---| | [unittests](https://app.codecov.io/gh/vaadin/hilla/pull/2502/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=vaadin) | `92.58% <92.85%> (+0.02%)` | :arrow_up: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=vaadin#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

sonarcloud[bot] commented 3 months ago

Quality Gate Passed Quality Gate passed

Issues
7 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

sonarcloud[bot] commented 2 months ago

Quality Gate Passed Quality Gate passed

Issues
1 New issue
0 Accepted issues

Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud

vaadin-bot commented 2 months ago

This ticket/PR has been released with Hilla 24.5.0.alpha6 and is also targeting the upcoming stable 24.5.0 version.