Skip to content

Instantly share code, notes, and snippets.

@marklundin
Created April 24, 2024 15:37
Show Gist options
  • Save marklundin/99ee9174bdb8fc37723df15e7d9ab826 to your computer and use it in GitHub Desktop.
Save marklundin/99ee9174bdb8fc37723df15e7d9ab826 to your computer and use it in GitHub Desktop.
export class MyClass {
/**
* @attribute
* Adding an attribute tag tag in a block comment flags the property as an attribute to the editor.
*/
speed = 10
/**
* @attribute
* Attributes can't be expressions. We don't evaluate code.
* A warning will be generated and the attribute will be ignored.
*/
speedExpression = 10 + 1
/**
* This does not have an attribute tag and will be ignored.
*/
notAnAttribute = false
/**
* @attribute
* Attributes types can also be defined using the `type` tag.
*
* @type {string}
*/
uninitializedString
/**
* @attribute
* If an attribute is not initialized and does not include a `type` tag, it is invalid.
* A warning will be generated.
*/
uninitializedInvalidType
/**
* @attribute
* If both are provided, the inferred type is ignored and the `type` tag is used.
*
* @type {number}
*/
speedNotString = 'This inferred string type is ignored'
/**
* @attribute
* Attributes can be arrays of a type.
*
* @type {string[]}
*/
uninitializedArrayOfStrings
/**
* @attribute
* But this can also be inferred from it's initialization
*/
initializedArrayOfStrings = ['This is an array of strings']
/**
* @attribute
* There are additional tags an attribute can have to provide more context to the editor.
*
* Range, step, precision specifies numerical constraints
* @title The title tag is used as short label
* @range [0.1, 10]
* @precision 0.01
* @step 0.005
* @placeholder This is some placeholder text, used to populate input fields
*/
velocity = 2
/**
* @attribute
* Attributes can also be complex types. The type must be marked with the `@serializable` tag.
* It's properties tagged with `@attribute` will be exposed in the editor. This similar to the older 'json' use case.
*/
enemy = new EnemyType()
/**
* @attribute
* Uninitialized Complex Types also respect the `type` tag.
*
* @type {EnemyType}
*/
uninitializedEnemy
/**
* @attribute
* and can also be arrays of complex types. Again the @serializable tag is required.
*
* @type {EnemyType[]}
*/
uninitializedEnemies
/**
* @attribute
* Same for initialized arrays of complex types.
*/
enemies = [new EnemyType()]
/**
* @attribute
* If an attribute type exists but isn't marked with the `@serializable` tag, it will be ignored.
* A warning will be generated.
*/
initializedInvalidType = new InvalidType()
/**
* @attribute
* Of course, if a type doesn't exist, It will not be added.
*
* @type {ThisDoesntExist}
*/
invalidInferredType
/**
* @attribute
* Same goes for attributes initialized with non existent types.
*/
invalidInitializedType = new ThisDoesntExist();
/**
* @attribute
* This is an enum attribute. The Lights definition has `@enum` tag which
* creates a dropdown list in the editor.
*
* @type {Lights}
*/
lights = 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment