Created
November 16, 2021 07:38
-
-
Save Lucifier129/08f15e29a63455444dc230588f0dab3f to your computer and use it in GitHub Desktop.
A showcase of Remesh DSL
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
domain TodoInputDomain { | |
state TodoInput = '' | |
command updateTodoInput(newTodoInput: string) { | |
return TodoInput.new(newTodoInput) | |
} | |
} | |
type Todo = { | |
id: string | |
content: string | |
completed: boolean | |
} | |
domain TodoListDomain { | |
state TodoList = [] as Todo[] | |
event AddTodoFailedEvent: { | |
message: string | |
} | |
event AddTodoSuccessEvent: { | |
todo: Todo | |
} | |
command addTodo(content: string) { | |
if (content.length < 1) { | |
return AddTodoFailedEvent({ | |
message: 'Todo content must be at least 1 character long' | |
}) | |
} | |
let todoList = TodoList.get() | |
let todo = { | |
id: uuid(), | |
content, | |
completed: false | |
} | |
return [ | |
AddTodoSuccessEvent({ todo }), | |
TodoList.new(todoList.concat(todo)) | |
] | |
} | |
} | |
domain TodoHeader { | |
domain todoInputDomain = TodoInputDomain.get() | |
domain todoListDomain = TodoListDomain.get() | |
query todoHeader() { | |
return { | |
todoInput: todoInputDomain.TodoInput.get(), | |
todoList: todoListDomain.TodoList.get() | |
} | |
} | |
command updateTodoInput = todoInputDomain.command.updateTodoInput | |
command addTodo() { | |
let content = todoInputDomain.TodoInput.get() | |
return todoListDomain.command.addTodo(content) | |
} | |
command$ todoHeader() { | |
return fromEvent(todoListDomain.event.AddTodoSuccessEvent) | |
|> map(() => todoInputDomain.command.updateTodoInput('')) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment