Vent is a Microblogging (twitter-like) application. The purpose of this tutorial is to learn the basics of Clojure, with some guidance from a tutor.
-
Clone edge and go into the tutorial
$ git clone https://github.com/juxt/edge.git $ cd edge/examples/tutorial.vent
-
Start a REPL
$ ../bin/rebel --cljs -A:dev:build:dev/build
-
Start the server
dev=> (go)
There is a front-end you can browse at http://localhost:3000.
In src/tutorial/vent/lib.clj there are a number of functions which haven’t yet been implemented. The majority of challenges require:
-
Fetching information from a "db" (A file on disk)
-
Manipulating that data
-
Writing new data to the db
There are 3 operations for the database:
(db/reset)
-
This will reset the database to a known good state
(db/store new-db)
-
Save a new version of the database
(db/read)
-
Fetch the current version of the database
These are available in your REPL.
Vents are stored in the database as a sequence. Each Vent has these keys:
:id
|
A globally unique id for this message, a number works. |
:text
|
The text of the actual vent |
:username
|
The username of the author, a string. |
:favorite?
|
(Optional) Either |
:author
|
(Optional) The data of the User (see below) who created it. This should be added after reading from the database, it should not be stored in the database. |
{:id 2
:text "Lord but I dislike poetry. How can anyone remember words that aren't put to music?"
:username "arl_the_bard"
:favorite? true}
{:id 2
:text "Lord but I dislike poetry. How can anyone remember words that aren't put to music?"
:author {:name "Arliden"
:following? true}
:username "arl_the_bard"
:favorite? true}
{:vents [{:id 1 :text "Text" :username "foo"} …]}
Users are stored in the database as a map. This is like a dictionary or hash map in other languages. The keys are usernames, and the values are Users.
Users look like so:
:name
|
A full name |
:follows
|
A list of usernames this user follows |
:following?
|
(Optional) |
{:name "John Smith"
:follows ["janesmith" "arl_the_bard"]
:following? false}
{:users {"jsmith" {:name "John Smith"
:follows ["janesmith" "arl_the_bard"]
:following? true}
"arl_the_bard" {:name "Arliden"
:follows ["janesmith"]}}}
These can all be achieved by modifying files in src/tutorial/vent/lib.clj.
Currently, the vents from all
are hard-coded.
It would be great if all
would return all the vents from the database.
Tip
|
Use (db/read) and get the :vents key out of it.
|
Add the ability to create a new vent.
Take the list of vents in the database, and filter them to show only the favorites on the favorites page.
Tip
|
Use filter and anonymous functions to filter the list of vents. |
Depends on Fetch database vents.
Now that vents are being fetched from the database, the user details are missing!
Fetch the user information from the database based on the :username
key in the vent, and add it to the vents as the :author
key.
Add the ability to see who you follow.
Tip
|
select-keys over users in your :follows key.
|
Add the ability to see who your followers are.
Tip
|
select-keys on users, based on a keep on the :users which have username in their :follows .
|
You will need to complete Implement Followers page to see this working.
Make it so that Follow/Unfollow buttons toggle the current state.
You won’t be able to see this working until you’ve done Implement favorites list.
Add the ability for the user to make a vent a favorite.
Tip
|
Use map and check using = if the current vent is the one you’re supposed to update. You might want to https://clojuredocs.org/clojure.core/not the current value. |