本文整理汇总了Golang中kego/io/flux.Payload.Notify方法的典型用法代码示例。如果您正苦于以下问题:Golang Payload.Notify方法的具体用法?Golang Payload.Notify怎么用?Golang Payload.Notify使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kego/io/flux.Payload
的用法示例。
在下文中一共展示了Payload.Notify方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: validateNodes
func (s *RuleStore) validateNodes(payload *flux.Payload, changes []*node.Node) {
for _, n := range changes {
m := s.app.Nodes.Get(n)
changed, err := m.Validate(s.ctx, s.app.Rule.Get(n.Root(), n))
if err != nil {
s.app.Fail <- kerr.Wrap("BYQOBLPRDP", err)
break
}
if changed {
payload.Notify(n, NodeErrorsChanged)
}
}
}
示例2: Handle
func (s *PackageStore) Handle(payload *flux.Payload) bool {
switch action := payload.Action.(type) {
case *actions.InitialState:
pkgNode, err := node.Unmarshal(s.ctx, action.Info.Package)
if err != nil {
s.app.Fail <- kerr.Wrap("KXIKEWOKJI", err)
}
s.node = pkgNode
s.filename = action.Info.PackageFilename
payload.Notify(nil, PackageChanged)
}
return true
}
示例3: Handle
func (s *TypeStore) Handle(payload *flux.Payload) bool {
switch action := payload.Action.(type) {
case *actions.InitialState:
types := action.Info.Imports[action.Info.Path].Types
if len(types) == 0 {
break
}
for name, ti := range types {
typ, err := node.Unmarshal(s.ctx, ti.Bytes)
if err != nil {
s.app.Fail <- kerr.Wrap("QDOVEIKABS", err)
}
s.types[name] = &models.TypeModel{
Node: typ,
File: ti.File,
}
}
payload.Notify(nil, TypeChanged)
}
return true
}
示例4: Handle
func (s *MiscStore) Handle(payload *flux.Payload) bool {
switch action := payload.Action.(type) {
case *actions.ToggleInfoState:
s.info = !s.info
payload.Notify(nil, InfoStateChange)
case *actions.OpenAddPopup:
s.addPopup = &models.AddPopupModel{
Visible: true,
Parent: action.Parent,
Node: action.Node,
Types: action.Types,
}
payload.Notify(nil, AddPopupChange)
case *actions.CloseAddPopup:
s.addPopup = &models.AddPopupModel{
Visible: false,
}
payload.Notify(nil, AddPopupChange)
}
return true
}
示例5: Handle
func (s *NodeStore) Handle(payload *flux.Payload) bool {
switch action := payload.Action.(type) {
case *actions.ToggleSystemControls:
m := s.Get(action.Node)
m.ShowSystemControls = !m.ShowSystemControls
payload.Notify(action.Node, NodeSystemControls)
case *actions.Add:
payload.Wait(s.app.Actions)
switch action.Direction() {
case actions.New:
if err := mutateAddNode(s.ctx, action.Node, action.Parent, action.Key, action.Index, action.Type, action.BranchName); err != nil {
s.app.Fail <- kerr.Wrap("HUOGBUQCAO", err)
break
}
payload.Notify(action.Node, NodeInitialised)
if action.Parent != nil {
payload.Notify(action.Parent, NodeChildAdded)
}
payload.Notify(action.Node, NodeFocus)
case actions.Undo:
action.Backup = node.NewNode()
if err := mutateDeleteNode(s.ctx, action.Node, action.Parent, action.Backup); err != nil {
s.app.Fail <- kerr.Wrap("RTAGMUIKMD", err)
break
}
payload.Notify(action.Node, NodeDeleted)
if action.Parent != nil {
payload.Notify(action.Parent, NodeChildDeleted)
}
case actions.Redo:
if err := mutateRestoreNode(s.ctx, action.Node, action.Parent, action.Backup); err != nil {
s.app.Fail <- kerr.Wrap("MHUTMXOGBP", err)
break
}
payload.Notify(action.Node, NodeInitialised)
payload.Notify(action.Parent, NodeChildAdded)
payload.Notify(action.Node, NodeFocus)
}
if action.Parent != nil {
model := s.app.Nodes.Get(action.Parent)
changed, err := model.Validate(s.ctx, s.app.Rule.Get(action.Parent.Root(), action.Parent))
if err != nil {
s.app.Fail <- kerr.Wrap("AKIUPRWGLV", err)
break
}
if changed {
payload.Notify(action.Parent, NodeErrorsChanged)
}
}
c := action.Parent
for c != nil {
payload.Notify(c, NodeDescendantChanged)
c = c.Parent
}
case *actions.Delete:
payload.Wait(s.app.Actions)
switch action.Direction() {
case actions.New, actions.Redo:
action.Backup = node.NewNode()
if err := mutateDeleteNode(s.ctx, action.Node, action.Parent, action.Backup); err != nil {
s.app.Fail <- kerr.Wrap("DFHTKJRLQC", err)
break
}
payload.Notify(action.Node, NodeDeleted)
payload.Notify(action.Parent, NodeChildDeleted)
case actions.Undo:
if err := mutateRestoreNode(s.ctx, action.Node, action.Parent, action.Backup); err != nil {
s.app.Fail <- kerr.Wrap("HAPWUOPBTW", err)
break
}
payload.Notify(action.Node, NodeInitialised)
payload.Notify(action.Parent, NodeChildAdded)
payload.Notify(action.Node, NodeFocus)
}
if action.Parent != nil {
model := s.app.Nodes.Get(action.Parent)
changed, err := model.Validate(s.ctx, s.app.Rule.Get(action.Parent.Root(), action.Parent))
if err != nil {
s.app.Fail <- kerr.Wrap("IOFCSITVXB", err)
break
}
if changed {
payload.Notify(action.Parent, NodeErrorsChanged)
}
}
c := action.Parent
for c != nil {
payload.Notify(c, NodeDescendantChanged)
c = c.Parent
}
case *actions.Reorder:
payload.Wait(s.app.Actions)
if !action.Model.Node.Type.IsNativeArray() {
s.app.Fail <- kerr.New("EPBQVIICFM", "Must be array")
break
}
//.........这里部分代码省略.........
示例6: Handle
func (s *BranchStore) Handle(payload *flux.Payload) bool {
previous := s.selected
switch action := payload.Action.(type) {
case *actions.ChangeView:
s.view = action.View
s.selected = s.Root()
payload.Notify(nil, ViewChanged)
case *actions.Add:
payload.Wait(s.app.Nodes)
switch action.Direction() {
case actions.New, actions.Redo:
child, parent, err := mutateAppendBranch(s, action.Parent, action.Node, action.BranchName, action.BranchFile)
if err != nil {
s.app.Fail <- kerr.Wrap("LDBMBRHWHB", err)
break
}
if child != nil {
if ancestor := child.EnsureVisible(); ancestor != nil {
payload.NotifyWithData(ancestor, BranchOpened, &BranchDescendantSelectData{
Branch: child,
Op: models.BranchOpChildAdded,
})
}
s.selected = child
payload.Notify(previous, BranchUnselectControl)
payload.Notify(s.selected, BranchSelectControl)
payload.Notify(s.selected, BranchSelected)
}
if parent != nil {
payload.Notify(parent, BranchChildAdded)
}
case actions.Undo:
_, parent, err := mutateDeleteBranch(s, action.Node)
if err != nil {
s.app.Fail <- kerr.Wrap("NLFWVSNNTY", err)
break
}
if parent != nil {
payload.Notify(parent, BranchChildDeleted)
s.selected = parent
payload.Notify(previous, BranchUnselectControl)
payload.Notify(s.selected, BranchSelectControl)
payload.Notify(s.selected, BranchSelected)
}
}
case *actions.Delete:
payload.Wait(s.app.Nodes)
switch action.Direction() {
case actions.New, actions.Redo:
branch, parent, err := mutateDeleteBranch(s, action.Node)
if err != nil {
s.app.Fail <- kerr.Wrap("QTXPXAKXHH", err)
break
}
if branch != nil {
action.BranchIndex = branch.Index
if nci, ok := branch.Contents.(models.NodeContentsInterface); ok {
action.BranchName = nci.GetName()
}
if fci, ok := branch.Contents.(models.FileContentsInterface); ok {
action.BranchFile = fci.GetFilename()
}
}
if parent != nil {
payload.Notify(parent, BranchChildDeleted)
s.selected = parent
payload.Notify(previous, BranchUnselectControl)
payload.Notify(s.selected, BranchSelectControl)
payload.Notify(s.selected, BranchSelected)
}
case actions.Undo:
child, parent, err := mutateInsertBranch(s, action.Parent, action.Node, action.BranchIndex, action.BranchName, action.BranchFile)
if err != nil {
s.app.Fail <- kerr.Wrap("OOGOEWKPIL", err)
break
}
if child != nil {
if ancestor := child.EnsureVisible(); ancestor != nil {
payload.NotifyWithData(ancestor, BranchOpened, &BranchDescendantSelectData{
Branch: child,
Op: models.BranchOpChildAdded,
})
}
s.selected = child
payload.Notify(previous, BranchUnselectControl)
payload.Notify(s.selected, BranchSelectControl)
payload.Notify(s.selected, BranchSelected)
}
if parent != nil {
payload.Notify(parent, BranchChildAdded)
}
}
case *actions.Reorder:
payload.Wait(s.app.Nodes)
parent, err := mutateReorderBranch(s, action.Model.Node)
if err != nil {
s.app.Fail <- kerr.Wrap("NUQOPWWXHA", err)
break
}
if parent != nil {
//.........这里部分代码省略.........
示例7: Handle
func (s *ActionStore) Handle(payload *flux.Payload) bool {
u, ok := payload.Action.(actions.Undoable)
if !ok {
return true
}
switch u.Direction() {
case actions.New:
s.actions = append(s.actions[:s.index], u)
s.index = len(s.actions)
case actions.Undo:
if s.index <= 0 {
break
}
s.index--
case actions.Redo:
if s.index >= len(s.actions) {
break
}
s.index++
}
payload.Notify(nil, ActionsChanged)
/*
switch action := payload.Action.(type) {
case *actions.Add:
action.Action = &Add{
Node: action.Node,
Parent: action.Parent,
Key: action.Key,
Index: len(action.Parent.Array),
}
s.Add(action.Action)
case *actions.Delete:
action.Action = &Delete{
Parent: action.Node.Parent,
Node: action.Node,
}
s.Add(action.Action)
case *actions.Modify:
action.Action = &Modify{
Node: action.Editor.Node,
Before: action.Editor.Node.Value,
After: action.Value,
}
s.Add(action.Action)
case *actions.Reorder:
if !action.Model.Node.Type.IsNativeArray() {
s.app.Fail <- kerr.New("EPBQVIICFM", "Must be array")
break
}
action.Action = &Reorder{
Parent: action.Model.Node,
Before: action.OldIndex,
After: action.NewIndex,
}
s.Add(action.Action)
case *actions.Undo:
if s.index == 0 {
break
}
s.index--
action.Action = s.actions[s.index]
case *actions.Redo:
if s.index == len(s.actions) {
break
}
s.index++
action.Action = s.actions[s.index]
}*/
return true
}
示例8: Handle
func (s *FileStore) Handle(payload *flux.Payload) bool {
switch action := payload.Action.(type) {
case *actions.Add:
payload.Wait(s.app.Nodes)
if action.Parent != nil {
// only root nodes are files
break
}
switch action.Direction() {
case actions.New, actions.Redo:
n := action.Node
n.RecomputeHash(s.ctx, true)
fm := &models.FileModel{
Package: false,
Type: *action.Type.Id == *system.NewReference("kego.io/system", "type"),
Filename: action.BranchFile,
Node: n,
Hash: n.Hash(),
}
s.files[n] = fm
case actions.Undo:
delete(s.files, action.Node)
}
payload.Notify(nil, FileChangedStateChange)
case *actions.SaveFileSuccess:
for _, file := range action.Response.Files {
f := s.fileByName(file.File)
if f == nil {
s.app.Fail <- kerr.New("FPXNHFJNOR", "File %s not found", file.File)
}
f.SaveHash = file.Hash
}
payload.Notify(nil, FileChangedStateChange)
case *actions.InitialState:
payload.Wait(s.app.Nodes)
n := s.app.Package.Node()
fm := &models.FileModel{
Package: true,
Type: false,
Filename: s.app.Package.Filename(),
Node: n,
Hash: n.Hash(),
LoadHash: n.Hash(),
}
s.files[n] = fm
for _, ti := range s.app.Types.All() {
n := ti.Node
fm := &models.FileModel{
Package: false,
Type: true,
Filename: ti.File,
Node: n,
Hash: n.Hash(),
LoadHash: n.Hash(),
}
s.files[n] = fm
}
case *actions.LoadFileSuccess:
sci, ok := action.Branch.Contents.(models.FileContentsInterface)
if !ok {
break
}
n := sci.GetNode()
fm := &models.FileModel{
Package: false,
Type: false,
Filename: sci.GetFilename(),
Node: n,
Hash: n.Hash(),
LoadHash: n.Hash(),
}
s.files[n] = fm
}
if m, ok := payload.Action.(actions.Mutator); ok {
payload.Wait(s.app.Nodes)
n := m.CommonAncestor().Root()
f, ok := s.files[n]
if ok {
prevChanged := f.Changed()
f.Hash = n.Hash()
newChanged := f.Changed()
if prevChanged != newChanged {
// state changed!
payload.Notify(n, FileChangedStateChange)
}
}
}
return true
}