Skip to content

refactor(signal-forms): rework metadata API #62713

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

Merged
merged 13 commits into from
Jul 22, 2025

Conversation

mmalerba
Copy link
Contributor

@mmalerba mmalerba commented Jul 18, 2025

Note: each commit is an independently reviewable step if you prefer to review commit-by-commit.

I still have a few open questions:

  1. Do we prefer the name metadata or property for this concept?

Decided on slight preference for property because it better conveys that these things can be used to drive actual schema logic

  1. What should be the names of the functions used to bind logic to MetadataKey and AggregateMetadataKey.
    Some ideas for MetadataKey include:

    • metadata (or property)
    • setMetadata (or setProperty)

    Some ideas for AggregateMetadataKey include:

    • addMetadata (or addProperty)
    • addToMetadata (or addToProperty)
    • aggregateMetadata (or aggregateProperty)
    • accumulateMetadata (or accumulateProperty)
    • contributeMetadata (or contributeToProperty)

Decided to go with property and aggregateProperty for now, seems clear and matches the class names

  1. It can be tedious to type the generic MetadataKey.create<...>() for a key that you use internally to the schema. I'm worried people will just yolo and MetadataKey.create<any>(), should we add back an equivalent to the 2-parameter variant of define?

Decided yes, will introduce 2-parameter variant of property (const PROP = property(p.whatever, () => ...))

@mmalerba mmalerba requested review from leonsenft, kirjs and alxhub July 18, 2025 21:57
@mmalerba mmalerba added area: forms target: feature This PR is targeted for a feature branch (outside of main and semver branches) labels Jul 18, 2025
@ngbot ngbot bot added this to the Backlog milestone Jul 18, 2025
Co-authored-by: michael-small <33669563+michael-small@users.noreply.github.com>
export class Property<TValue> {
private brand!: TValue;

protected constructor() {}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is done for consistency with AggregateProperty which is constructed via static factory methods. Can you elaborate on why? I'm not necessarily against it, just curious why its important to you.

@mmalerba
Copy link
Contributor Author

/gemini review

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This is a great refactoring that significantly improves the clarity and consistency of the API by renaming "metadata" to "property". The introduction of Property and AggregateProperty classes, along with the new property and aggregateProperty functions, makes the system more explicit and easier to understand. The removal of the old metadata and data APIs cleans up the codebase nicely.

I've found a couple of minor areas for improvement:

  • The JSDoc for the new property function could be enhanced to better document its overloads.
  • There appears to be some unused code in the new FieldPropertyState class that can be removed.

Overall, this is a high-quality change that moves the signal-based forms in the right direction.

@mmalerba mmalerba merged commit e96d9e3 into angular:prototype/signal-forms Jul 22, 2025
11 of 18 checks passed
leonsenft pushed a commit to leonsenft/angular that referenced this pull request Jul 23, 2025
* rename metadata key types

* fix metadata reduce to not confuse item and acc types

* remove defineComputed, defineResource

* rename define and meatdata logic binding fns

* move setMetadata next to addToMetadata

* address comments

Co-authored-by: michael-small <33669563+michael-small@users.noreply.github.com>

* pattern cleanup

* rename metadata concept to property

* consolidate field property state

* rename metadata.ts to property.ts

* add 2-param variant of property rule

* rename getDefault to getInitial for alignment with standard reduce

* address ai review

---------

Co-authored-by: michael-small <33669563+michael-small@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: forms target: feature This PR is targeted for a feature branch (outside of main and semver branches)
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy