Skip to content

Commit

Permalink
More ideas over lunchtime.
Browse files Browse the repository at this point in the history
  • Loading branch information
davemackintosh committed Jan 25, 2024
1 parent cf52b25 commit 5631a96
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 35 deletions.
36 changes: 29 additions & 7 deletions examples/ChatRoom/main.velp
Original file line number Diff line number Diff line change
@@ -1,15 +1,37 @@
import { App } from "elp/app"
import { App, Window } from "elp/app"
import { Form, Label, Input, Button } from "elp/app/elements"
import { Message, User } from "$types/chat"
import { Message as MessageView } from "$components/message"

export fn Chat: App {
export object ChatAppState implements Contextual {
.name: *string
.messages: []Message
.members: []User
.messages: [Message]
.members: [User]
.loggedIn: bool = false
}

if name not Empty {
ForEach(messages) { message in
MessageView(user = message.user, body = message.body)
// The Contextual type here actually transforms Chat into a context provider which
// along with the implements on ChatAppState gives all child components writeable
// state if it is passed down and the property is not marked as const.
// So when we pass message down by reference we can actually do .message.reactions.push(newReaction)
// and it will cause reactivity all the way up the view chain where that property is read.
export fn Chat(name: *string) implements App, Contextual<ChatAppState> -> Window {
Window {
if .name not Empty or not .loggedIn {
ForEach(.messages) { message in
// We borrow the message to pass down which extends it's lifetime
// and allows for mutation and avoids copying.
MessageView( message = &message)
}
} else {
Form(preventDefault, onSubmit={fn { .loggedIn = true }}) {
Label("Enter your display name") {
Input(name="display-name", type="text", value={.name})
Button {
Text("Log in")
}
}
}
}
}
}
11 changes: 6 additions & 5 deletions examples/ChatRoom/types/chat.elp
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { UUID } from "elp/types"

export interface User {
displayName: string
export object User {
.displayName: string
}

export interface Message {
body: string
user: User
export object Message {
.body: const string
.user: const User
.reactions: []string
}

export enum Actions {
Expand Down
5 changes: 3 additions & 2 deletions examples/HelloWorld/components/paragraph.velp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Text, Component } from "ellipsis"
import { Component } from "elp/app"
import { Text } from "elp/app/components"

export fn Paragraph(text: string): Component {
export fn Paragraph(text: string) implements Component {
Text(text)
}

Expand Down
8 changes: 5 additions & 3 deletions examples/HelloWorld/main.velp
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { App, Router } from "ellipsis"
import { App, Window } from "ellipsis"
import { Home } from "$screens/home"
import Styles from "$app/styles"

export fn HelloWorld: App(globalStyles = Styles()) {
Home()
export fn HelloWorld implements App(globalStyles = Styles()) -> Window {
Window {
Home()
}
}

6 changes: 3 additions & 3 deletions examples/HelloWorld/screens/about.velp
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { AsyncQueue, String } from "elp"
import { AsyncQueue } from "elp/app"
import { getAboutContent } from "$app/internal/api"
import { Paragraph } from "$components/paragraph"

export fn About(): Screen {
export fn About() implements Screen {
let aboutContent: String
let error: Error

AsyncQueue {
aboutContent, error = await getAboutContent()
aboutContent, error = getAboutContent()
}

Column {
Expand Down
18 changes: 6 additions & 12 deletions examples/HelloWorld/screens/home.velp
Original file line number Diff line number Diff line change
@@ -1,27 +1,21 @@
import { Column, Row, Text, Date, String } from "ellipsis"
import { Stylesheet } from "ellipsis/styling"
import { Column, Row, Text, Date } from "elp/app/elements"
import { Stylesheet } from "elp/app/styling"
import Paragraph from "$components/paragraph"

export fn Home: Screen {
export fn Home implements Screen {
const name = "Dave"

Column {
Row(columns = 2) {
Column {
Text {
String("Current date:")
}
Text("Current date:")
}
Column {
Text {
Date.Now(format="ll")
}
Text(Date.Now(format="ll"))
}
}
Row {
Text {
String("hello {name}")
}
Text("hello {name}")
Link(to = "about") {
Text("Read about Ellipsis")
}
Expand Down
6 changes: 3 additions & 3 deletions examples/kitchen-sink.velp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ enum MyEnum {

const NAME: string
const NAME: string = "hello"
variable: string = "world"
binding = 1
variadic, binding = 1, 2
var variable: string = "world"
var binding = 1
var variadic, binding = Tuple(1, 2)

fn MyFunction {}
fn MyFunction() {}
Expand Down

0 comments on commit 5631a96

Please sign in to comment.