tapable

package
v0.0.0-...-c1bf0db Latest Latest
Warning

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

Go to latest
Published: May 22, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ActionHook

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

func (*ActionHook) Tap

Tap invoked by client to enable registration of the hook

type Activity

type Activity[F any] interface {
	Tap(name string, fn F) (F, error)
}

Activity represents an entity that performs an action that is tapable. The type F should be a function signature, defined by the tapable, so F is not really any, but it can't be enforced to be a func, so do not try to instantiate with a type that is not a func. To enable a client to augment the core action, Tap returns a func of type F which represents the core behaviour. If required, the client should store this and then invoke it as appropriate when it is called back.

type ActivityL

type ActivityL[F any] interface {
	Tap(name string, fn F) (F, error)
}

ActivityL represents an entity that performs an action that is tapable. The type F should be a function signature, defined by the tapable, so F is not really any, but it can't be enforced to be a func, so do not try to instantiate with a type that is not a func. To enable a client to augment the core action, Tap returns a func of type F which represents the core behaviour. If required, the client should store this and then invoke it as appropriate when it is called back.

type AlreadyTappedError

type AlreadyTappedError[R constraints.Integer] struct {
	// contains filtered or unexported fields
}

func (AlreadyTappedError[R]) Error

func (e AlreadyTappedError[R]) Error() string

type Client

type Client struct {
}

func (*Client) WithComponent

func (c *Client) WithComponent(from *Component)

type Component

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

Component contains tapable behaviour

func (*Component) DoWork

func (c *Component) DoWork()

type Container

type Container[R constraints.Integer] struct {
	// contains filtered or unexported fields
}

Container manages a collection of hooks defined for different roles. Since the hook is role specific, there is no way

func NewContainer

func NewContainer[R constraints.Integer]() *Container[R]

NewContainer creates a new instance of a hook container

func (*Container[R]) Query

func (c *Container[R]) Query(name string, role R) error

Query prevents client from trying to register multiple hooks for the same role.

type FuncSimpleWithWidgetAndError

type FuncSimpleWithWidgetAndError func(name string, amount int) (*Widget, error)

FuncSimpleWithWidgetAndError is the action func; invoke this function that can be hooked/tapable. In fact, this function can either enable core functionality to be overridden, decorated with auxiliary behaviour or simply as a life-cycle event; ie we have come to a significant point in the component's workflow and the some external entity's function needs to be invoked.

type HookName

type HookName = string

type HooksCollection

type HooksCollection[R constraints.Integer] map[R]HookName

type NotificationHook

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

func (*NotificationHook) On

Tap invoked by client to enable registration of the hook

type NotifyL

type NotifyL[F any, E constraints.Integer] interface {
	On(name string, event E, handler F) error
}

NotifyL used for life cycle events. There can be multiple subscribers to life cycle events

type Receiver

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

Receiver contains tapable behaviour received as a notification

func (*Receiver) When

func (r *Receiver) When(from *Component)

type Role

type Role[F any, R constraints.Integer] interface {
	Tap(name string, role R, fn F) (F, error)
}

Role is similar to Activity, but it allows the tapable entity to request that the client specify which specific behaviour needs to be tapped. This is useful when the entity has multiple behaviours that clients may wish to tap. To enable a client to augment the core action, Tap returns a func of type F which represents the core behaviour. If required, the client should store this and then invoke it as appropriate when it is called back.

type RoleL

type RoleL[F any, E constraints.Integer] interface {
	Tap(name string, role E, fn F) error
}

RoleL is similar to Activity, but it allows the tapable entity to request that the client specify which specific behaviour needs to be tapped. This is useful when the entity has multiple behaviours that clients may wish to tap.

type TapContainer

type TapContainer[R constraints.Integer] interface {
	Tap(name string, role R) error
}

type Widget

type Widget struct {
	Name   string
	Amount int
}

Widget is some domain abstraction

type WithDefault

type WithDefault[F any, R constraints.Integer] struct {
	Name      HookName
	Role      R
	Action    F
	Default   F
	Container *Container[R]
}

WithDefault is a helper that binds together a Hook and its associated default action. The default is the pure, non-tapable underlying function.

func (*WithDefault[F, R]) Tap

func (d *WithDefault[F, R]) Tap(name string, role R, fn F) (F, error)

Tap taps into the hook and captures the default action.

Jump to

Keyboard shortcuts

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