Skip to content

Conversation

@gdotdesign
Copy link
Member

This PR adds the feature / quality of life improvement of allowing variants to expand into their parent types in certain cases:

type User {
  age : Maybe(Number),
  name : String,
}

component Expansion {
  // Default properties
  property value : Maybe(String) = Just("Hello")
  
  // Initial state values
  state name : Maybe(String) = Nothing
  
  // Default argument values
  fun setName (name : Maybe(String) = Nothing)  {
    // Next calls
    next { name: Just("Joe") }
    next { name: name }
  }
  
  fun render {
    value or "FALLBACK"
  }
}

component Main {
  fun render {
	// Records and record updates
	{ age: Just(32), name: "Joe" }
	{ { age: Just(32), name: "Joe" } | age: Just(40) }
	
    // Html attribute values
    <Expansion value={Nothing}/>
  }
}

The main use case was to make Html less verbose, so this:

<Ui.View direction={Ui.Direction.Horizontal} flex={Ui.Flex.Fill}>
  <Ui.View
    flex={Ui.Flex.Custom("0 0 500px")}
    direction={Ui.Direction.Vertical}
    padding={4}
    gap={4}
  >
  ...
  </Ui.View>
</Ui.View>

can be written as:

<Ui.View direction={Horizontal} flex={Fill}>
  <Ui.View
    flex={Custom("0 0 500px")}
    direction={Vertical}
    padding={4}
    gap={4}
  >
  ...
  </Ui.View>
</Ui.View>

It's also useful in components where the states use ADTs and need to be written a lot.

@gdotdesign gdotdesign merged commit 9c7c58c into master Nov 24, 2025
3 checks passed
@gdotdesign gdotdesign deleted the variants-in-types branch November 24, 2025 15:48
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