-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomponent.go
More file actions
57 lines (51 loc) · 1.71 KB
/
component.go
File metadata and controls
57 lines (51 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Package uiok defines abstractions for building composable, renderable, and
// validatable components,
// suitable for HATEOAS resources or UI construction.
package uiok
import "context"
// Component is the primary interface for any renderable unit.
//
// Partial returns a byte slice representing the component's partial (fragment)
// output.
// Render returns a byte slice representing the component's full output.
// Change applies state changes, typically with the provided context.
type Component interface {
Partial() ([]byte, error)
Render() ([]byte, error)
Change(context.Context) error
}
// Composite represents a component that can aggregate multiple child
// components and validators.
//
// It extends Component and Validator, and provides methods to add/remove
// components, retrieve the contained components/validators, and manage their
// relationships.
type Composite interface {
Component
Validator
Add(...Component) error
Remove(...Component) error
Components() []Component
Validators() []Validator
}
// HttpComponent is a component that can bind data from HTTP form submissions.
//
// BindFromForm populates the component's fields from the provided form data.
type HttpComponent interface {
Component
BindFromForm(map[string][]string) error
}
// HttpComposite combines Composite and HttpComponent functionality,
// allowing for composition and HTTP form binding in one construct.
type HttpComposite interface {
Composite
HttpComponent
}
// Validator represents an object capable of performing validations.
//
// Errors returns a slice of errors for current validation state.
// Validate performs validation and returns true if valid, false otherwise.
type Validator interface {
Errors() []error
Validate() bool
}