Class: CustomElementsManifestParser::Nodes::MixinDeclaration
- Inherits:
-
BaseStruct
- Object
- Dry::Struct
- BaseStruct
- CustomElementsManifestParser::Nodes::MixinDeclaration
- Includes:
- Mixins::HasParentModule
- Defined in:
- lib/custom_elements_manifest_parser/nodes/mixin_declaration.rb
Overview
A description of a class mixin.
Mixins are functions which generate a new subclass of a given superclass. This interfaces describes the class and custom element features that are added by the mixin. As such, it extends the CustomElement interface and ClassLike interface.
Since mixins are functions, it also extends the FunctionLike interface. This means a mixin is callable, and has parameters and a return type.
The return type is often hard or impossible to accurately describe in type
systems like TypeScript. It requires generics and an extends
operator
that TypeScript lacks. Therefore it's recommended that the return type is
left empty. The most common form of a mixin function takes a single
argument, so consumers of this interface should assume that the return type
is the single argument subclassed by this declaration.
A mixin should not have a superclass. If a mixins composes other mixins,
they should be listed in the mixins
field.
See https://justinfagnani.com/2015/12/21/real-mixins-with-javascript-classes/ for more information on the classmixin pattern in JavaScript.
This JavaScript mixin declaration:
const MyMixin = (base) => class extends base {
foo() { ... }
}
Is described by this JSON:
{
"kind": "mixin",
"name": "MyMixin",
"parameters": [
{
"name": "base",
}
],
"members": [
{
"kind": "method",
"name": "foo",
}
]
}
Instance Attribute Summary collapse
Class Method Summary collapse
Instance Method Summary collapse
Methods included from Mixins::HasParentModule
Instance Attribute Details
#kind ⇒ "mixin"
78 |
# File 'lib/custom_elements_manifest_parser/nodes/mixin_declaration.rb', line 78 attribute :kind, Types.Value("mixin") |
Class Method Details
.kind ⇒ "mixin"
81 |
# File 'lib/custom_elements_manifest_parser/nodes/mixin_declaration.rb', line 81 def self.kind; 'mixin'; end |
Instance Method Details
#visit(parser:) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/custom_elements_manifest_parser/nodes/mixin_declaration.rb', line 83 def visit(parser:) hash = {} hash = hash.merge( # Structs::FunctionLikeStruct.build_hash(parser: parser, struct: self), Structs::CustomElementLikeStruct.build_hash(parser: parser, struct: self), Structs::DeclarableNodeStruct.build_hash(parser: parser, struct: self), ) new(hash) end |