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

Draft
wants to merge 29 commits into
base: main
Choose a base branch
from

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.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
  • 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

All modified and coverable lines are covered by tests ✅

Project coverage is 92.53%. Comparing base (fca044b) to head (ce42feb).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2502      +/-   ##
==========================================
- Coverage   92.56%   92.53%   -0.03%     
==========================================
  Files          69       68       -1     
  Lines        2245     2238       -7     
  Branches      590      590              
==========================================
- Hits         2078     2071       -7     
  Misses        120      120              
  Partials       47       47              
Flag Coverage Δ
unittests 92.53% <ø> (-0.03%) ⬇️

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 force-pushed the taefi/add-number-signal-basics branch from c8501a1 to df1ee1d Compare June 13, 2024 13:46
Copy link

sonarcloud bot commented Jun 13, 2024

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

Copy link

sonarcloud bot commented Jul 18, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

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