Skip to content

Conversation

kylebarron
Copy link
Member

@kylebarron kylebarron commented Oct 14, 2025

In ipywidgets, a "model" is the core of reactivity. In particular, a Lonboard Map is reactive, but every underlying layer is also reactive, so that when a user changes any property on a layer, it automatically gets updated on the map.

By extension, our Extension classes are also themselves models. These are separate Python classes that get serialized as their own reactive models on the JS side.

Soon we'll have more types of widget models that we want to be reactive, including views and basemap styles (#908).

Right now, model initialization is slightly hard-coded to handle layer initialization. This PR refactors the model initialization to be fully generic.

@kylebarron kylebarron marked this pull request as draft October 14, 2025 15:37
@kylebarron kylebarron marked this pull request as ready for review October 14, 2025 16:25
@kylebarron kylebarron requested review from Copilot and vgeorge October 14, 2025 16:25
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors model initialization logic to be fully generic instead of being hardcoded for layer initialization, preparing for future support of additional reactive widget models like views and basemap styles.

  • Moved generic model loading logic from util.ts to a new dedicated model/initialize.ts file
  • Created a generic initializeChildModels function that can handle any type of child model with proper lifecycle management
  • Updated layer initialization to use the new generic infrastructure while maintaining existing functionality

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/util.ts Removed layer-specific loadChildModels function to consolidate model loading logic
src/model/initialize.ts Added new generic model initialization utilities with proper lifecycle management
src/model/index.ts Exported the new initializeChildModels function for external use
src/model/base-layer.ts Updated to use generic model initialization and changed extensions from array to Record
src/index.tsx Refactored to use the new generic model initialization infrastructure

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@kylebarron
Copy link
Member Author

Open to comments still, but this is a pretty straightforward refactor I think, so I'll merge so that I can use it in #935

@kylebarron kylebarron merged commit 84c8add into main Oct 15, 2025
6 checks passed
@kylebarron kylebarron deleted the kyle/refactor-model-initialization branch October 15, 2025 02:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant