@@ -20,7 +20,7 @@ poke it. There'll be a button to poke the app, and line of text
2020below it saying how many times the app has been poked. We can
2121update this by subscribing our page to the relevant path on its app.
2222
23−Let's first checkout the app `/app/examples/click.hoon`:
23+Save the following as `click.hoon` in the `/app` directory of your urbit's pier.
2424
2525```
2626/? 314
@@ -30,26 +30,26 @@ Let's first checkout the app `/app/examples/click.hoon`:
3030--
3131!:
3232|_ [hid=bowl:gall clicks=@]
33−++ poke-examples-click-click
34− |= click/$click
33+++ poke-click
34+ |= click=%click
3535 ~& [%poked +(clicks)]
3636 :_ +>.$(clicks +(clicks))
37− %+ turn (prey /the-path hid)
38− |=({o=bone *} [o %diff %examples-click-clicks +(clicks)])
37+ %+ turn (prey:pubsub:userlib /the-path hid)
38+ |=([o=bone *] [o %diff %clicks +(clicks)])
3939++ peer-the-path
40− |= pax/path
41− [[[ost.hid %diff %examples-click-clicks clicks] ~] +>.$]
40+ |= pax=path
41+ [[[ost.hid %diff %clicks clicks] ~] +>.$]
4242--
4343```
4444
4545There's nothing really new here, except that we use a couple of
4646new marks, `click` and `clicks`. When we get poked with a
4747`click`, we increment the variable `clicks` in our state and tell
48−all our subcribers the new value. When someone subscribes to us
48+all our subscribers the new value. When someone subscribes to us
4949on the path `/the-path`, we immediately give them the current
5050number of clicks.
5151
52−Let's take a look at the new marks. Here's `/mar/examples/click/click.hoon`:
52+Let's take a look at the new marks. Save this as `/mar/click.hoon`:
5353
5454```
5555|_ click=%click
@@ -58,68 +58,66 @@ Let's take a look at the new marks. Here's `/mar/examples/click/click.hoon`:
5858 ++ noun |=(* %click)
5959 ++ json
6060 |= jon=^json
61− ?> =('click' (need (so:jo jon)))
61+ ?> =('click' (need (so:dejs-soft:format jon)))
6262 %click
6363 --
6464--
6565```
6666
67−The mark `examples-click-click` has type `%click`, which means the only
67+The mark `click` has type `%click`, which means the only
6868valid value is `%click`. We can convert from `noun` by just
6969producing `%click`.
7070
71−We also convert from json by parsing a json string with `so:jo`,
71+We also convert from json by parsing a json string with `so:dejs-soft:format`,
7272asserting the parsing succeeded with `need`, and asserting the
7373result was 'click' with `?>`, which asserts that its first child
7474is true.
7575
76−> Note the argument to `++json`is `jon=^json`. Why `^json`?
77−> `++json` shadows the type definition, so if we want to refer to
78−> the type, we have to prepend a `^`. This extends to multiple
79−> levels: `^^^foo` means the fourth most innermost instance of `foo`.
76+> Note the argument to `++json`is `jon=^json`. Why `^json`? `++json` shadows the type definition, so if we want to refer to the type, we have to prepend a `^`. This extends to multiple levels: `^^^foo` means the fourth most innermost instance of `foo`.
8077
81−> `++jo` in `zuse` is a useful library for parsing complex json
82−> into hoon structures. In this case, the `:` between `so` and
83−> `jo` means 'inside of', because `so` is an arm contained within
84−> the core `jo`. Our case is actually simple enough that the
85−> `?>` line could have been `?> =([%s 'click'] jon)`.
78+> `dejs-soft:format` in `zuse` is a useful library for parsing complex json into hoon structures. In this case, the `:` between `dejs-soft` and `format` means 'inside of', because `dejs-soft` is an arm contained within the core `format`. Our case is actually simple enough that the `?>` line could have been `?> =([%s 'click'] jon)`.
8679
87−We can test this mark from the command line (don't forget to start your app with `|start %examples-click`)
80+We can test this mark from the command line (don't forget to start your app with `|start %click`)
8881
8982```
90−~fintud-macrep:dojo> &examples-click-click %click
83+~fintud-macrep:dojo> &click %click
9184%click
92−~fintud-macrep:dojo> &examples-click-click &json [%s 'click']
85+
86+~fintud-macrep:dojo> &click &json [%s 'click']
9387%click
94−~fintud-macrep:dojo> &examples-click-click &json &mime [/text/json (taco '"click"')]
88+
89+~fintud-macrep:dojo> &click &json &mime [/text/json (as-octs:mimes:html '"click"')]
9590%click
96−~fintud-macrep:dojo> &examples-click-click &json &mime [/text/json (taco '"clickety"')]
91+
92+~fintud-macrep:dojo> &click &json &mime [/text/json (as-octs:mimes:html '"clickety"')]
9793/~fintud-macrep/home/0/mar/click:<[7 5].[8 11]>
9894ford: casting %json to %click
9995ford: cast %click
10096```
10197
102−And `/mar/examples/click/clicks.hoon`:
98+And save the following as `/mar/clicks.hoon`:
10399
104100```
105101|_ clicks=@
102+++ grab
103+ |%
104+ ++ noun @
105+ --
106106++ grow
107107 |%
108108 ++ json
109− (joba %clicks (jone clicks))
109+ (frond:enjs:format %clicks (numb:enjs:format clicks))
110110 --
111111--
112112```
113113
114−`examples-clicks-clicks` is just an atom. We convert to json by creating an
114+`clicks` is just an atom. We convert to json by creating an
115115object with a single field "clicks" with our value.
116116
117−> Be sure to checkout section 3bD, JSON and XML, in zuse.hoon
118−> `++joba` is just a function that takes a key-value pair and
119−> produces a JSON object with one element.
117+> Be sure to check out section 3bD, JSON and XML, in zuse.hoon `frond:enjs:format` is just a function that takes a key-value pair and produces a JSON object with one element.
120118
121119```
122−~fintud-macrep:dojo> &json &examples-click-clicks 6
120+~fintud-macrep:dojo> &json &clicks 6
123121[%o p={[p='clicks' q=[%n p=~.6]]}]
124122```
125123
@@ -128,26 +126,26 @@ above. Everything should be pretty straightforward. Let's poke
128126the app from the command line.
129127
130128```
131−~fintud-macrep:dojo> |start %examples-click
129+~fintud-macrep:dojo> |start %click
132130>=
133−~fintud-macrep:dojo> :examples-click &examples-click-click %click
131+~fintud-macrep:dojo> :click &click %click
134132[%poked 1]
135133>=
136−~fintud-macrep:dojo> :examples-click &examples-click-click %click
134+~fintud-macrep:dojo> :click &click %click
137135[%poked 2]
138136>=
139137```
140138
141−Please pardon the awkwardness of the name 'examples-click-click', but we used it to stay true to our examples naming convention.
142−
143139*Exercise*:
144140
145−- Modify `:sink` from the subcriptions chapter to listen to `:click` and print out the subscription updates on the command line.
141+- Modify `:sink` from the subscriptions chapter to listen to `:click` and print out the subscription updates on the command line.
146142
147143# Frontend
148144
145+> Note: the instructions below are outdated and do not work in the current version of Urbit. Feel free to experiment though.
146+
149147That's all that's needed for the back end. The front end is just
150−some "sail" html (Hoon markup for XML) and javascript. Here's `/web/pages/examples/click.hoon`:
148+some "sail" html (Hoon markup for XML) and javascript. Here's `/web/pages/click.hoon`:
151149
152150```
153151;html
@@ -162,7 +160,7 @@ some "sail" html (Hoon markup for XML) and javascript. Here's `/web/pages/examp
162160 ;div#err(class "disabled");
163161 ;div#clicks;
164162 ==
165− ;script(type "text/javascript", src "/pages/examples/click/click.js");
163+ ;script(type "text/javascript", src "/pages/click/click.js");
166164 ==
167165==
168166```
@@ -171,12 +169,12 @@ You should recognize the sail syntax from an earlier chapter.
171169Aside from jquery, we also include `urb.js`, which is a framework
172170for interacting with urbit.
173171
174−To view the frontend, point your browser at `ship-name.urbit.org/~~/pages/examples/click` if you're on the live network. If you're running a fake galaxy, navigate to whatever port it's running on, which is usually: `https://localhost:8443/~~/pages/examples/click`.
172+To view the frontend, point your browser at `ship-name.urbit.org/~~/pages/click` if you're on the live network. If you're running a fake galaxy, navigate to whatever port it's running on, which is usually: `https://localhost:8443/~~/pages/click`.
175173
176174We have a button labeled "Poke!" and a div with id `clicks` where
177175we'll put the number of clicks. We also include a small
178176javascript file where the client-side application logic can be
179−found. It's in `/web/pages/examples/click/click.js`:
177+found. It's in `/web/pages/click.js`:
180178
181179```
182180$(function() {
@@ -189,7 +187,7 @@ $(function() {
189187 $go.on("click",
190188 function() {
191189 window.urb.send(
192− "click", {mark: "examples-click-click"}
190+ "click", {mark: "click-click"}
193191 ,function(err,res) {
194192 if(err)
195193 return $err.text("There was an error. Sorry!")
@@ -202,7 +200,7 @@ $(function() {
202200 })
203201 })
204202
205− window.urb.appl = "examples-click"
203+ window.urb.appl = "click"
206204 window.urb.bind('/the-path',
207205 function(err,dat) {
208206 clicks = dat.data.clicks