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

Add extensibility to various classes #11859

Merged
merged 6 commits into from
Feb 29, 2024
Merged

Add extensibility to various classes #11859

merged 6 commits into from
Feb 29, 2024

Conversation

jjspace
Copy link
Contributor

@jjspace jjspace commented Feb 26, 2024

Description

Add new functions to register various updaters and visualizers to support custom entities and data constructs.

Issue number and link

No issue

Testing plan

  • Run the specs and make sure they all still pass
  • Try the sandcastles related to entities, primitives and CZML and make sure they all still behave as intended.

Author checklist

  • I have submitted a Contributor License Agreement
  • I have added my name to CONTRIBUTORS.md
  • I have updated CHANGES.md with a short summary of my change
  • I have added or updated unit tests to ensure consistent code coverage
  • I have update the inline documentation, and included code examples where relevant
  • I have performed a self-review of my code

@jjspace jjspace requested a review from ggetz February 26, 2024 18:09
@jjspace
Copy link
Contributor Author

jjspace commented Feb 26, 2024

@ggetz I wasn't totally sure how to test these as they modify the global objects and I think that would impact all other specs which is not desirable. Open to ideas

Copy link

github-actions bot commented Feb 26, 2024

Thank you for the pull request, @jjspace! Welcome to the Cesium community!

In order for us to review your PR, please complete the following steps:

Review Pull Request Guidelines to make sure your PR gets accepted quickly.

@ggetz
Copy link
Contributor

ggetz commented Feb 27, 2024

@jjspace I just added you to the Cesium CLA list. You're good to go!

@jjspace
Copy link
Contributor Author

jjspace commented Feb 28, 2024

@ggetz This has been updated with unregister functions and specs for everything except the Entity class (see comment below)
This should be good to review now

Comment on lines +507 to +509
Object.defineProperties(Entity.prototype, {
[propertyName]: createPropertyTypeDescriptor(propertyName, Type),
});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. I'm not entirely sure how to "undo" this change. The only way I can tell it would be possible is to make this property configurable: true which then lets me delete Entity.prototype.propertyName. But I'm not entirely sure we want to make the property fully configurable?
    • This may point to a deeper issue of needing a better way to create and manage entity type properties.
  2. I'm also not really sure how to even test and validate the correct properties are set up with the right getter/setter. They'd default to undefined so I couldn't find a nice way to check. Also the privateName and subscriptionName are not always defined so using Object.keys to check doesn't seem like a 100% complete solution.

Copy link
Contributor

Choose a reason for hiding this comment

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

Discussed offline: Given we'd have to jump through hoops here to make an "unsubscribe" function, we'll omit.

Depending on if we need additional Entity flexibility in the future, we could consider how the types are managed under the hood. But for the scope of this PR, its not needed.

Copy link
Contributor

@ggetz ggetz left a comment

Choose a reason for hiding this comment

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

Thanks @jjspace! A few comments, mostly related to documentation.

packages/engine/Source/Scene/Primitive.js Outdated Show resolved Hide resolved
Comment on lines +507 to +509
Object.defineProperties(Entity.prototype, {
[propertyName]: createPropertyTypeDescriptor(propertyName, Type),
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Discussed offline: Given we'd have to jump through hoops here to make an "unsubscribe" function, we'll omit.

Depending on if we need additional Entity flexibility in the future, we could consider how the types are managed under the hood. But for the scope of this PR, its not needed.

packages/engine/Source/DataSources/DataSourceDisplay.js Outdated Show resolved Hide resolved
* Add the specified type and construct the properties for it in the Entity class
* @private
* @param {string} propertyName
* @param {any} Type
Copy link
Contributor

Choose a reason for hiding this comment

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

Strictly speaking this would be

Suggested change
* @param {any} Type
* @param {object.constructor} Type

right?

Copy link
Contributor

Choose a reason for hiding this comment

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

I know this is marked as private, but typically we do add descriptions for each parameter. That applies here and throughout this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

More and more often I go down rabbit holes dug by JSDoc being old and not maintained.
object.constructor is not a type. After a quick google search I came across this issue jsdoc/jsdoc#1349 which, paired with other JSDoc knowledge, seems to indicate there's no way to really specify "any class" as a type. The best I think we can do is specify a type of {{ constructor: function }} to try and only accept objects with a constructor function?

packages/engine/Source/DataSources/GeometryUpdaterSet.js Outdated Show resolved Hide resolved
packages/engine/Source/Scene/Scene.js Show resolved Hide resolved
packages/engine/Source/Workers/createGeometry.js Outdated Show resolved Hide resolved
packages/engine/Source/Workers/createGeometry.js Outdated Show resolved Hide resolved
@jjspace
Copy link
Contributor Author

jjspace commented Feb 29, 2024

@ggetz thanks for the comments, I believe I've addressed them all

@ggetz
Copy link
Contributor

ggetz commented Feb 29, 2024

Thanks @jjspace! I updated CHANGES.md with a link to this PR, which is the usual practice when there is no original linked issue to reference.

Once CI passes, this should be good to go.

@jjspace
Copy link
Contributor Author

jjspace commented Feb 29, 2024

Thanks @ggetz I just forgot to link them. Looks like this is good now! 🙏

@ggetz ggetz merged commit 5539fdb into main Feb 29, 2024
9 checks passed
@ggetz ggetz deleted the package-extensibility branch February 29, 2024 19:24
@jjspace jjspace mentioned this pull request Mar 1, 2024
6 tasks
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.

2 participants