context

package
v0.30.8 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2023 License: MIT Imports: 7 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var From miruken.Qualifier[fromScope]

From constrains resolution to a handler with scoped lifestyle. This is used to suppress resolving implied values available through a Context.

View Source
var PublishFromRoot miruken.BuilderFunc = func(handler miruken.Handler) miruken.Handler {
	if context, _, err := provides.Type[*Context](handler); err != nil {
		panic("root context could not be found")
	} else {
		return miruken.Publish.BuildUp(context.Root())
	}
}

Functions

This section is empty.

Types

type ChangedObserver

type ChangedObserver interface {
	ContextChanged(
		contextual Contextual,
		oldCtx *Context,
		newCtx *Context)
}

ChangedObserver reports a Context contextualObserverChanged.

type ChangedObserverFunc

type ChangedObserverFunc func(
	contextual Contextual,
	oldCtx *Context,
	newCtx *Context)

func (ChangedObserverFunc) ContextChanged

func (f ChangedObserverFunc) ContextChanged(
	contextual Contextual,
	oldCtx *Context,
	newCtx *Context,
)

type ChangingObserver

type ChangingObserver interface {
	ContextChanging(
		contextual Contextual,
		oldCtx *Context,
		newCtx **Context)
}

ChangingObserver reports a Context is contextualObserverChanging.

type ChangingObserverFunc

type ChangingObserverFunc func(
	contextual Contextual,
	oldCtx *Context,
	newCtx **Context)

func (ChangingObserverFunc) ContextChanging

func (f ChangingObserverFunc) ContextChanging(
	contextual Contextual,
	oldCtx *Context,
	newCtx **Context,
)

type ChildEndedObserver

type ChildEndedObserver interface {
	ChildContextEnded(childCtx *Context, reason any)
}

ChildEndedObserver reports child Context ended.

type ChildEndedObserverFunc

type ChildEndedObserverFunc func(ctx *Context, reason any)

func (ChildEndedObserverFunc) ChildContextEnded

func (f ChildEndedObserverFunc) ChildContextEnded(
	ctx *Context,
	reason any,
)

type ChildEndingObserver

type ChildEndingObserver interface {
	ChildContextEnding(childCtx *Context, reason any)
}

ChildEndingObserver reports child Context is ending.

type ChildEndingObserverFunc

type ChildEndingObserverFunc func(ctx *Context, reason any)

func (ChildEndingObserverFunc) ChildContextEnding

func (f ChildEndingObserverFunc) ChildContextEnding(
	ctx *Context,
	reason any,
)

type Context

type Context struct {
	miruken.MutableHandlers
	// contains filtered or unexported fields
}

A Context represents the scope at a give point in time. Context has a beginning and an end and can handle callbacks As well As notify observers of lifecycle changes. In addition, it maintains parent-child relationships and thus can form a graph.

func New

func New(handlers ...any) *Context

func (*Context) Children

func (c *Context) Children() []miruken.Traversing

func (*Context) Dispose

func (c *Context) Dispose()

func (*Context) End

func (c *Context) End(reason any)

func (*Context) Handle

func (c *Context) Handle(
	callback any,
	greedy bool,
	composer miruken.Handler,
) miruken.HandleResult

func (*Context) HandleAxis

func (c *Context) HandleAxis(
	axis miruken.TraversingAxis,
	callback any,
	greedy bool,
	composer miruken.Handler,
) miruken.HandleResult

func (*Context) HasChildren

func (c *Context) HasChildren() bool

func (*Context) NewChild

func (c *Context) NewChild() *Context

func (*Context) Observe

func (c *Context) Observe(observer Observer) miruken.Disposable

func (*Context) Parent

func (c *Context) Parent() miruken.Traversing

func (*Context) Root

func (c *Context) Root() *Context

func (*Context) State

func (c *Context) State() State

func (*Context) Store

func (c *Context) Store(values ...any) *Context

func (*Context) Traverse

func (c *Context) Traverse(
	axis miruken.TraversingAxis,
	visitor miruken.TraversalVisitor,
) error

func (*Context) Unwind

func (c *Context) Unwind(reason any) *Context

func (*Context) UnwindToRoot

func (c *Context) UnwindToRoot(reason any) *Context

type Contextual

type Contextual interface {
	Context() *Context
	SetContext(ctx *Context)
	Observe(observer Observer) miruken.Disposable
}

Contextual represents anything with a Context.

type ContextualBase

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

func (*ContextualBase) ChangeContext

func (c *ContextualBase) ChangeContext(
	contextual Contextual,
	ctx *Context,
)

func (*ContextualBase) Context

func (c *ContextualBase) Context() *Context

func (*ContextualBase) EndContext

func (c *ContextualBase) EndContext()

func (*ContextualBase) Observe

func (c *ContextualBase) Observe(
	observer Observer,
) miruken.Disposable

type EndedObserver

type EndedObserver interface {
	ContextEnded(ctx *Context, reason any)
}

EndedObserver reports Context ended.

type EndedObserverFunc

type EndedObserverFunc func(ctx *Context, reason any)

func (EndedObserverFunc) ContextEnded

func (f EndedObserverFunc) ContextEnded(
	ctx *Context,
	reason any,
)

type EndingObserver

type EndingObserver interface {
	ContextEnding(ctx *Context, reason any)
}

EndingObserver reports Context is ending.

type EndingObserverFunc

type EndingObserverFunc func(ctx *Context, reason any)

func (EndingObserverFunc) ContextEnding

func (f EndingObserverFunc) ContextEnding(
	ctx *Context,
	reason any,
)

type Lifestyle

type Lifestyle struct {
	miruken.BindingGroup

	miruken.Qualifier[fromScope]
	// contains filtered or unexported fields
}

Lifestyle is a BindingGroup for requesting a scoped lifestyle. Lifestyle associates both the scoped lifestyle and fromScope constraint.

func (*Lifestyle) Init

func (s *Lifestyle) Init() error

func (*Lifestyle) InitWithTag

func (s *Lifestyle) InitWithTag(tag reflect.StructTag) error

type Observer

type Observer = interface{}

Observer is a generic Context observer.

type Reason

type Reason uint

Reason identifies the cause for the notification.

const (
	ReasonAlreadyEnded Reason = iota
	ReasonUnwinded
	ReasonDisposed
)

type Rooted

type Rooted struct {
	miruken.BindingGroup

	miruken.Qualifier[fromScope]
	// contains filtered or unexported fields
}

Rooted is a BindingGroup for requesting a rooted scoped lifestyle with all resolutions assigned to the root Context.

func (*Rooted) Init

func (s *Rooted) Init() error

func (*Rooted) InitWithTag

func (s *Rooted) InitWithTag(tag reflect.StructTag) error

type State

type State uint

State represents the state of a Context.

const (
	StateActive State = iota
	StateEnding
	StateEnded
)

Jump to

Keyboard shortcuts

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