{"id":13801000,"url":"https://github.com/ibdknox/jayq","last_synced_at":"2025-12-24T21:57:18.864Z","repository":{"id":2389542,"uuid":"3355509","full_name":"ibdknox/jayq","owner":"ibdknox","description":"A ClojureScript wrapper for jQuery","archived":false,"fork":false,"pushed_at":"2018-02-23T18:47:45.000Z","size":105,"stargazers_count":412,"open_issues_count":0,"forks_count":57,"subscribers_count":22,"default_branch":"master","last_synced_at":"2024-08-04T00:05:45.232Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Clojure","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"epl-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ibdknox.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-02-04T21:22:28.000Z","updated_at":"2024-02-25T13:02:02.000Z","dependencies_parsed_at":"2022-09-17T23:21:15.983Z","dependency_job_id":null,"html_url":"https://github.com/ibdknox/jayq","commit_stats":null,"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ibdknox%2Fjayq","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ibdknox%2Fjayq/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ibdknox%2Fjayq/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ibdknox%2Fjayq/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ibdknox","download_url":"https://codeload.github.com/ibdknox/jayq/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225198962,"owners_count":17437006,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-04T00:01:18.423Z","updated_at":"2025-12-24T21:57:18.853Z","avatar_url":"https://github.com/ibdknox.png","language":"Clojure","funding_links":[],"categories":["Awesome ClojureScript"],"sub_categories":["JavaScript Interoperability"],"readme":"# jayq\n\n[![Clojars Project](http://clojars.org/jayq/latest-version.svg)](http://clojars.org/jayq)\n\nA jQuery wrapper for ClojureScript.\n\n## Wait a second.. I thought we weren't supposed to use jQuery?\n\nWhen ClojureScript first came out, the prevailing wisdom was that since jQuery wasn't compatible\nwith the Google Closure Compiler, we shouldn't be using it. So I set off to work on Pinot, a library\nthat wrapped the goog.\\* APIs. The journey was painful and frustrating, and before long I realized I was\nessentially rewriting parts of jQuery for no gain. Instead of doing that, I figured my time would be\nbetter spent building on top of the most battle hardened JS library out there. Before I started down this path though, I wanted to make sure that I had answers to all the arguments\nagainst using it. They were as follows:\n\n* It can't be compiled by the Closure compiler and means we can't use Advanced compilation.\n* It will add another thing for you to download and increase the size of the cljs code, because the symbols won't be munged by the Closure compiler.\n* It won't lend itself to Clojure idioms.\n\nI'll tackle each of these in order.\n\nIn terms of it not being able to be compiled, we shouldn't be packaging jquery with our apps anyways.\nVirtually the entire web is built on $ and that means nearly every computer connected to the internet already\nhas a google CDN'd version of jquery on their machine. That means there's no extra weight and no reason\nto compile it. This also addresses the first part of the second one - there's nothing more to download.\n\nWhile it's true that if we used jQuery directly, all method calls would be left alone and could\nnot be replaced with a minified name. With a wrapper, however, that happens exactly once per method and\nall occurences of the wrapper will be munged. This means that at most we're talking about a difference\non the magnitude of bytes. If you need to optimize for size at that level, you shouldn't be using\nCLJS anyways.\n\nLastly, there's the argument that it won't lead to idiomatic usage. That's likely true if we use jQuery\ndirectly, but I'm not sure I really believe that's a valid argument. The same goes for Clojure if we use\nJava libraries directly all over the place. Wrappers, however, allow us to utilize all the functionality\nprovided by these libraries, but still create Clojure idioms over top of them. There's no reason to ignore\nthe most solid base out there, when we can just build greater abstractions on top of it. Do I think\njQuery is the pinnacle of the client side web? Not at all, but I do believe it provides a great foundation\nfor us to build exactly that.\n\n## Installation\n\nAdd the following to your `project.clj`\n\n```clojure\n[jayq \"2.5.4\"]\n```\nNote: If you are upgrading to a major version be sure to check the\n[changelog](https://github.com/ibdknox/jayq/blob/master/CHANGELOG.md)\nfor breaking changes.\n\n## Usage\n\n### jayq.core [Source](https://github.com/ibdknox/jayq/blob/master/src/jayq/core.cljs)\n\nMost of the API in `jayq.core` maps 1:1 with jQuery functions.\n\n```clojure\n(ns myapp\n  (:use [jayq.core :only [$ css html]]))\n\n(def $interface ($ :#interface))\n\n(-\u003e $interface\n  (css {:background \"blue\"})\n  (html \"Loading!\"))\n\n```\n\n#### jayq.core/ajax clojure \u0026 edn mime types support\n\nRequests with `:contentType` option matching `text/clojure` `text/edn`\n`application/clojure` `application/edn` (as string or keyword) will\nhave the :data turned into its string representation (via pr-str)\n\nResponses with `text/clojure` `text/edn` `application/clojure`\n`application/edn` mime types are read as clojure data before being\npassed to callbacks.  The same applies if the dataType option is set\nto `:edn` or `:clojure`.\n\n\n### jayq.util [Source](https://github.com/ibdknox/jayq/blob/master/src/jayq/util.cljs)\n\n* `jayq.util/log [value \u0026 text]` : console.log wrapper\n\n* `jayq.util/wait [ms f]` : setTimeout wrapper\n\n\n### jayq.macros [Source](https://github.com/ibdknox/jayq/blob/master/src/jayq/macros.clj)\n\n* `jayq.macros/queue [elem \u0026 body]` : a wrapper of `jayq.core/queue`\n  that includes the lambda with a scoped `this` symbol\n\n* `jayq.macros/ready [\u0026 body]` : a wrapper of `jayq.core/document-ready`\n\n* `jayq.macros/let-ajax [steps \u0026 body]`: `let` like form allowing\n  chaining of ajax calls and binding return values to locals for use\n  once all the calls are complete (or in a :let intermediary step).\n  The step value expected is a valid jq.core/ajax request map.\n  You can supply :let/:when steps (like in for/doseq) between \"regular\" steps.\n\n```clojure\n(let-ajax [a {:url \"http://localhost:8000/1.json\"\n              :dataType :json}\n           b  {:dataType :json :url \"http://localhost:8000/2.json\"}]\n       (merge a b))\n```\n\n* `jayq.macros/let-deferred [steps \u0026 body]`: `let` like form allowing\n  chaining of deferreds and binding return values to locals for use\n  once all the deferreds are realized (or in a :let/:when intermediary step).\n  The step value expected is anything that returns a deferred instance.\n  You can supply :let/:when steps (like in for/doseq) between \"regular\" steps.\n\n```clojure\n(let-deferred\n    [a (jq/ajax \"http://localhost:8000/1.json\")\n     :let [foo \"bar\"]\n     :when (= (concat a foo) \"foobar\")\n     b (jq/ajax \"http://localhost:8000/2.json\")]\n(merge a b foo))\n```\n\n* `jayq.macros/do-\u003e [m-specs steps \u0026 body]`: `let-*` macros are built\n  from it. `m-specs` is a map of :bind and :return functions that dictate\n  the workflow (see: `jayq.core/deferred-m` and `jayq.core/ajax-m`).\n\nError handling in `let-ajax` and `let-deferred` forms should be done using\n`jq.core/fail` or the :error key on the request map.\n\n## Changelog\n\nSee [CHANGELOG.md](https://github.com/ibdknox/jayq/blob/master/CHANGELOG.md)\n\n## Compiling\n\nIf you're using advanced Clojurescript compilation you'll need to\nreference a jQuery externs file.\n\nYou can find externs files from the\n[closure-compiler repository](https://github.com/google/closure-compiler/tree/master/contrib/externs)\nfor a specific jQuery version.\n\nAdd this to your compilation options (assuming that your put the\nexterns file in `./externs/`):\n\n```clojure\n\n  {\n    :optimizations :advanced\n    :externs [\"externs/jquery.js\"]\n    ...\n  }\n```\n\nWithout this, you will see errors like `Object ... has no method XX`. See http://lukevanderhart.com/2011/09/30/using-javascript-and-clojurescript.html for more on externs.\n\n## License\n\nCopyright (C) 2011 Chris Granger\n\nDistributed under the Eclipse Public License, the same as Clojure.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fibdknox%2Fjayq","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fibdknox%2Fjayq","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fibdknox%2Fjayq/lists"}