Skip to content

refactor: migrate models to dart_mappable#53

Closed
leoafarias wants to merge 3 commits intomainfrom
leoafarias/dart-mappable-plan
Closed

refactor: migrate models to dart_mappable#53
leoafarias wants to merge 3 commits intomainfrom
leoafarias/dart-mappable-plan

Conversation

@leoafarias
Copy link
Collaborator

Migrate core model classes to use dart_mappable for boilerplate reduction and consistency. Replace manual ==, hashCode, and copyWith implementations with generated versions. Add BlockDiscriminatorHook for legacy 'column' type compatibility and UnmappedPropertiesHook for dynamic args. Introduce consistent parse() methods that validate via Ack schemas. Remove dead extensions and add reserved-key validation to SlideOptions.

All tests passing (701 core, 651 superdeck, 428 genui).

…yWith, and decode

Replace manual ==, hashCode, and copyWith implementations across all core
models with dart_mappable code generation. Add consistent parse() methods
that validate via Ack schemas before construction. Introduce
BlockDiscriminatorHook for legacy 'column' type compatibility and
UnmappedPropertiesHook for dynamic args in WidgetBlock/SlideOptions.
…lideOptions

Remove unused BlockX and StringContentX extensions. Add construction-time
validation to SlideOptions that rejects reserved keys in args, matching
the existing WidgetBlock behavior.
Copilot AI review requested due to automatic review settings March 11, 2026 01:00
@docs-page
Copy link

docs-page bot commented Mar 11, 2026

To view this pull requests documentation preview, visit the following URL:

docs.page/btwld/superdeck~53

Documentation is deployed and generated using docs.page.

Prevents runaway jobs from consuming GitHub Actions minutes. Based on
observed run durations: test 15m, integration/web-smoke/firebase 20m,
docs 5m.
Copy link

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

Migrates SuperDeck core model classes to dart_mappable to reduce manual boilerplate (equality/hashCode/copyWith), while tightening/standardizing input parsing via Ack schema validation (parse()), and adding reserved-key protections for dynamic argument maps.

Changes:

  • Refactor core models (Deck, Slide, blocks, assets, deck configuration) to use dart_mappable generated mappers and generated copyWith/==/hashCode.
  • Introduce/standardize parse() entrypoints that validate with Ack schemas and add hooks/utilities for legacy discriminator compatibility and unmapped properties.
  • Update tests and call sites to account for non-const constructors and new validation/immutability behaviors.

Reviewed changes

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

Show a summary per file
File Description
packages/superdeck/test/slide_template_test.dart Update tests to remove const usage for Slide.
packages/superdeck/test/markdown/markdown_builders_test.dart Update markdown builder test harness to use non-const Slide.
packages/superdeck/test/markdown/image_element_rendering_test.dart Update image rendering tests to use non-const Slide.
packages/superdeck/test/markdown/builders/text_element_builder_widget_test.dart Update text builder widget tests to use non-const Slide.
packages/superdeck/test/deck/template_resolver_test.dart Update tests to remove const usage for SlideOptions.
packages/superdeck/test/deck/slide_configuration_builder_test.dart Update slide configuration builder tests to use non-const slides and compact list literals.
packages/superdeck/lib/src/deck/slide_configuration.dart Default slide options now constructed dynamically when absent.
packages/superdeck/lib/src/deck/bundled_deck_service.dart Switch bundled deck loading to Deck.parse(...) validation.
packages/genui/test/presentation/thumbnail_preview_service_test.dart Update thumbnail preview tests to use non-const slides.
packages/core/test/src/models/slide_model_test.dart Update Slide/SlideOptions tests for non-const ctors; add immutability + reserved-key tests; switch to parse() where appropriate.
packages/core/test/src/models/deck_model_test.dart Update Deck tests for unmodifiable slides and Deck.parse(...) validation expectations.
packages/core/test/src/models/block_model_test.dart Adjust error expectations; add immutability + reserved-key tests; remove extension-related tests.
packages/core/test/src/models/asset_model_test.dart Add parse() tests and immutability/schema tests for asset reference models.
packages/core/test/src/deck_service_test.dart Update DeckService tests to use non-const Slide.
packages/core/pubspec.yaml Add dart_mappable + builder deps (build_runner, dart_mappable_builder, ack_generator).
packages/core/lib/src/models/slide_model.mapper.dart New generated dart_mappable mapper for Slide/SlideOptions.
packages/core/lib/src/models/slide_model.g.dart Minor generator output adjustment (comment cleanup).
packages/core/lib/src/models/slide_model.dart Refactor Slide/SlideOptions to dart_mappable, add unmodifiable collections, reserved-key validation, and schema-validating parse().
packages/core/lib/src/models/mappers.dart Add BlockDiscriminatorHook for legacy column discriminator normalization.
packages/core/lib/src/models/deck_model.mapper.dart New generated dart_mappable mapper for Deck.
packages/core/lib/src/models/deck_model.dart Refactor Deck to dart_mappable, make slides unmodifiable, and route validation through parse().
packages/core/lib/src/models/block_model.mapper.dart New generated dart_mappable mappers for blocks and enums.
packages/core/lib/src/models/block_model.dart Refactor blocks/enums to dart_mappable, add parse() validation, add reserved-key protection for widget args, remove old extensions.
packages/core/lib/src/models/asset_model.mapper.dart New generated dart_mappable mappers for asset models.
packages/core/lib/src/models/asset_model.dart Refactor asset models to dart_mappable, add parse() and unmodifiable collections.
packages/core/lib/src/deck_service.dart Switch file-based deck loading to Deck.parse(...) validation.
packages/core/lib/src/deck_configuration.mapper.dart New generated dart_mappable mapper for DeckConfiguration.
packages/core/lib/src/deck_configuration.g.dart Minor generator output adjustment (comment cleanup).
packages/core/lib/src/deck_configuration.dart Refactor DeckConfiguration to dart_mappable while keeping existing parsing/validation utilities.
packages/core/build.yaml Configure dart_mappable_builder generation options for the core package.

final data = jsonDecode(content) as Map<String, dynamic>;
return Deck.fromMap(data);
return Deck.parse(data);
} on Exception catch (e) {
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

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

jsonDecode(content) as Map<String, dynamic> can throw a TypeError if the JSON isn’t an object, and TypeError won’t be caught by the current on Exception handler. To ensure loadDeck() reliably returns an error deck (instead of crashing), either broaden the catch to on Object or validate the decoded value’s type before casting/parse.

Suggested change
} on Exception catch (e) {
} on Object catch (e) {

Copilot uses AI. Check for mistakes.
_widgets = widgets;

SlideOptions get options => _slide.options ?? const SlideOptions();
SlideOptions get options => _slide.options ?? SlideOptions();
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

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

options creates a new SlideOptions() instance every time it’s accessed when the slide has no options. Since this getter can be hit frequently during widget builds, consider caching a single empty instance (e.g., a static final empty options or a lazily initialized field) to avoid repeated allocations.

Copilot uses AI. Check for mistakes.
@github-actions
Copy link

Visit the preview URL for this PR (updated for commit 4861984):

https://superdeck-dev--pr53-leoafarias-dart-mapp-p1qltdqq.web.app

(expires Fri, 10 Apr 2026 01:09:05 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: bd68fc230762285849207e7e120aaf87cd4ca2f9

@leoafarias leoafarias closed this Mar 11, 2026
@leoafarias leoafarias deleted the leoafarias/dart-mappable-plan branch March 11, 2026 14:13
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