Skip to content

Commit

Permalink
wip: drafting possible patterns and implementation
Browse files Browse the repository at this point in the history
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
jeronimoalbi committed Oct 6, 2024
1 parent 2e86bbe commit ff037e4
Show file tree
Hide file tree
Showing 6 changed files with 176 additions and 0 deletions.
26 changes: 26 additions & 0 deletions examples/gno.land/p/demo/boardsv2/draft1/boards.gno
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 examples/gno.land/p/demo/boardsv2/draft1/content_board.gno
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 examples/gno.land/p/demo/boardsv2/draft1/content_comment.gno
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 ""
}
32 changes: 32 additions & 0 deletions examples/gno.land/p/demo/boardsv2/draft1/content_poll.gno
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 ""
}
29 changes: 29 additions & 0 deletions examples/gno.land/p/demo/boardsv2/draft1/content_post.gno
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 ""
}
35 changes: 35 additions & 0 deletions examples/gno.land/p/demo/boardsv2/draft1/post.gno
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))
}

0 comments on commit ff037e4

Please sign in to comment.