Compare commits
No commits in common. "cbf3cabb24a9c8ebe07f5c2bf0d60030ee827798" and "e1d8c0098fb2eaaaa2f869b684592a5f6d1ba581" have entirely different histories.
cbf3cabb24
...
e1d8c0098f
|
@ -28,8 +28,7 @@ type Handle struct {
|
|||
Class []string
|
||||
Components map[string][]Components
|
||||
ThemeMods wpconfig.ThemeMods
|
||||
HandleFns map[int][]HandleCall
|
||||
Error error
|
||||
HandleFns map[int][]HandleFn[*Handle]
|
||||
}
|
||||
|
||||
func NewHandle(c *gin.Context, scene int, theme string) *Handle {
|
||||
|
@ -44,7 +43,7 @@ func NewHandle(c *gin.Context, scene int, theme string) *Handle {
|
|||
Stats: constraints.Ok,
|
||||
ThemeMods: mods,
|
||||
Components: make(map[string][]Components),
|
||||
HandleFns: make(map[int][]HandleCall),
|
||||
HandleFns: make(map[int][]HandleFn[*Handle]),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -58,7 +57,7 @@ func NewComponents(fn func(*Handle) string, order int) Components {
|
|||
return Components{Fn: fn, Order: order}
|
||||
}
|
||||
|
||||
func (h *Handle) PushHandleFn(stats int, fns ...HandleCall) {
|
||||
func (h *Handle) PushHandleFn(stats int, fns ...HandleFn[*Handle]) {
|
||||
h.HandleFns[stats] = append(h.HandleFns[stats], fns...)
|
||||
}
|
||||
|
||||
|
@ -88,20 +87,13 @@ func (h *Handle) GetPassword() {
|
|||
func (h *Handle) ExecHandleFns() {
|
||||
calls, ok := h.HandleFns[h.Stats]
|
||||
if ok {
|
||||
slice.SortSelf(calls, func(i, j HandleCall) bool {
|
||||
return i.Order > j.Order
|
||||
})
|
||||
for _, call := range calls {
|
||||
call.Fn(h)
|
||||
call(h)
|
||||
}
|
||||
}
|
||||
fns, ok := h.HandleFns[constraints.AllStats]
|
||||
if ok {
|
||||
for _, fn := range fns {
|
||||
fn.Fn(h)
|
||||
}
|
||||
for _, fn := range h.HandleFns[constraints.AllStats] {
|
||||
fn(h)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (h *Handle) PreTemplate() {
|
||||
|
@ -162,15 +154,6 @@ type HandleFn[T any] func(T)
|
|||
|
||||
type HandlePipeFn[T any] func(HandleFn[T], T)
|
||||
|
||||
type HandleCall struct {
|
||||
Fn HandleFn[*Handle]
|
||||
Order int
|
||||
}
|
||||
|
||||
func NewHandleFn(fn HandleFn[*Handle], order int) HandleCall {
|
||||
return HandleCall{Fn: fn, Order: order}
|
||||
}
|
||||
|
||||
// HandlePipe 方便把功能写在其它包里
|
||||
func HandlePipe[T any](initial func(T), fns ...HandlePipeFn[T]) HandleFn[T] {
|
||||
return slice.ReverseReduce(fns, func(next HandlePipeFn[T], f func(t T)) func(t T) {
|
||||
|
|
|
@ -41,7 +41,7 @@ func dispatch(next common.HandleFn[*common.Handle], h *common.Handle) {
|
|||
common.NewComponents(CalCustomBackGround, 10),
|
||||
common.NewComponents(colorSchemeCss, 10),
|
||||
)
|
||||
h.PushHandleFn(constraints.AllStats, common.NewHandleFn(customHeader, 10))
|
||||
h.PushHandleFn(constraints.AllStats, customHeader)
|
||||
switch h.Scene {
|
||||
case constraints.Detail:
|
||||
detail(next, h.Detail)
|
||||
|
|
|
@ -36,7 +36,7 @@ func Hook(h *common.Handle) {
|
|||
func ready(next common.HandleFn[*common.Handle], h *common.Handle) {
|
||||
h.WidgetAreaData()
|
||||
h.GetPassword()
|
||||
h.PushHandleFn(constraints.AllStats, common.NewHandleFn(calClass, 10))
|
||||
h.PushHandleFn(constraints.AllStats, calClass)
|
||||
h.PushHeadScript(
|
||||
common.NewComponents(colorScheme, 10),
|
||||
common.NewComponents(customHeader, 10),
|
||||
|
|
Loading…
Reference in New Issue
Block a user