Holy cow, callbacks!
One choice they made and that I don’t really like is using callbacks in it. For example, you have to write stuff like:
OMG, promises \o/
There are two main callbacks in the kit: when retrieving the API and when making a
submit. What I want to write is something like:
Sooooo much more readable and swag… Overriding the Api callback is really simple:
submit call is a bit more tricky because it is a prototype function of the
SearchForm object, which is totally hidden inside Prismic clojure. This is a bit (super) sad but we can deal with it by creating a fake form and not submitting it. The easiest way I found so far is doing it right after getting the Api. Let’s add the following code at
Save point 1 (see previous code).
And after that, you just need to use the new
Api function in place of
Prismic.Api. You can see the full code here using
Q library. This refers to a particular commit to ensure the line highlight is correct but you can freely switch to the master branch to see the most recent code (which shouldn’t be much different… but who knows…).
Thanks for reading. Next time we will talk about responsive images inside StructuredText.