@@ -20,7 +20,7 @@ poke it. There'll be a button to poke the app, and line of text
20below it saying how many times the app has been poked. We can
20below it saying how many times the app has been poked. We can
21update this by subscribing our page to the relevant path on its app.
21update this by subscribing our page to the relevant path on its app.
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.
@@ -30,26 +30,26 @@ Let's first checkout the app `/app/examples/click.hoon`:
32|_ [hid=bowl:gall clicks=@]
32|_ [hid=bowl:gall clicks=@]
33−++ poke-examples-click-click
33+++ poke-click
34− |= click/$click
34+ |= click=%click
35 ~& [%poked +(clicks)]
35 ~& [%poked +(clicks)]
36 :_ +>.$(clicks +(clicks))
36 :_ +>.$(clicks +(clicks))
37− %+ turn (prey /the-path hid)
37+ %+ turn (prey:pubsub:userlib /the-path hid)
38− |=({o=bone *} [o %diff %examples-click-clicks +(clicks)])
38+ |=([o=bone *] [o %diff %clicks +(clicks)])
39++ peer-the-path
39++ peer-the-path
40− |= pax/path
40+ |= pax=path
41− [[[ost.hid %diff %examples-click-clicks clicks] ~] +>.$]
41+ [[[ost.hid %diff %clicks clicks] ~] +>.$]
45There's nothing really new here, except that we use a couple of
45There's nothing really new here, except that we use a couple of
46new marks, `click` and `clicks`. When we get poked with a
46new marks, `click` and `clicks`. When we get poked with a
47`click`, we increment the variable `clicks` in our state and tell
47`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
49on the path `/the-path`, we immediately give them the current
49on the path `/the-path`, we immediately give them the current
50number of clicks.
50number of clicks.
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`:
55|_ click=%click
55|_ click=%click
@@ -58,68 +58,66 @@ Let's take a look at the new marks. Here's `/mar/examples/click/click.hoon`:
58 ++ noun |=(* %click)
58 ++ noun |=(* %click)
60 |= jon=^json
60 |= jon=^json
61− ?> =('click' (need (so:jo jon)))
61+ ?> =('click' (need (so:dejs-soft:format jon)))
67−The mark `examples-click-click` has type `%click`, which means the only
67+The mark `click` has type `%click`, which means the only
68valid value is `%click`. We can convert from `noun` by just
68valid value is `%click`. We can convert from `noun` by just
69producing `%click`.
69producing `%click`.
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`,
72asserting the parsing succeeded with `need`, and asserting the
72asserting the parsing succeeded with `need`, and asserting the
73result was 'click' with `?>`, which asserts that its first child
73result was 'click' with `?>`, which asserts that its first child
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`.
81−> `++jo` in `zuse` is a useful library for parsing complex json
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)`.
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)`.
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`)
90−~fintud-macrep:dojo> &examples-click-click %click
83+~fintud-macrep:dojo> &click %click
92−~fintud-macrep:dojo> &examples-click-click &json [%s 'click']
86+~fintud-macrep:dojo> &click &json [%s 'click']
94−~fintud-macrep:dojo> &examples-click-click &json &mime [/text/json (taco '"click"')]
89+~fintud-macrep:dojo> &click &json &mime [/text/json (as-octs:mimes:html '"click"')]
96−~fintud-macrep:dojo> &examples-click-click &json &mime [/text/json (taco '"clickety"')]
92+~fintud-macrep:dojo> &click &json &mime [/text/json (as-octs:mimes:html '"clickety"')]
97/~fintud-macrep/home/0/mar/click:<[7 5].[8 11]>
93/~fintud-macrep/home/0/mar/click:<[7 5].[8 11]>
98ford: casting %json to %click
94ford: casting %json to %click
99ford: cast %click
95ford: cast %click
102−And `/mar/examples/click/clicks.hoon`:
98+And save the following as `/mar/clicks.hoon`:
105|_ clicks=@
101|_ clicks=@
109− (joba %clicks (jone clicks))
109+ (frond:enjs:format %clicks (numb:enjs:format clicks))
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
115object with a single field "clicks" with our value.
115object with a single field "clicks" with our value.
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
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.
119−> produces a JSON object with one element.
122−~fintud-macrep:dojo> &json &examples-click-clicks 6
120+~fintud-macrep:dojo> &json &clicks 6
123[%o p={[p='clicks' q=[%n p=~.6]]}]
121[%o p={[p='clicks' q=[%n p=~.6]]}]
@@ -128,26 +126,26 @@ above. Everything should be pretty straightforward. Let's poke
128the app from the command line.
126the app from the command line.
131−~fintud-macrep:dojo> |start %examples-click
129+~fintud-macrep:dojo> |start %click
133−~fintud-macrep:dojo> :examples-click &examples-click-click %click
131+~fintud-macrep:dojo> :click &click %click
134[%poked 1]
132[%poked 1]
136−~fintud-macrep:dojo> :examples-click &examples-click-click %click
134+~fintud-macrep:dojo> :click &click %click
137[%poked 2]
135[%poked 2]
141−Please pardon the awkwardness of the name 'examples-click-click', but we used it to stay true to our examples naming convention.
143*Exercise*:
139*Exercise*:
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.
147# Frontend
143# Frontend
145+> Note: the instructions below are outdated and do not work in the current version of Urbit. Feel free to experiment though.
149That's all that's needed for the back end. The front end is just
147That'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`:
@@ -162,7 +160,7 @@ some "sail" html (Hoon markup for XML) and javascript. Here's `/web/pages/examp
162 ;div#err(class "disabled");
160 ;div#err(class "disabled");
163 ;div#clicks;
161 ;div#clicks;
165− ;script(type "text/javascript", src "/pages/examples/click/click.js");
163+ ;script(type "text/javascript", src "/pages/click/click.js");
@@ -171,12 +169,12 @@ You should recognize the sail syntax from an earlier chapter.
171Aside from jquery, we also include `urb.js`, which is a framework
169Aside from jquery, we also include `urb.js`, which is a framework
172for interacting with urbit.
170for interacting with urbit.
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`.
176We have a button labeled "Poke!" and a div with id `clicks` where
174We have a button labeled "Poke!" and a div with id `clicks` where
177we'll put the number of clicks. We also include a small
175we'll put the number of clicks. We also include a small
178javascript file where the client-side application logic can be
176javascript 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`:
182$(function() {
180$(function() {
@@ -189,7 +187,7 @@ $(function() {
189 $go.on("click",
187 $go.on("click",
190 function() {
188 function() {
191 window.urb.send(
189 window.urb.send(
192− "click", {mark: "examples-click-click"}
190+ "click", {mark: "click-click"}
193 ,function(err,res) {
191 ,function(err,res) {
195 return $err.text("There was an error. Sorry!")
193 return $err.text("There was an error. Sorry!")
@@ -202,7 +200,7 @@ $(function() {
205− window.urb.appl = "examples-click"
203+ window.urb.appl = "click"
206 window.urb.bind('/the-path',
204 window.urb.bind('/the-path',
207 function(err,dat) {
205 function(err,dat) {
208 clicks = dat.data.clicks
206 clicks = dat.data.clicks