context

package
v0.30.113 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: MIT Imports: 12 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrScopeInactiveContext = errors.New("scoped: cannot scope instances to an inactive context")
)
View Source
var PublishFromRoot miruken.BuilderFunc = func(handler miruken.Handler) miruken.Handler {
	if context, _, ok, err := provides.Type[*Context](handler); !(ok && 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(*Context)
	Observe(Observer) miruken.Disposable
}

Contextual represents anything with a Context.

type ContextualBase

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

ContextualBase is a base implementation for Contextual.

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 Observer

type Observer = any

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
	Scoped `mode:"rooted"`
}

Rooted is a BindingGroup for configuring a rooted scoped lifestyle in which all resolutions are assigned to the root Context.

type Scoped added in v0.30.32

type Scoped struct {
	miruken.LifestyleProvider
	// contains filtered or unexported fields
}

Scoped is a LifestyleProvider that provides instances per Context.

func (*Scoped) InitLifestyle added in v0.30.32

func (s *Scoped) InitLifestyle(binding miruken.Binding) error

func (*Scoped) InitWithTag added in v0.30.32

func (s *Scoped) 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