Skip to content

Instantly share code, notes, and snippets.

@Lucifier129
Created November 16, 2021 07:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Lucifier129/08f15e29a63455444dc230588f0dab3f to your computer and use it in GitHub Desktop.
Save Lucifier129/08f15e29a63455444dc230588f0dab3f to your computer and use it in GitHub Desktop.
A showcase of Remesh DSL
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