Modddels
HomeGithubPub.dev
v0.1
v0.1
  • Motivation
  • Setup
  • Generalities
    • Modddels Overview
    • Validations & Validation steps
    • Structure of a Modddel
    • Member parameters & Dependency parameters
    • Usage
      • Data equality & toString
      • Pattern matching
      • Reading the fields
      • Reading the failures
      • CopyWith
  • ValueObjects
    • ValueObjects Overview
    • Creating a ValueObject
  • Entities
    • Entities Overview
    • ContentValidation & ContentFailure
    • ValidationSteps in Entities
    • SimpleEntity
      • Creating a SimpleEntity
      • Special Cases
    • IterableEntity & Iterable2Entity
      • IterableEntity / Iterable2Entity kinds
      • The Type Template
      • Creating an IterableEntity / Iterable2Entity
      • InvalidMembers Description
      • Special Cases
      • Creating your own IterableEntity / Iterable2Entity kind
  • Advanced Notions
    • The NullFailure Annotation
    • Using multiple parameters annotations
    • Class Hierarchy of ValueObjects
    • Class Hierarchy of Entities
    • Models that are always valid / invalid
  • Union of Modddels
    • Union of Modddels Overview
    • Basic Usage
    • Case-modddels pattern matching
    • Default Factory Constructor
    • Shared Properties
    • The Validate Methods
    • CopyWith
  • Unit-Testing Of Modddels
    • Unit-Testing Overview
    • Available Tests
    • Customizing Tests
  • Additional Information
    • Using type aliases
    • Re-running the generator
    • All Available Modddels
    • VsCode Snippets
Powered by GitBook
On this page
  1. Union of Modddels

CopyWith

In addition to the copyWith method of each case-modddel, the super-sealed class has a copyWith method too. However, this method only includes shared properties that have the same type across all case-modddels.

For example : Let's say we have a Weather MultiValueObject union :

// @Modddel (... , sharedProps: [ SharedProp('int', 'temperature') ])
// class ... {

factory Weather.sunny({
  required int temperature,
}) // { ... }

factory Weather.rainy({
  required int temperature,
  required double rainIntensity,
}) // { ... }

In this example, temperature is a shared property of type int, and it has the same type int in both case-modddels. So it can be used in the super-sealed class's copyWith method :

final otherWeather = weather.copyWith(temperature: 12);

The original plan was that the super-sealed class's copyWith method would include all shared properties, even when their types in the case-modddels is different. However, this could not be done due to a limitation in the Dart language related to inheritence.

PreviousThe Validate MethodsNextUnit-Testing Overview

Last updated 2 years ago