Create Types

Every variable in Visual Builder is assigned a type, something that defines the type and structure of the data stored in a variable. Two kinds of types can be assigned to variables: standard JavaScript built-in types and custom types that can be declared and instantiated as needed.

Standard built-in types can be used to specify data that are:
  • a specific primitive type (string, boolean, number, and so on)
  • a structured type such as an array or object, for which each field can either be a primitive or a structure
  • a dynamic type (any), or
  • a built-in type such as Array Data Provider, Service Data Provider, or Multi Service Data Provider.

    Service Data Provider (SDP) is typically used to store data retrieved from a REST endpoint and populate collection components such as tables and lists; Multi Service Data Provider is commonly used for list of values components when different fetch capabilities are required. Array Data Provider (ADP) is used when some operations need to be performed on the data.

    The Buffering Data Provider (BDP) type is a special built-in type. It wraps underlying data providers such as SDPs and ADPs to provide enhanced functionality such as buffering for CRUD operations, commit, revert, and so on.

When you use Quick Starts to develop your application's pages, Visual Builder creates whatever types are necessary. If you do want to create your own type, you have the option of creating custom types. Custom types can be based on an endpoint to make sure the shape of the variable's data matches what the endpoint expects in its payload. You can also create types to define custom objects, arrays, and enumerated lists. Advanced users can further define a type from code (such as a type class written in JavaScript or a typescript class) and associate this type to a special InstanceFactory variable. This way, they can simply plug their type into a variable without writing any extra JavaScript code.

Types from an endpoint or from code define custom type structures either by using the endpoint (response) data structure, or by using a type class (or a type declaration file when provided).

When creating types, remember that they are defined within a scope, just like variables. They can be created at the application, flow, and page level. They can also be defined at the dynamic layout level to be shared between dynamic layout templates, and at the fragment level.