Skip to content

Enhance handleProperty function to dynamically handle additional properties #2098

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 14 commits into from
Aug 3, 2025

Conversation

Bashamega
Copy link
Contributor

related #2053

Copy link
Contributor

github-actions bot commented Aug 2, 2025

Thanks for the PR!

This section of the codebase is owned by @saschanaz - if they write a comment saying "LGTM" then it will be merged.

props.forEach((prop) => {
const value = child.properties[prop];
if (value !== undefined) {
result[prop] = value as any;
Copy link
Contributor

Choose a reason for hiding this comment

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

Would be nice to have some type check, any should not be used.

Perhaps could use some helper:

import { parse, type Node, type Value } from "kdljs";

function optionalMember<const T>(prop: string, type: T, value?: Value) {
  if (value === undefined) {
    return {};
  }
  if (typeof value !== type) {
    throw new Error(`Expected type ${value} for ${prop}`);
  }
  return { [prop]: value as T extends "string" ? string : T extends "number" ? number : T extends "boolean" ? boolean : never };
}

const result = {
  name: child.values[0] as string,
  ...optionalMember("exposed", "string", child.properties?.exposed),
  ...optionalMember("optional", "boolean", child.properties?.optional),
  ...optionalMember("overrideType", "string", child.properties?.overrideType),
};

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have updated it for property and mixins

property ontouchcancel optional=#true
property ontouchend optional=#true
property ontouchmove optional=#true
property ontouchstart optional=#true
Copy link
Contributor

Choose a reason for hiding this comment

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

Some context comment would be nice for touch events, which would be nicer as touch-events.kdl:

Touch event handlers are intentionally hidden in non-mobile web browsers.
See https://w3c.github.io/touch-events/#dfn-expose-legacy-touch-event-apis.

property ontouchend optional=#true
property ontouchmove optional=#true
property ontouchstart optional=#true
property onerror overrideType=OnErrorEventHandler
Copy link
Contributor

Choose a reason for hiding this comment

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

This can go events.kdl, as this should ultimately also be autogenerated rather than overridden.

@Bashamega Bashamega requested a review from saschanaz August 3, 2025 04:22
Comment on lines 76 to 81
// Touch event handlers are intentionally hidden in non-mobile web browsers.
// See w3c.github.io/touch-events#dfn-expose-legacy-touch-event-apis.
property ontouchcancel optional=#true
property ontouchend optional=#true
property ontouchmove optional=#true
property ontouchstart optional=#true
Copy link
Contributor

@saschanaz saschanaz Aug 3, 2025

Choose a reason for hiding this comment

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

These should go to touch-events.kdl. With that LGTM.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have moved them to a separate file

@Bashamega
Copy link
Contributor Author

Is this LGTM? @saschanaz

Copy link
Contributor

github-actions bot commented Aug 3, 2025

property ontouchmove optional=#true
property ontouchstart optional=#true
property onerror overrideType=OnErrorEventHandler
}
Copy link
Contributor

Choose a reason for hiding this comment

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

missing final newline and 2-space indent

property ontouchend optional=#true
property ontouchmove optional=#true
property ontouchstart optional=#true
property onerror overrideType=OnErrorEventHandler
Copy link
Contributor

Choose a reason for hiding this comment

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

And onerror should go back to events.kdl

@Bashamega
Copy link
Contributor Author

I have moved it, and formatted all KDL files @saschanaz

Comment on lines 5 to 6
param x type=long
param y type=long
Copy link
Contributor

@saschanaz saschanaz Aug 3, 2025

Choose a reason for hiding this comment

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

Needs more indentation

Copy link
Contributor

Choose a reason for hiding this comment

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

Wait, why are two PRs merged here? 🤔

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 should be removed. Which I did

@Bashamega
Copy link
Contributor Author

I have fixed it @saschanaz
My Git broke everything, and merged the PRs.

@saschanaz
Copy link
Contributor

LGTM

Copy link
Contributor

github-actions bot commented Aug 3, 2025

There was an issue merging, maybe try again saschanaz. Details

@saschanaz
Copy link
Contributor

LGTM

@github-actions github-actions bot merged commit 22f04bb into microsoft:main Aug 3, 2025
5 checks passed
Copy link
Contributor

github-actions bot commented Aug 3, 2025

Merging because @saschanaz is a code-owner of all the changes - thanks!

@Bashamega Bashamega deleted the optional-properties branch August 4, 2025 05:47
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.

3 participants