Copy of View

An entity that accepts a collection of properties and returns an element.

Definition

As opposed to a Function, the property order for views doesn't matter, it always produces the same type signature. The only valid return types for a view are the Primitives.

view SimpleView(age: number, name: string) -> {
  <div />
}

// is equivalent to

view AlternateView(name: string, age: number) -> {
  <div />
}

// and

type SpreadType {
  age: number;
  name: string;
}

view SpreadView(...props: SpreadType) -> {
  <div />
}

SimpleView.Props;     // $Type(age: number, name: string)
AlternateView.Props;  // $Type(age: number, name: string)
SpreadView.Props;     // SpreadType -> $Type(age: number, name: string)

SimpleView;
// $View<SimpleView.Props, SimpleView()>
//   -> $View<$Type(age: number, name: string), SimpleView()>

AlternateView;
// $View<AlternateView.Props, AlternateView()>
//   -> $View<$Type(age: number, name: string), AlternateView()>

SpreadView;
// $View<SpreadView.Props, SpreadView()>
//   -> $View<SpreadType, SpreadView()>
//   -> $View<$Type(age: number, name: string), SpreadView()>

Keys

In order to differentiate elements for more efficient re-rendering, keys can be provided (this might not actually be necessary based on how we build the dependency graphs).

Omit Parentheses

When your view does not accept properties, the parentheses can be omitted.

View Composition

Building your view's with composition in mind allows you to re-use them easily and combine them with other view's to create complex experiences for your users with ease.

Slots

Composition is achieved by using special <slot> tags to inject content placed within the containing view. This allows view's to be more easily re-used, such as a complex "button" that can have different textual content injected into it.

Named Slots

In order to inject multiple different pieces of content, slots can be named and matched to the keys provided on elements placed into the view.

Default Content

Slots can be provided with default content that is replaced if overridden by the containing view.

Alternate Composition

The above solution might not be so good because it ties you more closely to only being able to use the children in a very rigid way. This alternative pattern sticks closer to React's children.

Slots

The keyword children is available within any view to easily access the children placed into it.

Named Slots

In order to inject multiple different pieces of content, children can be selected based on their keys.

Extend or Implement Other Views

Override or extend the signature and functionality of another view.

Property Type Inheritance

Properties by the same name as the super view inherit the same types by default.

Simple Property Transformation

Easily transform properties before applying them to a base view.

Partially Apply Properties

Properties can be applied during view declaration. If no properties are passed to the extended view, the parentheses can be omitted.

Extend and Augment Signature

Override and the property signature of the extended view.

Extension as an Interface

Use extend another view for its signature.

Nest Super Content

Nest content from super view inside of more tags.

Full view declaration syntax

NOTE: consider an alternative to with such as the & character.

Create State explicitly (bypass dependency injection)

Ignore grabbing a state from the currect scope by partially or fully constructing one in the declaration of the view.

Partial Context Application

Last updated

Was this helpful?