-
Notifications
You must be signed in to change notification settings - Fork 370
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip: drafting possible patterns and implementation
This changes are just one idea in case we want to consider using a single type, like Post or Node for example, for all board types. The proposed ideas here are based on points discussed by the team up to this point of the definition. The idea is to see if we can define a good pattern to implement the boards (boards, posts, comments, ...) using a single type as mentioned by Jae at some point during early discussions. These changes are NOT finished, they are a "showcase" for further exploration and discussion at this point.
- Loading branch information
1 parent
2e86bbe
commit ff037e4
Showing
6 changed files
with
176 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package boardsv2 | ||
|
||
// NOTE: Boards type should be a realm type | ||
type Boards struct { | ||
// NOTE: Most of all types could be saved within the same AVL tree, prefixing the level | ||
// NOTE: We provably want different AVL trees (stores) | ||
// NOTE: Again, we could consider using Node instead of Post, and tree instead of posts (semantics) | ||
posts avl.Tree // string(Post.Level + slug) -> *Post (post, comment, poll) | ||
} | ||
|
||
// NOTE: Iterating only Post type is confusing semantically | ||
// NOTE: Potential need cast/switch/type-check when iterating. | ||
func (b Boards) Iterate(slug string, fn func(*Post) bool) bool {} | ||
func (b Boards) IteratePosts(slug string, fn func(*Post) bool) bool {} | ||
func (b Boards) IterateComments(slug string, fn func(*Post) bool) bool {} | ||
|
||
// How to map render paths to actual post instances? | ||
// | ||
// AVL KEYS BY LEVEL PREFIX (start/end) | ||
// Boards => 0_ ... 1_ | ||
// Posts => 1_BOARD/ ... 2_ | ||
// Comments => 2_BOARD/POST/ ... 3_ | ||
// | ||
// HOW TO GUESS PREFIX FROM SLUG | ||
// User enters a SLUG => (one part => 1_BOARD)(more than one part => 1_BOARD/POST) | ||
// How to recognize comments? Should be URL accesible? We could use ":" as separator (not optimal) |
27 changes: 27 additions & 0 deletions
27
examples/gno.land/p/demo/boardsv2/draft1/content_board.gno
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package boardsv2 | ||
|
||
const ContentTypeBoard = "boards:board" | ||
|
||
var _ Content = (*BoardContent)(nil) | ||
|
||
type BoardContent struct { | ||
Name string | ||
} | ||
|
||
func NewBoard() *Post { | ||
return &Post{ | ||
// ... | ||
Level: LevelBoard, | ||
Content: &BoardContent{ | ||
// ... | ||
}, | ||
} | ||
} | ||
|
||
func (c BoardContent) Type() string { | ||
return ContentTypeBoard | ||
} | ||
|
||
func (c BoardContent) Render() string { | ||
return "" | ||
} |
27 changes: 27 additions & 0 deletions
27
examples/gno.land/p/demo/boardsv2/draft1/content_comment.gno
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package boardsv2 | ||
|
||
const ContentTypeComment = "boards:comment" | ||
|
||
var _ Content = (*CommentContent)(nil) | ||
|
||
type CommentContent struct { | ||
Body string | ||
} | ||
|
||
func NewComment() *Post { | ||
return &Post{ | ||
// ... | ||
Level: LevelComment, | ||
Content: &CommentContent{ | ||
// ... | ||
}, | ||
} | ||
} | ||
|
||
func (c CommentContent) Type() string { | ||
return ContentTypeComment | ||
} | ||
|
||
func (c CommentContent) Render() string { | ||
return "" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package boardsv2 | ||
|
||
const ContentTypePoll = "boards:poll" | ||
|
||
var _ Content = (*PollContent)(nil) | ||
|
||
type PollContent struct { | ||
Question string | ||
Options []string | ||
Votes []struct { | ||
Address std.Adress | ||
Option string | ||
} | ||
} | ||
|
||
func NewPoll() *Post { | ||
return &Post{ | ||
// ... | ||
Level: LevelPost, | ||
Content: &PollContent{ | ||
// ... | ||
}, | ||
} | ||
} | ||
|
||
func (c PollContent) Type() string { | ||
return ContentTypePoll | ||
} | ||
|
||
func (c PollContent) Render() string { | ||
return "" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package boardsv2 | ||
|
||
const ContentTypePost = "boards:post" | ||
|
||
var _ Content = (*TextContent)(nil) | ||
|
||
type TextContent struct { | ||
Title string | ||
Body string | ||
Tags []string | ||
} | ||
|
||
func NewPost() *Post { | ||
return &Post{ | ||
// ... | ||
Level: LevelPost, | ||
Content: &TextContent{ | ||
// ... | ||
}, | ||
} | ||
} | ||
|
||
func (c TextContent) Type() string { | ||
return ContentTypePost | ||
} | ||
|
||
func (c TextContent) Render() string { | ||
return "" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package boardsv2 | ||
|
||
import ( | ||
"strconv" | ||
) | ||
|
||
const ( | ||
LevelBoard = iota | ||
LevelPost | ||
LevelComment | ||
) | ||
|
||
type ( | ||
Content interface { | ||
Type() string | ||
Render() string | ||
} | ||
|
||
// TODO: Still have to consider how to add custom features like up/down voting, reputation, fork, lock, ... | ||
Post struct { | ||
ID string | ||
Content Content // NOTE: Maybe should be Type (board as content is odd) | ||
Level int | ||
Base *Post | ||
Children []*Post | ||
Forks []*Post | ||
UpdatedAt time.Time | ||
CreatedAt time.Time | ||
Creator std.Address | ||
} | ||
) | ||
|
||
func (p Post) NextIncrementalKey(baseKey string) string { | ||
return baseKey + "/" + strconv.Itoa(len(p.Children)) | ||
} |