stateful

package
v3.0.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 21, 2024 License: MIT Imports: 19 Imported by: 16

Documentation

Index

Constants

View Source
const (
	LocalsKeyNewAction   = "newAction"
	LocalsKeyQueryTags   = "queryTags"
	LocalsKeySetCookies  = "setCookies"
	LocalsKeyEncodeQuery = "encodeQuery"
)

Variables

View Source
var ErrInjectorNotFound = errors.New("injector not found")
View Source
var QueryTagMethodBare = &QueryTagMethod{
	Name: "bare",
	Encoder: `({ value, queries, tag }) => {
		if (value) {
			value.split('&').forEach((query) => {
				queries.push(query)
			})
		}
	}`,
	Decoder: func(qs url.Values, tag QueryTag, v any) error {
		if len(tag.Args) < 1 {
			return fmt.Errorf("bare query tag method requires at least one argument")
		}
		bareQuery := make(url.Values)
		prefix := tag.Args[0]
		for k, vs := range qs {
			if strings.HasPrefix(k, prefix) {
				for _, v := range vs {
					unescaped, err := url.QueryUnescape(v)
					if err != nil {
						return fmt.Errorf("failed to unescape %q: %w", v, err)
					}
					bareQuery.Add(k, unescaped)
				}
			}
		}
		reflectutils.Set(v, tag.path, bareQuery.Encode())
		return nil
	},
}

tag example: `query:";method=bare,f_"` arg0: the prefix of the query key

View Source
var QueryTagMethods = []*QueryTagMethod{
	QueryTagMethodBare,
}
View Source
var QueryTagMethodsMap = func() map[string]*QueryTagMethod {
	m := map[string]*QueryTagMethod{}
	for _, v := range QueryTagMethods {
		if _, ok := m[v.Name]; ok {
			panic(fmt.Sprintf("duplicate query tag method %q", v.Name))
		}
		m[v.Name] = v
	}
	return m
}()

Functions

func Actionable

func Actionable[T h.HTMLComponent](ctx context.Context, c T, children ...h.HTMLComponent) (r h.HTMLComponent)

func AppendReloadToResponse

func AppendReloadToResponse(r *web.EventResponse, c Identifiable)

func Clone

func Clone[T any](src T) (T, error)

func Copy

func Copy(dst, src any) error

func GetFuncName

func GetFuncName(f any) string

func IdentifiableCookieKey

func IdentifiableCookieKey(v Identifiable) string

func Install

func Install(b web.EventFuncHub, dc *DependencyCenter)

func IsQuerySubset

func IsQuerySubset(sup, sub url.Values) bool

IsQuerySubset checks if all key-value pairs in sub are contained within sup, considering comma-separated.

func IsRawQuerySubset

func IsRawQuerySubset(sup, sub string) bool

IsRawQuerySubset checks if all key-value pairs in the sub query string are contained within the sup query string.

func IsSyncQuery

func IsSyncQuery(ctx context.Context) bool

func MurmurHash3

func MurmurHash3(input string) string

func MustClone

func MustClone[T any](src T) T

func OnReload

func OnReload(c Identifiable) (r web.EventResponse, err error)

func ParseQuery

func ParseQuery(c h.HTMLComponent) h.HTMLComponent

func PostAction

func PostAction(ctx context.Context, c any, method any, request any, opts ...PostActionOption) *web.VueEventTagBuilder

func PrettyJSONString

func PrettyJSONString(v any) (r string)

func RegisterActionableCompoType

func RegisterActionableCompoType(vs ...h.HTMLComponent)

func ReloadAction

func ReloadAction[T Identifiable](ctx context.Context, source T, f func(target T), opts ...PostActionOption) *web.VueEventTagBuilder

func SkipPortalize

func SkipPortalize(c Identifiable) h.HTMLComponent

func SyncQuery

func SyncQuery(c h.HTMLComponent) h.HTMLComponent

func Unwrap

func Unwrap(c h.HTMLComponent) h.HTMLComponent

func WithPortalName

func WithPortalName(ctx context.Context, name string) context.Context

Types

type Action

type Action struct {
	CompoType string          `json:"compo_type"`
	Compo     json.RawMessage `json:"compo"`
	Injector  string          `json:"injector"`
	SyncQuery bool            `json:"sync_query"`
	Method    string          `json:"method"`
	Request   json.RawMessage `json:"request"`
}

type DependencyCenter

type DependencyCenter struct {
	// contains filtered or unexported fields
}

func NewDependencyCenter

func NewDependencyCenter() *DependencyCenter

func (*DependencyCenter) Apply

func (dc *DependencyCenter) Apply(ctx context.Context, target h.HTMLComponent) error

func (*DependencyCenter) Inject

func (dc *DependencyCenter) Inject(injectorName string, c h.HTMLComponent) (h.HTMLComponent, error)

func (*DependencyCenter) Injector

func (dc *DependencyCenter) Injector(name string) (*inject.Injector, error)

func (*DependencyCenter) MustApply

func (dc *DependencyCenter) MustApply(ctx context.Context, target h.HTMLComponent) h.HTMLComponent

func (*DependencyCenter) MustInject

func (dc *DependencyCenter) MustInject(injectorName string, c h.HTMLComponent) h.HTMLComponent

func (*DependencyCenter) MustProvide

func (dc *DependencyCenter) MustProvide(name string, fs ...any)

func (*DependencyCenter) Provide

func (dc *DependencyCenter) Provide(name string, fs ...any) error

func (*DependencyCenter) RegisterInjector

func (dc *DependencyCenter) RegisterInjector(name string, opts ...RegisterInjectorOption)

type Identifiable

type Identifiable interface {
	h.HTMLComponent
	CompoID() string
}

type InjectorName

type InjectorName string

just to make it easier to get the name of the currently applied injector

type PostActionOption

type PostActionOption func(*postActionOptions)

func WithAppendFix

func WithAppendFix(v string) PostActionOption

func WithUseProvidedCompo

func WithUseProvidedCompo() PostActionOption

type QueryTag

type QueryTag struct {
	Name      string `json:"name"`
	JsonName  string `json:"json_name"`
	Omitempty bool   `json:"omitempty"`

	Method string   `json:"method,omitempty"`
	Args   []string `json:"args,omitempty"`

	Cookie bool `json:"cookie,omitempty"`
	// contains filtered or unexported fields
}

type QueryTagMethod

type QueryTagMethod struct {
	Name    string                                         `json:"name"`
	Encoder string                                         `json:"encoder"` // js
	Decoder func(qs url.Values, tag QueryTag, v any) error `json:"-"`       // go
}

type QueryTags

type QueryTags []QueryTag

func ParseQueryTags

func ParseQueryTags(v any) (QueryTags, error)

func (QueryTags) CookieTags

func (tags QueryTags) CookieTags() QueryTags

func (QueryTags) Decode

func (tags QueryTags) Decode(rawQuery string, dest any) (rerr error)

type RegisterInjectorOption

type RegisterInjectorOption func(*registerInjectorOptions)

func WithParent

func WithParent(parent string) RegisterInjectorOption

type Unwrapable

type Unwrapable interface {
	Unwrap() h.HTMLComponent
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL