The project can be built using Lumo
npm install -g lumo-cljs
lumo build.cljs
| (ns cljs.promise | |
| (:refer-clojure :exclude [resolve])) | |
| (defmacro promise | |
| " | |
| Example: | |
| (promise (resolve 5)) | |
| (promise (reject (js/Error. \"oops\"))) | |
| " |
| ; load some data up | |
| LDA #$7 | |
| STA $00 ; memory addr A | |
| LDA #$05 | |
| STA $01 ; memory addr B | |
| JMP Divide | |
| ;modulus, returns in register A | |
| Mod: | |
| LDA $00 ; memory addr A |
| (defn create-function-call [param expr] | |
| "Create an sexp for calling expr with a first argument provided by a promise. | |
| If expr is a list (already in form suitable for a function call), insert the first argument at second position, | |
| otherwise turn expr into a function call expression, unless the function is an fn, which is simply returned. | |
| println -> (fn [param] (println param)) | |
| (* 2) -> (fn [param] (* param 2)) | |
| /** | |
| * @typedef MutationCallback | |
| * @param {NodeList} addedNodes A NodeList of elements that have been added to the DOM. | |
| * @param {NodeList} removedNodes A NodeList of elements that have been removed from the DOM. | |
| */ | |
| /** | |
| * Add a MutationObserver to a DOM node. | |
| * | |
| * @example | |
| * |
The project can be built using Lumo
npm install -g lumo-cljs
lumo build.cljs
| (ns the-namespace.core | |
| (:require [clj-http.client :as client] | |
| [clojure.java.io :as io])) | |
| (defn- fetch-photo! | |
| "makes an HTTP request and fetches the binary object" | |
| [url] | |
| (let [req (client/get url {:as :byte-array :throw-exceptions false})] | |
| (if (= (:status req) 200) | |
| (:body req)))) |
| object EitherValidationExamples { | |
| type ValidationError = String | |
| def validateEmail(user: User): Either[ValidationError, User] = | |
| if (user.email contains "@") Right(user) else Left("Must supply a valid email") | |
| def validateAge(user: User): Either[ValidationError, User] = | |
| if (user.age > 18) Right(user) else Left("Must be over 18") |
| var parser = document.createElement('a'); | |
| parser.href = "http://example.com:3000/pathname/?search=test#hash"; | |
| parser.protocol; // => "http:" | |
| parser.hostname; // => "example.com" | |
| parser.port; // => "3000" | |
| parser.pathname; // => "/pathname/" | |
| parser.search; // => "?search=test" | |
| parser.hash; // => "#hash" | |
| parser.host; // => "example.com:3000" |
| In Application.scala: | |
| object MyServer extends AutowirePlayServer[Api] { | |
| override def routes(target: Api) = route[Api](target) | |
| override def createImpl(autowireContext: AutowireContext): Api = new ServerImpl(autowireContext) | |
| } | |
| object Application extends Controller { | |
| def api = PlayAutowire.api(MyServer)_ | |
| } |
| package controllers | |
| import play.api.http.{ContentTypes, ContentTypeOf} | |
| import upickle.Js | |
| import upickle.default._ | |
| import play.api.mvc._ | |
| import scala.concurrent.Future | |
| import scala.concurrent.ExecutionContext.Implicits.global |