Created
July 3, 2017 14:09
-
-
Save knewter/d404193a8f0b0a6622e5145d2ecea2f2 to your computer and use it in GitHub Desktop.
Hello World for Eve
This file contains hidden or 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
# Hello World | |
Eve is based on the concept of a single data store that you can search in and | |
commit to. Let's start by committing a record: | |
~~~ | |
commit | |
[#greeting message: "hello world"] | |
~~~ | |
Here we're committing a record with the tag `greeting` and a field `message` | |
containing the string `hello world`. Tags are used to specify groups of related | |
records. | |
We can search for records. Let's search for this record and display it on the | |
screen: | |
~~~ | |
search | |
[#greeting message] | |
bind | |
[#ui/text text: message] | |
~~~ | |
Here we've created a new record. It's tagged with `#ui/text`. The Eve runtime | |
will search for records of this type and display them on the screen. | |
A search might return multiple records. We'll add a new record and see it | |
displayed: | |
~~~ | |
commit | |
[#greeting message: "howdy world"] | |
~~~ | |
Eve blocks react to changes in the data store automatically. Let's take | |
advantage of this to add a clock: | |
~~~ | |
commit | |
[#time #system/timer resolution: 1000] | |
~~~ | |
Here we're committing a new record tagged with `time`. It uses `#system/timer` | |
to create a timer that updates each second. Let's display it on the screen: | |
~~~ | |
search | |
[#time second] | |
bind | |
[#ui/text text: second] | |
~~~ | |
This time we're just binding a record. This is different than committing them, | |
as this record won't persist until explicitly removed. | |
We can add a `ui/button` record to draw a button on the screen. | |
~~~ | |
commit | |
[#ui/button #increment text: "+1"] | |
~~~ | |
Now this button will be an element of type `increment` containing the text `+1`. | |
We will search for click events on this element and commit each click event to | |
the store: | |
~~~ | |
search | |
event = [#html/event/click element: [#increment]] | |
commit | |
[#clicked event] | |
~~~ | |
Here, we're finding all clicks on our `increment` elements, and committing a | |
record for each click. | |
Now our store contains a `clicked` record for each instance of us clicking on | |
the button. We can count these with the `gather/count` function, then bind a | |
text element that displays the result: | |
~~~ | |
search | |
how-many = gather/count[for: [#clicked]] | |
bind | |
[#ui/text text: "The button has been clicked {{how-many}} times"] | |
~~~ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment