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

feat: add NumberSignal basic support #2502

Merged
merged 49 commits into from
Jul 26, 2024
Merged

Conversation

taefi
Copy link
Contributor

@taefi taefi commented Jun 4, 2024

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

  • Bugfix
  • Feature

Checklist

  • I have read the contribution guide: https://vaadin.com/docs/latest/guide/contributing/overview/
  • I have added a description following the guideline.
  • 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.
  • I have performed self-review and corrected misspellings.

Additional for Feature type of change

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

@taefi taefi changed the title Taefi/add number signal basics feat: add NumberSignal basic support Jun 4, 2024
@Legioth
Copy link
Member

Legioth commented Jun 5, 2024

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

@taefi
Copy link
Contributor Author

taefi commented Jun 5, 2024

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

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

Copy link

codecov bot commented Jun 5, 2024

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 ⚠️
packages/ts/react-signals/src/Signals.ts 87.50% 1 Missing ⚠️
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%) ⬆️

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@taefi taefi marked this pull request as ready for review July 24, 2024 14:28
@taefi taefi requested review from Lodin and cromoteca July 24, 2024 14:28
@cromoteca cromoteca self-requested a review July 26, 2024 08:19
@taefi taefi requested a review from cromoteca July 26, 2024 12:28
cromoteca
cromoteca previously approved these changes Jul 26, 2024
Copy link

sonarcloud bot commented Jul 26, 2024

packages/ts/react-signals/src/EventChannel.ts Outdated Show resolved Hide resolved
packages/ts/react-signals/src/EventChannel.ts Outdated Show resolved Hide resolved
@taefi taefi merged commit 8e9a938 into main Jul 26, 2024
15 checks passed
@taefi taefi deleted the taefi/add-number-signal-basics branch July 26, 2024 13:35
@vaadin-bot
Copy link
Collaborator

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

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.

[Full-stack Signals] Add basic support for NumberSignals
5 participants