[Ur] Minimal attempt to wrap a datepicker library (Pikaday). What do I put in js.urs ?

Stefan Scott Alexander stefanscottalexx at gmail.com
Mon Aug 3 11:21:58 EDT 2015


Well, it seems such a wrapper for Pikaday has been written in another
functional front-end language: ClojureScript.

In April 2015 somebody wrote a ClojureScript wrapper for the Pikaday
JavaScript datepicker library:

  https://timgilbert.wordpress.com/2015/04/03/i-wrote-a-thing/

Actually this implementation of a Pikaday wrapper is dependent not only on:

- ClojureScript; but also on

- Reagent - which is one of the leading ClojureScript wrappers for Facebook
React

Notes:

(1) I found Pikaday by googling [minimal javascript datepicker]. Pickaday
does not have any dependencies on other JavaScript libraries, and it says
it uses "modular" CSS.

(2) The author of this Reagent-based ClojureScript Pikaday wrapper says
that, later on, other implementations of this ClojureScript Pikaday wrapper
are also planned, which would be based on other leading ClojureScript
wrappers for Facebook React such as:

- Om; and
- re-frame

The fact that this ClojureScript Pikaday wrapper is based on a
ClojureScript React wrapper is probably a *good* thing.

For 2 reasons:

(a) It probably makes its syntax and semantics even *closer* to those of
Ur/Web

(b) It abstracts away from the React library code - which would be
redundant in Ur/Web anyways.

Implementation:

Apparently the main thing this ClojureScript Pikaday wrapper involves is a
function with three 'if'-statements which set three fields in the argument
record passed to the Pikaday object-instantiation function in JavaScript:


https://github.com/timgilbert/cljs-pikaday/blob/master/src/cljs_pikaday/reagent.cljs

It makes sense that this would be the main thing this function would do -
and I guess it directly addresses my question earlier in this thread:

>     val aPikaday : ??? -> transaction unit

> (2) The function aPikaday in file pikaday.js [*] takes an argument called
'options'.

> What is the *type* of this argument (to insert above, where the '???' is)?

[*] Originally this file was named 'Pikaday'. I changed it to
'aPikaday' to make it a valid Ur/Web 'val' identifier.

---

Now I imagine that an Ur/Web wrapper for the Pikaday library could be
more easily developed by using this ClojureScript wrapper for the
Pikaday library as a guide.

Confession:

Most JavaScript libraries have been unintelligible to me - as a
code-reading exercise. I've printed out shorter libraries which I thought
were compact and important enough to learn, and Istared at them for hours -
and I just never know what's what.

It's always some factory returning a factory which returns some anonymous
function which contains a bunch of functions - and I just never can figure
out how I could call these
functions-inside-a-function-inside-a-factory-inside-a-factory via an FFI
(foreign-function interface).

Hope:

But I can understand a ClojureScript (and CoffeeScript, etc.) library - and
it seems to directly suggest a similar (and probably much shorter!)
implementation in a language such as Ur/Web.

I hope I can jump directly from being someone who can't even read most
JavaScript libraries - to being someone who can wrap one in Ur/Web - at
least when initially given a ClojureScript wrapper of the same JavaScript
library.

###
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.impredicative.com/pipermail/ur/attachments/20150803/eb34a735/attachment.html>


More information about the Ur mailing list