Skip to content

Commit 6c34631

Browse files
committed
move quickstart
1 parent 6be163a commit 6c34631

File tree

1 file changed

+119
-0
lines changed

1 file changed

+119
-0
lines changed

v0.3/tutorials/quickstart.eve

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
---
2+
layout: default
3+
title: Quickstart
4+
---
5+
6+
# Quickstart
7+
8+
This guide is a 5 - 10 minute introduction to the essential concepts in Eve. If you've never used Eve before, you're in the right place! Before you start with this tutorial, please follow the [installation and usage](../install) instructions, which will get you running Eve programs on your machine. In the eve-starter/programs directory, create an empty document called "quickstart.eve". Use your favorite editor to edit the program, and run it with the command:
9+
10+
```
11+
npm start -- eve-starter/programs/quickstart.eve
12+
```
13+
14+
Eve documents are written in Markdown. Eve code is written in blocks, delinated by Markdown code fences (matching pairs of ``` or ~~~ surrounding a section of code). These blocks of code search for and create records, which are key value pairs attached to a unique ID.
15+
16+
## Adding records to Eve
17+
18+
Let's start with a block that adds a record to Eve (we'll show the code fence in this block, but elide them in later blocks):
19+
20+
``````
21+
~~~
22+
commit
23+
[#greeting message: "hello world"]
24+
~~~
25+
``````
26+
27+
The record committed by this block is tagged `#greeting`, and has an attribute "message" with the value "hello world". Tags are attributes like any other, their special syntax notwithstanding. We encourage you to use tags to classify groups of related records.
28+
29+
## Finding records in Eve
30+
31+
Blocks search for records, and then bind or commit new records. Let's search for the `#greeting` we just committed, and then display it on the screen:
32+
33+
~~~eve
34+
search
35+
[#greeting message]
36+
37+
bind
38+
[#ui/text text: message]
39+
~~~
40+
41+
Searches find records that matches the supplied pattern, in this case records tagged greeting with a message attribute. You use these results to create new records. In this block, we create a `#ui/text` record for every message that is found. If no records match the search, the block has no effect. Try adding another `#greeting` record in the first block to see what happens when more than one record matches the search.
42+
43+
Variables with the same name are equivalent within a block; because they have the same name, the `message` in `[#greeting message]` and `[#ui/text text: message]` are equivalent.
44+
45+
## Records update as data changes
46+
47+
Blocks in Eve react automatically to changes in data. When a record changes, any bound records are automatically updated. Let's search for the current time, and display it on the screen:
48+
49+
~~~eve
50+
search
51+
[#time seconds]
52+
53+
bind
54+
[#ui/text text: seconds]
55+
~~~
56+
57+
As the time changes, the output updates to reflect the current state of the `#time` record. Records can be committed instead of bound, but the behavior is a little different -- committed records persist until they are removed explicitly.
58+
59+
## Reacting to events
60+
61+
Let's draw a button on the screen:
62+
63+
~~~eve
64+
commit
65+
[#ui/button #increment text: "+1"]
66+
~~~
67+
68+
When you click anywhere on the screen, Eve creates an `#html/event/click` record representing the click. You can react to clicks on the `#increment` button by searching for the `#html/event/click` record, where the element attribute is the button:
69+
70+
~~~eve
71+
search
72+
event = [#html/event/click element: [#increment]]
73+
74+
commit
75+
[#clicked event]
76+
~~~
77+
78+
Clicks only last for an instant, but we want to create a permanent record of each click so we can search for them later. This block commits a `#clicked` record that will persist until it's explicitly removed. Much like the `#greeting` text we bound to the `#ui`, variables with the same name are equivalent, so the variable `event` in the `#clicked` record is a reference to the `#html/event/click` on the `#increment` button.
79+
80+
The identity of a record is determined by its attribute/value pairs. Two records with the same attributes and values are identical in Eve. We included the `event` attribute in the `#clicked` record to differentiate each record. Without this differentiation, we could only ever create a single `#clicked` record.
81+
82+
## Count the number of clicks
83+
84+
Now let's count the number of times the button has been clicked. Make sure `event` is back in `#clicked`, and then we can count those records directly:
85+
86+
~~~eve
87+
search
88+
how-many = gather/count[for: [#clicked]]
89+
90+
bind
91+
[#ui/text text: "The button has been clicked {{how-many}} times"]
92+
~~~
93+
94+
This block searches for every unique `#clicked`, counts them, and returns that value in `how-many`. Then we display this value in a text container using the operator `{{ ... }}`, which inserts the value of the contained variable into the string. An important thing to remember here is that this block will only run when the button has been clicked at least once. Before then, this block will not run because there are no `#clicked` records to count.
95+
96+
## Summary
97+
98+
That's it for the 5 minute introduction to Eve. To summarize:
99+
100+
- Eve programs are made up of blocks.
101+
- Data are represented by records, key value pairs associated to a unique ID.
102+
- There are two sections of a block: one where you search for records, and one where you bind or commit records.
103+
- Blocks update records automatically to reflect changes in data.
104+
- Bound records are replaced when data changes, while committed records must be removed manually.
105+
- Records are unique, uniqueness is determined by a record's attributes and their values.
106+
107+
This will get you started with Eve, but there's still more to learn. From here, you can:
108+
109+
- Advance to Level 2 of the introductory tutorial (coming soon).
110+
- View the [syntax reference](../syntaxreference) or the [library reference](../handbook/libraries).
111+
- Explore already made [examples](https://github.com/witheve/eve-examples).
112+
- Or dive right in to the editor and try out the concepts you've just learned (coming soon).
113+
114+
## Appendix
115+
116+
~~~eve
117+
commit
118+
[#time #system/timer resolution: 1000]
119+
~~~

0 commit comments

Comments
 (0)