mirror of
https://github.com/anyproto/anytype-heart.git
synced 2025-06-09 09:35:00 +09:00
GO-1367: refactoring
This commit is contained in:
parent
dca4be5607
commit
1b2179c19f
2 changed files with 17 additions and 29 deletions
|
@ -2,8 +2,6 @@ package state
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/anytypeio/go-anytype-middleware/core/block/simple/base"
|
||||
|
||||
"github.com/globalsign/mgo/bson"
|
||||
|
||||
"github.com/anytypeio/go-anytype-middleware/core/block/simple"
|
||||
|
@ -43,12 +41,7 @@ func (s *State) normalize(withLayouts bool) (err error) {
|
|||
}
|
||||
}
|
||||
if b.Model().Id == s.RootId() {
|
||||
if n, ok := b.(base.Normalizable); ok {
|
||||
if err := n.Normalize(); err != nil {
|
||||
return fmt.Errorf("custom normalization for block %s: %w", b.Model().Id, err)
|
||||
}
|
||||
}
|
||||
|
||||
s.normalizeSmartBlock(b)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -291,6 +284,22 @@ func (s *State) removeDuplicates() {
|
|||
})
|
||||
}
|
||||
|
||||
func (s *State) normalizeSmartBlock(b simple.Block) {
|
||||
if isBlockEmpty(b) {
|
||||
b.Model().Content = &model.BlockContentOfSmartblock{
|
||||
Smartblock: &model.BlockContentSmartblock{},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func isBlockEmpty(b simple.Block) bool {
|
||||
if b.Model().Content == nil {
|
||||
return true
|
||||
}
|
||||
smartBlock := b.Model().Content.(*model.BlockContentOfSmartblock)
|
||||
return smartBlock == nil || smartBlock.Smartblock == nil
|
||||
}
|
||||
|
||||
func CleanupLayouts(s *State) (removedCount int) {
|
||||
var cleanup func(id string) []string
|
||||
cleanup = func(id string) (result []string) {
|
||||
|
|
|
@ -30,10 +30,6 @@ type Base struct {
|
|||
*model.Block
|
||||
}
|
||||
|
||||
type Normalizable interface {
|
||||
Normalize() error
|
||||
}
|
||||
|
||||
func (s *Base) Model() *model.Block {
|
||||
return s.Block
|
||||
}
|
||||
|
@ -109,23 +105,6 @@ func (b *Base) String() string {
|
|||
return fmt.Sprintf("%s: %T (%d)", b.Id, b.Content, len(b.ChildrenIds))
|
||||
}
|
||||
|
||||
func (b *Base) Normalize() error {
|
||||
if isBlockEmpty(b) {
|
||||
b.Content = &model.BlockContentOfSmartblock{
|
||||
Smartblock: &model.BlockContentSmartblock{},
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func isBlockEmpty(block *Base) bool {
|
||||
if block.Content == nil {
|
||||
return true
|
||||
}
|
||||
smartBlock := block.Content.(*model.BlockContentOfSmartblock)
|
||||
return smartBlock == nil || smartBlock.Smartblock == nil
|
||||
}
|
||||
|
||||
func stringSlicesEq(s1, s2 []string) bool {
|
||||
if len(s1) != len(s2) {
|
||||
return false
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue