hilla icon indicating copy to clipboard operation
hilla copied to clipboard

feat: add NumberSignal basic support

Open taefi opened this issue 1 year ago • 4 comments

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.getSignal();
  }
}

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>
  );
}

Fixes #2429

Type of change

  • [ ] Bugfix
  • [x] Feature

Checklist

  • [x] I have read the contribution guide: https://vaadin.com/docs/latest/guide/contributing/overview/
  • [x] I have added a description following the guideline.
  • [x] The issue is created in the corresponding repository and I have referenced it.
  • [ ] I have added tests to ensure my change is effective and works as intended.
  • [ ] New and existing tests are passing locally with my change.
  • [x] I have performed self-review and corrected misspellings.

Additional for Feature type of change

  • [x] Enhancement / new feature was discussed in a corresponding GitHub issue and Acceptance Criteria were created.

taefi avatar Jun 04 '24 14:06 taefi

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

Legioth avatar Jun 05 '24 07:06 Legioth

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

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

taefi avatar Jun 05 '24 08:06 taefi

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
@@            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 Coverage Δ
unittests 92.58% <92.85%> (+0.02%) :arrow_up:

Flags with carried forward coverage won't be shown. Click here to find out more.

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

codecov[bot] avatar Jun 05 '24 08:06 codecov[bot]

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

vaadin-bot avatar Jul 30 '24 08:07 vaadin-bot