initial commit
This commit is contained in:
Executable
+109
@@ -0,0 +1,109 @@
|
||||
(ns reagent.impl.batching
|
||||
(:refer-clojure :exclude [flush])
|
||||
(:require [reagent.debug :refer-macros [dbg]]
|
||||
[reagent.interop :refer-macros [.' .!]]
|
||||
[reagent.ratom :as ratom]
|
||||
[reagent.impl.util :refer [is-client]]
|
||||
[clojure.string :as string]))
|
||||
|
||||
;;; Update batching
|
||||
|
||||
(defonce mount-count 0)
|
||||
|
||||
(defn next-mount-count []
|
||||
(set! mount-count (inc mount-count)))
|
||||
|
||||
(defn fake-raf [f]
|
||||
(js/setTimeout f 16))
|
||||
|
||||
(def next-tick
|
||||
(if-not is-client
|
||||
fake-raf
|
||||
(let [w js/window]
|
||||
(or (.' w :requestAnimationFrame)
|
||||
(.' w :webkitRequestAnimationFrame)
|
||||
(.' w :mozRequestAnimationFrame)
|
||||
(.' w :msRequestAnimationFrame)
|
||||
fake-raf))))
|
||||
|
||||
(defn compare-mount-order [c1 c2]
|
||||
(- (.' c1 :cljsMountOrder)
|
||||
(.' c2 :cljsMountOrder)))
|
||||
|
||||
(defn run-queue [a]
|
||||
;; sort components by mount order, to make sure parents
|
||||
;; are rendered before children
|
||||
(.sort a compare-mount-order)
|
||||
(dotimes [i (alength a)]
|
||||
(let [c (aget a i)]
|
||||
(when (.' c :cljsIsDirty)
|
||||
(.' c forceUpdate)))))
|
||||
|
||||
(defn run-funs [a]
|
||||
(dotimes [i (alength a)]
|
||||
((aget a i))))
|
||||
|
||||
(deftype RenderQueue [^:mutable queue ^:mutable scheduled?
|
||||
^:mutable after-render]
|
||||
Object
|
||||
(queue-render [this c]
|
||||
(.push queue c)
|
||||
(.schedule this))
|
||||
(add-after-render [_ f]
|
||||
(.push after-render f))
|
||||
(schedule [this]
|
||||
(when-not scheduled?
|
||||
(set! scheduled? true)
|
||||
(next-tick #(.run-queue this))))
|
||||
(run-queue [_]
|
||||
(let [q queue aq after-render]
|
||||
(set! queue (array))
|
||||
(set! after-render (array))
|
||||
(set! scheduled? false)
|
||||
(run-queue q)
|
||||
(run-funs aq))))
|
||||
|
||||
(def render-queue (RenderQueue. (array) false (array)))
|
||||
|
||||
(defn flush []
|
||||
(.run-queue render-queue))
|
||||
|
||||
(defn queue-render [c]
|
||||
(.! c :cljsIsDirty true)
|
||||
(.queue-render render-queue c))
|
||||
|
||||
(defn mark-rendered [c]
|
||||
(.! c :cljsIsDirty false))
|
||||
|
||||
(defn do-after-flush [f]
|
||||
(.add-after-render render-queue f))
|
||||
|
||||
(defn do-later [f]
|
||||
(do-after-flush f)
|
||||
(.schedule render-queue))
|
||||
|
||||
;; Render helper
|
||||
|
||||
(defn is-reagent-component [c]
|
||||
(some-> c (.' :props) (.' :argv)))
|
||||
|
||||
(defn run-reactively [c run]
|
||||
(assert (is-reagent-component c))
|
||||
(mark-rendered c)
|
||||
(let [rat (.' c :cljsRatom)]
|
||||
(if (nil? rat)
|
||||
(let [res (ratom/capture-derefed run c)
|
||||
derefed (ratom/captured c)]
|
||||
(when (not (nil? derefed))
|
||||
(.! c :cljsRatom
|
||||
(ratom/make-reaction run
|
||||
:auto-run #(queue-render c)
|
||||
:derefed derefed)))
|
||||
res)
|
||||
(ratom/run rat))))
|
||||
|
||||
(defn dispose [c]
|
||||
(some-> (.' c :cljsRatom)
|
||||
ratom/dispose!)
|
||||
(mark-rendered c))
|
||||
|
||||
Executable
+220
@@ -0,0 +1,220 @@
|
||||
// Compiled by ClojureScript 1.11.60 {:static-fns true, :optimize-constants true, :optimizations :advanced}
|
||||
goog.provide('reagent.impl.batching');
|
||||
goog.require('cljs.core');
|
||||
goog.require('cljs.core.constants');
|
||||
goog.require('reagent.debug');
|
||||
goog.require('reagent.interop');
|
||||
goog.require('reagent.ratom');
|
||||
goog.require('reagent.impl.util');
|
||||
goog.require('clojure.string');
|
||||
if((typeof reagent !== 'undefined') && (typeof reagent.impl !== 'undefined') && (typeof reagent.impl.batching !== 'undefined') && (typeof reagent.impl.batching.mount_count !== 'undefined')){
|
||||
} else {
|
||||
reagent.impl.batching.mount_count = (0);
|
||||
}
|
||||
reagent.impl.batching.next_mount_count = (function reagent$impl$batching$next_mount_count(){
|
||||
return (reagent.impl.batching.mount_count = (reagent.impl.batching.mount_count + (1)));
|
||||
});
|
||||
reagent.impl.batching.fake_raf = (function reagent$impl$batching$fake_raf(f){
|
||||
return setTimeout(f,(16));
|
||||
});
|
||||
reagent.impl.batching.next_tick = (((!(reagent.impl.util.is_client)))?reagent.impl.batching.fake_raf:(function (){var w = window;
|
||||
var or__5045__auto__ = (w["requestAnimationFrame"]);
|
||||
if(cljs.core.truth_(or__5045__auto__)){
|
||||
return or__5045__auto__;
|
||||
} else {
|
||||
var or__5045__auto____$1 = (w["webkitRequestAnimationFrame"]);
|
||||
if(cljs.core.truth_(or__5045__auto____$1)){
|
||||
return or__5045__auto____$1;
|
||||
} else {
|
||||
var or__5045__auto____$2 = (w["mozRequestAnimationFrame"]);
|
||||
if(cljs.core.truth_(or__5045__auto____$2)){
|
||||
return or__5045__auto____$2;
|
||||
} else {
|
||||
var or__5045__auto____$3 = (w["msRequestAnimationFrame"]);
|
||||
if(cljs.core.truth_(or__5045__auto____$3)){
|
||||
return or__5045__auto____$3;
|
||||
} else {
|
||||
return reagent.impl.batching.fake_raf;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})());
|
||||
reagent.impl.batching.compare_mount_order = (function reagent$impl$batching$compare_mount_order(c1,c2){
|
||||
return ((c1["cljsMountOrder"]) - (c2["cljsMountOrder"]));
|
||||
});
|
||||
reagent.impl.batching.run_queue = (function reagent$impl$batching$run_queue(a){
|
||||
a.sort(reagent.impl.batching.compare_mount_order);
|
||||
|
||||
var n__5636__auto__ = a.length;
|
||||
var i = (0);
|
||||
while(true){
|
||||
if((i < n__5636__auto__)){
|
||||
var c_7393 = (a[i]);
|
||||
if(cljs.core.truth_((c_7393["cljsIsDirty"]))){
|
||||
(c_7393["forceUpdate"])();
|
||||
} else {
|
||||
}
|
||||
|
||||
var G__7394 = (i + (1));
|
||||
i = G__7394;
|
||||
continue;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
break;
|
||||
}
|
||||
});
|
||||
reagent.impl.batching.run_funs = (function reagent$impl$batching$run_funs(a){
|
||||
var n__5636__auto__ = a.length;
|
||||
var i = (0);
|
||||
while(true){
|
||||
if((i < n__5636__auto__)){
|
||||
var fexpr__7395_7396 = (a[i]);
|
||||
(fexpr__7395_7396.cljs$core$IFn$_invoke$arity$0 ? fexpr__7395_7396.cljs$core$IFn$_invoke$arity$0() : fexpr__7395_7396.call(null));
|
||||
|
||||
var G__7397 = (i + (1));
|
||||
i = G__7397;
|
||||
continue;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @implements {reagent.impl.batching.Object}
|
||||
*/
|
||||
reagent.impl.batching.RenderQueue = (function (queue,scheduled_QMARK_,after_render){
|
||||
this.queue = queue;
|
||||
this.scheduled_QMARK_ = scheduled_QMARK_;
|
||||
this.after_render = after_render;
|
||||
});
|
||||
(reagent.impl.batching.RenderQueue.prototype.queue_render = (function (c){
|
||||
var self__ = this;
|
||||
var this$ = this;
|
||||
self__.queue.push(c);
|
||||
|
||||
return this$.schedule();
|
||||
}));
|
||||
|
||||
(reagent.impl.batching.RenderQueue.prototype.add_after_render = (function (f){
|
||||
var self__ = this;
|
||||
var _ = this;
|
||||
return self__.after_render.push(f);
|
||||
}));
|
||||
|
||||
(reagent.impl.batching.RenderQueue.prototype.schedule = (function (){
|
||||
var self__ = this;
|
||||
var this$ = this;
|
||||
if(cljs.core.truth_(self__.scheduled_QMARK_)){
|
||||
return null;
|
||||
} else {
|
||||
(self__.scheduled_QMARK_ = true);
|
||||
|
||||
var G__7398 = (function (){
|
||||
return this$.run_queue();
|
||||
});
|
||||
return (reagent.impl.batching.next_tick.cljs$core$IFn$_invoke$arity$1 ? reagent.impl.batching.next_tick.cljs$core$IFn$_invoke$arity$1(G__7398) : reagent.impl.batching.next_tick.call(null,G__7398));
|
||||
}
|
||||
}));
|
||||
|
||||
(reagent.impl.batching.RenderQueue.prototype.run_queue = (function (){
|
||||
var self__ = this;
|
||||
var _ = this;
|
||||
var q = self__.queue;
|
||||
var aq = self__.after_render;
|
||||
(self__.queue = []);
|
||||
|
||||
(self__.after_render = []);
|
||||
|
||||
(self__.scheduled_QMARK_ = false);
|
||||
|
||||
reagent.impl.batching.run_queue(q);
|
||||
|
||||
return reagent.impl.batching.run_funs(aq);
|
||||
}));
|
||||
|
||||
(reagent.impl.batching.RenderQueue.getBasis = (function (){
|
||||
return new cljs.core.PersistentVector(null, 3, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.with_meta(cljs.core.cst$sym$queue,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null)),cljs.core.with_meta(cljs.core.cst$sym$scheduled_QMARK_,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null)),cljs.core.with_meta(cljs.core.cst$sym$after_DASH_render,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null))], null);
|
||||
}));
|
||||
|
||||
(reagent.impl.batching.RenderQueue.cljs$lang$type = true);
|
||||
|
||||
(reagent.impl.batching.RenderQueue.cljs$lang$ctorStr = "reagent.impl.batching/RenderQueue");
|
||||
|
||||
(reagent.impl.batching.RenderQueue.cljs$lang$ctorPrWriter = (function (this__5330__auto__,writer__5331__auto__,opt__5332__auto__){
|
||||
return cljs.core._write(writer__5331__auto__,"reagent.impl.batching/RenderQueue");
|
||||
}));
|
||||
|
||||
/**
|
||||
* Positional factory function for reagent.impl.batching/RenderQueue.
|
||||
*/
|
||||
reagent.impl.batching.__GT_RenderQueue = (function reagent$impl$batching$__GT_RenderQueue(queue,scheduled_QMARK_,after_render){
|
||||
return (new reagent.impl.batching.RenderQueue(queue,scheduled_QMARK_,after_render));
|
||||
});
|
||||
|
||||
reagent.impl.batching.render_queue = (new reagent.impl.batching.RenderQueue([],false,[]));
|
||||
reagent.impl.batching.flush = (function reagent$impl$batching$flush(){
|
||||
return reagent.impl.batching.render_queue.run_queue();
|
||||
});
|
||||
reagent.impl.batching.queue_render = (function reagent$impl$batching$queue_render(c){
|
||||
(c["cljsIsDirty"] = true);
|
||||
|
||||
return reagent.impl.batching.render_queue.queue_render(c);
|
||||
});
|
||||
reagent.impl.batching.mark_rendered = (function reagent$impl$batching$mark_rendered(c){
|
||||
return (c["cljsIsDirty"] = false);
|
||||
});
|
||||
reagent.impl.batching.do_after_flush = (function reagent$impl$batching$do_after_flush(f){
|
||||
return reagent.impl.batching.render_queue.add_after_render(f);
|
||||
});
|
||||
reagent.impl.batching.do_later = (function reagent$impl$batching$do_later(f){
|
||||
reagent.impl.batching.do_after_flush(f);
|
||||
|
||||
return reagent.impl.batching.render_queue.schedule();
|
||||
});
|
||||
reagent.impl.batching.is_reagent_component = (function reagent$impl$batching$is_reagent_component(c){
|
||||
var G__7399 = c;
|
||||
var G__7399__$1 = (((G__7399 == null))?null:(G__7399["props"]));
|
||||
if((G__7399__$1 == null)){
|
||||
return null;
|
||||
} else {
|
||||
return (G__7399__$1["argv"]);
|
||||
}
|
||||
});
|
||||
reagent.impl.batching.run_reactively = (function reagent$impl$batching$run_reactively(c,run){
|
||||
if(cljs.core.truth_(reagent.impl.batching.is_reagent_component(c))){
|
||||
} else {
|
||||
throw (new Error("Assert failed: (is-reagent-component c)"));
|
||||
}
|
||||
|
||||
reagent.impl.batching.mark_rendered(c);
|
||||
|
||||
var rat = (c["cljsRatom"]);
|
||||
if((rat == null)){
|
||||
var res = reagent.ratom.capture_derefed(run,c);
|
||||
var derefed = reagent.ratom.captured(c);
|
||||
if((!((derefed == null)))){
|
||||
(c["cljsRatom"] = reagent.ratom.make_reaction.cljs$core$IFn$_invoke$arity$variadic(run,cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2([cljs.core.cst$kw$auto_DASH_run,(function (){
|
||||
return reagent.impl.batching.queue_render(c);
|
||||
}),cljs.core.cst$kw$derefed,derefed], 0)));
|
||||
} else {
|
||||
}
|
||||
|
||||
return res;
|
||||
} else {
|
||||
return reagent.ratom.run(rat);
|
||||
}
|
||||
});
|
||||
reagent.impl.batching.dispose = (function reagent$impl$batching$dispose(c){
|
||||
var G__7400_7401 = (c["cljsRatom"]);
|
||||
if((G__7400_7401 == null)){
|
||||
} else {
|
||||
reagent.ratom.dispose_BANG_(G__7400_7401);
|
||||
}
|
||||
|
||||
return reagent.impl.batching.mark_rendered(c);
|
||||
});
|
||||
Executable
+287
@@ -0,0 +1,287 @@
|
||||
(ns reagent.impl.component
|
||||
(:require [reagent.impl.util :as util]
|
||||
[reagent.impl.batching :as batch]
|
||||
[reagent.ratom :as ratom]
|
||||
[reagent.interop :refer-macros [.' .!]]
|
||||
[reagent.debug :refer-macros [dbg prn dev? warn]]))
|
||||
|
||||
(declare ^:dynamic *current-component*)
|
||||
|
||||
(declare ^:dynamic *non-reactive*)
|
||||
|
||||
;;; State
|
||||
|
||||
(defn state-atom [this]
|
||||
(let [sa (.' this :cljsState)]
|
||||
(if-not (nil? sa)
|
||||
sa
|
||||
(.! this :cljsState (ratom/atom nil)))))
|
||||
|
||||
;; ugly circular dependency
|
||||
(defn as-element [x]
|
||||
(js/reagent.impl.template.as-element x))
|
||||
|
||||
;;; Rendering
|
||||
|
||||
(defn reagent-class? [c]
|
||||
(and (fn? c)
|
||||
(some? (.' c :cljsReactClass))))
|
||||
|
||||
(defn do-render-sub [c]
|
||||
(let [f (.' c :cljsRender)
|
||||
_ (assert (ifn? f))
|
||||
p (.' c :props)
|
||||
res (if (nil? (.' c :reagentRender))
|
||||
(f c)
|
||||
(let [argv (.' p :argv)
|
||||
n (count argv)]
|
||||
(case n
|
||||
1 (f)
|
||||
2 (f (nth argv 1))
|
||||
3 (f (nth argv 1) (nth argv 2))
|
||||
4 (f (nth argv 1) (nth argv 2) (nth argv 3))
|
||||
5 (f (nth argv 1) (nth argv 2) (nth argv 3) (nth argv 4))
|
||||
(apply f (subvec argv 1)))))]
|
||||
(if (vector? res)
|
||||
(as-element res)
|
||||
(if (ifn? res)
|
||||
(let [f (if (reagent-class? res)
|
||||
(fn [& args]
|
||||
(as-element (apply vector res args)))
|
||||
res)]
|
||||
(.! c :cljsRender f)
|
||||
(recur c))
|
||||
res))))
|
||||
|
||||
(declare comp-name)
|
||||
|
||||
(defn do-render [c]
|
||||
(binding [*current-component* c]
|
||||
(if (dev?)
|
||||
;; Log errors, without using try/catch (and mess up call stack)
|
||||
(let [ok (array false)]
|
||||
(try
|
||||
(let [res (do-render-sub c)]
|
||||
(aset ok 0 true)
|
||||
res)
|
||||
(finally
|
||||
(when-not (aget ok 0)
|
||||
(js/console.error (str "Error rendering component "
|
||||
(comp-name)))))))
|
||||
(do-render-sub c))))
|
||||
|
||||
|
||||
;;; Method wrapping
|
||||
|
||||
(def static-fns {:render
|
||||
(fn []
|
||||
(this-as c
|
||||
(if-not *non-reactive*
|
||||
(batch/run-reactively c #(do-render c))
|
||||
(do-render c))))})
|
||||
|
||||
(defn custom-wrapper [key f]
|
||||
(case key
|
||||
:getDefaultProps
|
||||
(assert false "getDefaultProps not supported yet")
|
||||
|
||||
:getInitialState
|
||||
(fn []
|
||||
(this-as c
|
||||
(reset! (state-atom c) (f c))))
|
||||
|
||||
:componentWillReceiveProps
|
||||
(fn [props]
|
||||
(this-as c
|
||||
(f c (.' props :argv))))
|
||||
|
||||
:shouldComponentUpdate
|
||||
(fn [nextprops nextstate]
|
||||
(or util/*always-update*
|
||||
(this-as c
|
||||
;; Don't care about nextstate here, we use forceUpdate
|
||||
;; when only when state has changed anyway.
|
||||
(let [old-argv (.' c :props.argv)
|
||||
new-argv (.' nextprops :argv)]
|
||||
(if (nil? f)
|
||||
(or (nil? old-argv)
|
||||
(nil? new-argv)
|
||||
(not= old-argv new-argv))
|
||||
(f c old-argv new-argv))))))
|
||||
|
||||
:componentWillUpdate
|
||||
(fn [nextprops]
|
||||
(this-as c
|
||||
(f c (.' nextprops :argv))))
|
||||
|
||||
:componentDidUpdate
|
||||
(fn [oldprops]
|
||||
(this-as c
|
||||
(f c (.' oldprops :argv))))
|
||||
|
||||
:componentWillMount
|
||||
(fn []
|
||||
(this-as c
|
||||
(.! c :cljsMountOrder (batch/next-mount-count))
|
||||
(when-not (nil? f)
|
||||
(f c))))
|
||||
|
||||
:componentWillUnmount
|
||||
(fn []
|
||||
(this-as c
|
||||
(batch/dispose c)
|
||||
(when-not (nil? f)
|
||||
(f c))))
|
||||
|
||||
nil))
|
||||
|
||||
(defn default-wrapper [f]
|
||||
(if (ifn? f)
|
||||
(fn [& args]
|
||||
(this-as c (apply f c args)))
|
||||
f))
|
||||
|
||||
(def dont-wrap #{:cljsRender :render :reagentRender :cljsName})
|
||||
|
||||
(defn dont-bind [f]
|
||||
(if (fn? f)
|
||||
(doto f
|
||||
(.! :__reactDontBind true))
|
||||
f))
|
||||
|
||||
(defn get-wrapper [key f name]
|
||||
(if (dont-wrap key)
|
||||
(dont-bind f)
|
||||
(let [wrap (custom-wrapper key f)]
|
||||
(when (and wrap f)
|
||||
(assert (ifn? f)
|
||||
(str "Expected function in " name key " but got " f)))
|
||||
(or wrap (default-wrapper f)))))
|
||||
|
||||
(def obligatory {:shouldComponentUpdate nil
|
||||
:componentWillMount nil
|
||||
:componentWillUnmount nil})
|
||||
|
||||
(def dash-to-camel (util/memoize-1 util/dash-to-camel))
|
||||
|
||||
(defn camelify-map-keys [fun-map]
|
||||
(reduce-kv (fn [m k v]
|
||||
(assoc m (-> k dash-to-camel keyword) v))
|
||||
{} fun-map))
|
||||
|
||||
(defn add-obligatory [fun-map]
|
||||
(merge obligatory fun-map))
|
||||
|
||||
(defn add-render [fun-map render-f name]
|
||||
(let [fm (assoc fun-map
|
||||
:cljsRender render-f
|
||||
:render (:render static-fns))]
|
||||
(if (dev?)
|
||||
(assoc fm :cljsName (fn [] name))
|
||||
fm)))
|
||||
|
||||
(defn fun-name [f]
|
||||
(or (and (fn? f)
|
||||
(or (.' f :displayName)
|
||||
(.' f :name)))
|
||||
(and (implements? INamed f)
|
||||
(name f))
|
||||
(let [m (meta f)]
|
||||
(if (map? m)
|
||||
(:name m)))))
|
||||
|
||||
(defn wrap-funs [fmap]
|
||||
(let [fun-map (if-some [cf (:componentFunction fmap)]
|
||||
(-> fmap
|
||||
(assoc :reagentRender cf)
|
||||
(dissoc :componentFunction))
|
||||
fmap)
|
||||
render-fun (or (:reagentRender fun-map)
|
||||
(:render fun-map))
|
||||
_ (assert (ifn? render-fun)
|
||||
(str "Render must be a function, not "
|
||||
(pr-str render-fun)))
|
||||
name (str (or (:displayName fun-map)
|
||||
(fun-name render-fun)))
|
||||
name' (if (empty? name)
|
||||
(str (gensym "reagent"))
|
||||
(clojure.string/replace name #"\$" "."))
|
||||
fmap (-> fun-map
|
||||
(assoc :displayName name')
|
||||
(add-render render-fun name'))]
|
||||
(reduce-kv (fn [m k v]
|
||||
(assoc m k (get-wrapper k v name')))
|
||||
{} fmap)))
|
||||
|
||||
(defn map-to-js [m]
|
||||
(reduce-kv (fn [o k v]
|
||||
(doto o
|
||||
(aset (name k) v)))
|
||||
#js{} m))
|
||||
|
||||
(defn cljsify [body]
|
||||
(-> body
|
||||
camelify-map-keys
|
||||
add-obligatory
|
||||
wrap-funs
|
||||
map-to-js))
|
||||
|
||||
(defn create-class
|
||||
[body]
|
||||
(assert (map? body))
|
||||
(let [spec (cljsify body)
|
||||
res (.' js/React createClass spec)
|
||||
f (fn [& args]
|
||||
(warn "Calling the result of create-class as a function is "
|
||||
"deprecated in " (.' res :displayName) ". Use a vector "
|
||||
"instead.")
|
||||
(as-element (apply vector res args)))]
|
||||
(util/cache-react-class f res)
|
||||
(util/cache-react-class res res)
|
||||
f))
|
||||
|
||||
(defn component-path [c]
|
||||
(let [elem (some-> (or (some-> c
|
||||
(.' :_reactInternalInstance))
|
||||
c)
|
||||
(.' :_currentElement))
|
||||
name (some-> elem
|
||||
(.' :type)
|
||||
(.' :displayName))
|
||||
path (some-> elem
|
||||
(.' :_owner)
|
||||
component-path
|
||||
(str " > "))
|
||||
res (str path name)]
|
||||
(when-not (empty? res) res)))
|
||||
|
||||
(defn comp-name []
|
||||
(if (dev?)
|
||||
(let [c *current-component*
|
||||
n (or (component-path c)
|
||||
(some-> c (.' cljsName)))]
|
||||
(if-not (empty? n)
|
||||
(str " (in " n ")")
|
||||
""))
|
||||
""))
|
||||
|
||||
(defn shallow-obj-to-map [o]
|
||||
(into {} (for [k (js-keys o)]
|
||||
[(keyword k) (aget o k)])))
|
||||
|
||||
(def elem-counter 0)
|
||||
|
||||
(defn reactify-component [comp]
|
||||
(.' js/React createClass
|
||||
#js{:displayName "react-wrapper"
|
||||
:render
|
||||
(fn []
|
||||
(this-as this
|
||||
(as-element
|
||||
[comp
|
||||
(-> (.' this :props)
|
||||
shallow-obj-to-map
|
||||
;; ensure re-render, might get mutable js data
|
||||
(assoc :-elem-count
|
||||
(set! elem-counter
|
||||
(inc elem-counter))))])))}))
|
||||
Executable
+541
@@ -0,0 +1,541 @@
|
||||
// Compiled by ClojureScript 1.11.60 {:static-fns true, :optimize-constants true, :optimizations :advanced}
|
||||
goog.provide('reagent.impl.component');
|
||||
goog.require('cljs.core');
|
||||
goog.require('cljs.core.constants');
|
||||
goog.require('reagent.impl.util');
|
||||
goog.require('reagent.impl.batching');
|
||||
goog.require('reagent.ratom');
|
||||
goog.require('reagent.interop');
|
||||
goog.require('reagent.debug');
|
||||
reagent.impl.component.state_atom = (function reagent$impl$component$state_atom(this$){
|
||||
var sa = (this$["cljsState"]);
|
||||
if((!((sa == null)))){
|
||||
return sa;
|
||||
} else {
|
||||
return (this$["cljsState"] = reagent.ratom.atom.cljs$core$IFn$_invoke$arity$1(null));
|
||||
}
|
||||
});
|
||||
reagent.impl.component.as_element = (function reagent$impl$component$as_element(x){
|
||||
return reagent.impl.template.as_element(x);
|
||||
});
|
||||
reagent.impl.component.reagent_class_QMARK_ = (function reagent$impl$component$reagent_class_QMARK_(c){
|
||||
return ((cljs.core.fn_QMARK_(c)) && ((!(((c["cljsReactClass"]) == null)))));
|
||||
});
|
||||
reagent.impl.component.do_render_sub = (function reagent$impl$component$do_render_sub(c){
|
||||
while(true){
|
||||
var f = (c["cljsRender"]);
|
||||
var _ = ((cljs.core.ifn_QMARK_(f))?null:(function(){throw (new Error("Assert failed: (ifn? f)"))})());
|
||||
var p = (c["props"]);
|
||||
var res = ((((c["reagentRender"]) == null))?(f.cljs$core$IFn$_invoke$arity$1 ? f.cljs$core$IFn$_invoke$arity$1(c) : f.call(null,c)):(function (){var argv = (p["argv"]);
|
||||
var n = cljs.core.count(argv);
|
||||
var G__7404 = n;
|
||||
switch (G__7404) {
|
||||
case (1):
|
||||
return (f.cljs$core$IFn$_invoke$arity$0 ? f.cljs$core$IFn$_invoke$arity$0() : f.call(null));
|
||||
|
||||
break;
|
||||
case (2):
|
||||
var G__7405 = cljs.core.nth.cljs$core$IFn$_invoke$arity$2(argv,(1));
|
||||
return (f.cljs$core$IFn$_invoke$arity$1 ? f.cljs$core$IFn$_invoke$arity$1(G__7405) : f.call(null,G__7405));
|
||||
|
||||
break;
|
||||
case (3):
|
||||
var G__7406 = cljs.core.nth.cljs$core$IFn$_invoke$arity$2(argv,(1));
|
||||
var G__7407 = cljs.core.nth.cljs$core$IFn$_invoke$arity$2(argv,(2));
|
||||
return (f.cljs$core$IFn$_invoke$arity$2 ? f.cljs$core$IFn$_invoke$arity$2(G__7406,G__7407) : f.call(null,G__7406,G__7407));
|
||||
|
||||
break;
|
||||
case (4):
|
||||
var G__7408 = cljs.core.nth.cljs$core$IFn$_invoke$arity$2(argv,(1));
|
||||
var G__7409 = cljs.core.nth.cljs$core$IFn$_invoke$arity$2(argv,(2));
|
||||
var G__7410 = cljs.core.nth.cljs$core$IFn$_invoke$arity$2(argv,(3));
|
||||
return (f.cljs$core$IFn$_invoke$arity$3 ? f.cljs$core$IFn$_invoke$arity$3(G__7408,G__7409,G__7410) : f.call(null,G__7408,G__7409,G__7410));
|
||||
|
||||
break;
|
||||
case (5):
|
||||
var G__7411 = cljs.core.nth.cljs$core$IFn$_invoke$arity$2(argv,(1));
|
||||
var G__7412 = cljs.core.nth.cljs$core$IFn$_invoke$arity$2(argv,(2));
|
||||
var G__7413 = cljs.core.nth.cljs$core$IFn$_invoke$arity$2(argv,(3));
|
||||
var G__7414 = cljs.core.nth.cljs$core$IFn$_invoke$arity$2(argv,(4));
|
||||
return (f.cljs$core$IFn$_invoke$arity$4 ? f.cljs$core$IFn$_invoke$arity$4(G__7411,G__7412,G__7413,G__7414) : f.call(null,G__7411,G__7412,G__7413,G__7414));
|
||||
|
||||
break;
|
||||
default:
|
||||
return cljs.core.apply.cljs$core$IFn$_invoke$arity$2(f,cljs.core.subvec.cljs$core$IFn$_invoke$arity$2(argv,(1)));
|
||||
|
||||
}
|
||||
})());
|
||||
if(cljs.core.vector_QMARK_(res)){
|
||||
return reagent.impl.component.as_element(res);
|
||||
} else {
|
||||
if(cljs.core.ifn_QMARK_(res)){
|
||||
var f__$1 = ((reagent.impl.component.reagent_class_QMARK_(res))?((function (c,f,_,p,res){
|
||||
return (function() {
|
||||
var G__7416__delegate = function (args){
|
||||
return reagent.impl.component.as_element(cljs.core.apply.cljs$core$IFn$_invoke$arity$3(cljs.core.vector,res,args));
|
||||
};
|
||||
var G__7416 = function (var_args){
|
||||
var args = null;
|
||||
if (arguments.length > 0) {
|
||||
var G__7417__i = 0, G__7417__a = new Array(arguments.length - 0);
|
||||
while (G__7417__i < G__7417__a.length) {G__7417__a[G__7417__i] = arguments[G__7417__i + 0]; ++G__7417__i;}
|
||||
args = new cljs.core.IndexedSeq(G__7417__a,0,null);
|
||||
}
|
||||
return G__7416__delegate.call(this,args);};
|
||||
G__7416.cljs$lang$maxFixedArity = 0;
|
||||
G__7416.cljs$lang$applyTo = (function (arglist__7418){
|
||||
var args = cljs.core.seq(arglist__7418);
|
||||
return G__7416__delegate(args);
|
||||
});
|
||||
G__7416.cljs$core$IFn$_invoke$arity$variadic = G__7416__delegate;
|
||||
return G__7416;
|
||||
})()
|
||||
;})(c,f,_,p,res))
|
||||
:res);
|
||||
(c["cljsRender"] = f__$1);
|
||||
|
||||
var G__7419 = c;
|
||||
c = G__7419;
|
||||
continue;
|
||||
} else {
|
||||
return res;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
});
|
||||
reagent.impl.component.do_render = (function reagent$impl$component$do_render(c){
|
||||
var _STAR_current_component_STAR__orig_val__7420 = reagent.impl.component._STAR_current_component_STAR_;
|
||||
var _STAR_current_component_STAR__temp_val__7421 = c;
|
||||
(reagent.impl.component._STAR_current_component_STAR_ = _STAR_current_component_STAR__temp_val__7421);
|
||||
|
||||
try{var ok = [false];
|
||||
try{var res = reagent.impl.component.do_render_sub(c);
|
||||
(ok[(0)] = true);
|
||||
|
||||
return res;
|
||||
}finally {if(cljs.core.truth_((ok[(0)]))){
|
||||
} else {
|
||||
console.error(["Error rendering component ",cljs.core.str.cljs$core$IFn$_invoke$arity$1((reagent.impl.component.comp_name.cljs$core$IFn$_invoke$arity$0 ? reagent.impl.component.comp_name.cljs$core$IFn$_invoke$arity$0() : reagent.impl.component.comp_name.call(null)))].join(''));
|
||||
}
|
||||
}
|
||||
}finally {(reagent.impl.component._STAR_current_component_STAR_ = _STAR_current_component_STAR__orig_val__7420);
|
||||
}});
|
||||
reagent.impl.component.static_fns = new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$render,(function (){
|
||||
var c = this;
|
||||
if(cljs.core.not(reagent.impl.component._STAR_non_reactive_STAR_)){
|
||||
return reagent.impl.batching.run_reactively(c,(function (){
|
||||
return reagent.impl.component.do_render(c);
|
||||
}));
|
||||
} else {
|
||||
return reagent.impl.component.do_render(c);
|
||||
}
|
||||
})], null);
|
||||
reagent.impl.component.custom_wrapper = (function reagent$impl$component$custom_wrapper(key,f){
|
||||
var G__7422 = key;
|
||||
var G__7422__$1 = (((G__7422 instanceof cljs.core.Keyword))?G__7422.fqn:null);
|
||||
switch (G__7422__$1) {
|
||||
case "getDefaultProps":
|
||||
throw (new Error(["Assert failed: ","getDefaultProps not supported yet","\n","false"].join('')));
|
||||
|
||||
|
||||
break;
|
||||
case "getInitialState":
|
||||
return (function (){
|
||||
var c = this;
|
||||
return cljs.core.reset_BANG_(reagent.impl.component.state_atom(c),(f.cljs$core$IFn$_invoke$arity$1 ? f.cljs$core$IFn$_invoke$arity$1(c) : f.call(null,c)));
|
||||
});
|
||||
|
||||
break;
|
||||
case "componentWillReceiveProps":
|
||||
return (function (props){
|
||||
var c = this;
|
||||
var G__7423 = c;
|
||||
var G__7424 = (props["argv"]);
|
||||
return (f.cljs$core$IFn$_invoke$arity$2 ? f.cljs$core$IFn$_invoke$arity$2(G__7423,G__7424) : f.call(null,G__7423,G__7424));
|
||||
});
|
||||
|
||||
break;
|
||||
case "shouldComponentUpdate":
|
||||
return (function (nextprops,nextstate){
|
||||
var or__5045__auto__ = reagent.impl.util._STAR_always_update_STAR_;
|
||||
if(cljs.core.truth_(or__5045__auto__)){
|
||||
return or__5045__auto__;
|
||||
} else {
|
||||
var c = this;
|
||||
var old_argv = (c["props"]["argv"]);
|
||||
var new_argv = (nextprops["argv"]);
|
||||
if((f == null)){
|
||||
return (((old_argv == null)) || ((((new_argv == null)) || (cljs.core.not_EQ_.cljs$core$IFn$_invoke$arity$2(old_argv,new_argv)))));
|
||||
} else {
|
||||
return (f.cljs$core$IFn$_invoke$arity$3 ? f.cljs$core$IFn$_invoke$arity$3(c,old_argv,new_argv) : f.call(null,c,old_argv,new_argv));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
break;
|
||||
case "componentWillUpdate":
|
||||
return (function (nextprops){
|
||||
var c = this;
|
||||
var G__7425 = c;
|
||||
var G__7426 = (nextprops["argv"]);
|
||||
return (f.cljs$core$IFn$_invoke$arity$2 ? f.cljs$core$IFn$_invoke$arity$2(G__7425,G__7426) : f.call(null,G__7425,G__7426));
|
||||
});
|
||||
|
||||
break;
|
||||
case "componentDidUpdate":
|
||||
return (function (oldprops){
|
||||
var c = this;
|
||||
var G__7427 = c;
|
||||
var G__7428 = (oldprops["argv"]);
|
||||
return (f.cljs$core$IFn$_invoke$arity$2 ? f.cljs$core$IFn$_invoke$arity$2(G__7427,G__7428) : f.call(null,G__7427,G__7428));
|
||||
});
|
||||
|
||||
break;
|
||||
case "componentWillMount":
|
||||
return (function (){
|
||||
var c = this;
|
||||
(c["cljsMountOrder"] = reagent.impl.batching.next_mount_count());
|
||||
|
||||
if((f == null)){
|
||||
return null;
|
||||
} else {
|
||||
return (f.cljs$core$IFn$_invoke$arity$1 ? f.cljs$core$IFn$_invoke$arity$1(c) : f.call(null,c));
|
||||
}
|
||||
});
|
||||
|
||||
break;
|
||||
case "componentWillUnmount":
|
||||
return (function (){
|
||||
var c = this;
|
||||
reagent.impl.batching.dispose(c);
|
||||
|
||||
if((f == null)){
|
||||
return null;
|
||||
} else {
|
||||
return (f.cljs$core$IFn$_invoke$arity$1 ? f.cljs$core$IFn$_invoke$arity$1(c) : f.call(null,c));
|
||||
}
|
||||
});
|
||||
|
||||
break;
|
||||
default:
|
||||
return null;
|
||||
|
||||
}
|
||||
});
|
||||
reagent.impl.component.default_wrapper = (function reagent$impl$component$default_wrapper(f){
|
||||
if(cljs.core.ifn_QMARK_(f)){
|
||||
return (function() {
|
||||
var G__7430__delegate = function (args){
|
||||
var c = this;
|
||||
return cljs.core.apply.cljs$core$IFn$_invoke$arity$3(f,c,args);
|
||||
};
|
||||
var G__7430 = function (var_args){
|
||||
var args = null;
|
||||
if (arguments.length > 0) {
|
||||
var G__7431__i = 0, G__7431__a = new Array(arguments.length - 0);
|
||||
while (G__7431__i < G__7431__a.length) {G__7431__a[G__7431__i] = arguments[G__7431__i + 0]; ++G__7431__i;}
|
||||
args = new cljs.core.IndexedSeq(G__7431__a,0,null);
|
||||
}
|
||||
return G__7430__delegate.call(this,args);};
|
||||
G__7430.cljs$lang$maxFixedArity = 0;
|
||||
G__7430.cljs$lang$applyTo = (function (arglist__7432){
|
||||
var args = cljs.core.seq(arglist__7432);
|
||||
return G__7430__delegate(args);
|
||||
});
|
||||
G__7430.cljs$core$IFn$_invoke$arity$variadic = G__7430__delegate;
|
||||
return G__7430;
|
||||
})()
|
||||
;
|
||||
} else {
|
||||
return f;
|
||||
}
|
||||
});
|
||||
reagent.impl.component.dont_wrap = new cljs.core.PersistentHashSet(null, new cljs.core.PersistentArrayMap(null, 4, [cljs.core.cst$kw$cljsRender,null,cljs.core.cst$kw$reagentRender,null,cljs.core.cst$kw$render,null,cljs.core.cst$kw$cljsName,null], null), null);
|
||||
reagent.impl.component.dont_bind = (function reagent$impl$component$dont_bind(f){
|
||||
if(cljs.core.fn_QMARK_(f)){
|
||||
var G__7433 = f;
|
||||
(G__7433["__reactDontBind"] = true);
|
||||
|
||||
return G__7433;
|
||||
} else {
|
||||
return f;
|
||||
}
|
||||
});
|
||||
reagent.impl.component.get_wrapper = (function reagent$impl$component$get_wrapper(key,f,name){
|
||||
if(cljs.core.truth_((reagent.impl.component.dont_wrap.cljs$core$IFn$_invoke$arity$1 ? reagent.impl.component.dont_wrap.cljs$core$IFn$_invoke$arity$1(key) : reagent.impl.component.dont_wrap.call(null,key)))){
|
||||
return reagent.impl.component.dont_bind(f);
|
||||
} else {
|
||||
var wrap = reagent.impl.component.custom_wrapper(key,f);
|
||||
if(cljs.core.truth_((function (){var and__5043__auto__ = wrap;
|
||||
if(cljs.core.truth_(and__5043__auto__)){
|
||||
return f;
|
||||
} else {
|
||||
return and__5043__auto__;
|
||||
}
|
||||
})())){
|
||||
if(cljs.core.ifn_QMARK_(f)){
|
||||
} else {
|
||||
throw (new Error(["Assert failed: ",["Expected function in ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(name),cljs.core.str.cljs$core$IFn$_invoke$arity$1(key)," but got ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(f)].join(''),"\n","(ifn? f)"].join('')));
|
||||
}
|
||||
} else {
|
||||
}
|
||||
|
||||
var or__5045__auto__ = wrap;
|
||||
if(cljs.core.truth_(or__5045__auto__)){
|
||||
return or__5045__auto__;
|
||||
} else {
|
||||
return reagent.impl.component.default_wrapper(f);
|
||||
}
|
||||
}
|
||||
});
|
||||
reagent.impl.component.obligatory = new cljs.core.PersistentArrayMap(null, 3, [cljs.core.cst$kw$shouldComponentUpdate,null,cljs.core.cst$kw$componentWillMount,null,cljs.core.cst$kw$componentWillUnmount,null], null);
|
||||
reagent.impl.component.dash_to_camel = reagent.impl.util.memoize_1(reagent.impl.util.dash_to_camel);
|
||||
reagent.impl.component.camelify_map_keys = (function reagent$impl$component$camelify_map_keys(fun_map){
|
||||
return cljs.core.reduce_kv((function (m,k,v){
|
||||
return cljs.core.assoc.cljs$core$IFn$_invoke$arity$3(m,cljs.core.keyword.cljs$core$IFn$_invoke$arity$1((reagent.impl.component.dash_to_camel.cljs$core$IFn$_invoke$arity$1 ? reagent.impl.component.dash_to_camel.cljs$core$IFn$_invoke$arity$1(k) : reagent.impl.component.dash_to_camel.call(null,k))),v);
|
||||
}),cljs.core.PersistentArrayMap.EMPTY,fun_map);
|
||||
});
|
||||
reagent.impl.component.add_obligatory = (function reagent$impl$component$add_obligatory(fun_map){
|
||||
return cljs.core.merge.cljs$core$IFn$_invoke$arity$variadic(cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2([reagent.impl.component.obligatory,fun_map], 0));
|
||||
});
|
||||
reagent.impl.component.add_render = (function reagent$impl$component$add_render(fun_map,render_f,name){
|
||||
var fm = cljs.core.assoc.cljs$core$IFn$_invoke$arity$variadic(fun_map,cljs.core.cst$kw$cljsRender,render_f,cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2([cljs.core.cst$kw$render,cljs.core.cst$kw$render.cljs$core$IFn$_invoke$arity$1(reagent.impl.component.static_fns)], 0));
|
||||
return cljs.core.assoc.cljs$core$IFn$_invoke$arity$3(fm,cljs.core.cst$kw$cljsName,(function (){
|
||||
return name;
|
||||
}));
|
||||
|
||||
});
|
||||
reagent.impl.component.fun_name = (function reagent$impl$component$fun_name(f){
|
||||
var or__5045__auto__ = (function (){var and__5043__auto__ = cljs.core.fn_QMARK_(f);
|
||||
if(and__5043__auto__){
|
||||
var or__5045__auto__ = (f["displayName"]);
|
||||
if(cljs.core.truth_(or__5045__auto__)){
|
||||
return or__5045__auto__;
|
||||
} else {
|
||||
return (f["name"]);
|
||||
}
|
||||
} else {
|
||||
return and__5043__auto__;
|
||||
}
|
||||
})();
|
||||
if(cljs.core.truth_(or__5045__auto__)){
|
||||
return or__5045__auto__;
|
||||
} else {
|
||||
var or__5045__auto____$1 = (function (){var and__5043__auto__ = (((!((f == null))))?(((((f.cljs$lang$protocol_mask$partition1$ & (4096))) || ((cljs.core.PROTOCOL_SENTINEL === f.cljs$core$INamed$))))?true:false):false);
|
||||
if(and__5043__auto__){
|
||||
return cljs.core.name(f);
|
||||
} else {
|
||||
return and__5043__auto__;
|
||||
}
|
||||
})();
|
||||
if(cljs.core.truth_(or__5045__auto____$1)){
|
||||
return or__5045__auto____$1;
|
||||
} else {
|
||||
var m = cljs.core.meta(f);
|
||||
if(cljs.core.map_QMARK_(m)){
|
||||
return cljs.core.cst$kw$name.cljs$core$IFn$_invoke$arity$1(m);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
reagent.impl.component.wrap_funs = (function reagent$impl$component$wrap_funs(fmap){
|
||||
var fun_map = (function (){var temp__4659__auto__ = cljs.core.cst$kw$componentFunction.cljs$core$IFn$_invoke$arity$1(fmap);
|
||||
if((temp__4659__auto__ == null)){
|
||||
return fmap;
|
||||
} else {
|
||||
var cf = temp__4659__auto__;
|
||||
return cljs.core.dissoc.cljs$core$IFn$_invoke$arity$2(cljs.core.assoc.cljs$core$IFn$_invoke$arity$3(fmap,cljs.core.cst$kw$reagentRender,cf),cljs.core.cst$kw$componentFunction);
|
||||
}
|
||||
})();
|
||||
var render_fun = (function (){var or__5045__auto__ = cljs.core.cst$kw$reagentRender.cljs$core$IFn$_invoke$arity$1(fun_map);
|
||||
if(cljs.core.truth_(or__5045__auto__)){
|
||||
return or__5045__auto__;
|
||||
} else {
|
||||
return cljs.core.cst$kw$render.cljs$core$IFn$_invoke$arity$1(fun_map);
|
||||
}
|
||||
})();
|
||||
var _ = ((cljs.core.ifn_QMARK_(render_fun))?null:(function(){throw (new Error(["Assert failed: ",["Render must be a function, not ",cljs.core.pr_str.cljs$core$IFn$_invoke$arity$variadic(cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2([render_fun], 0))].join(''),"\n","(ifn? render-fun)"].join('')))})());
|
||||
var name = cljs.core.str.cljs$core$IFn$_invoke$arity$1((function (){var or__5045__auto__ = cljs.core.cst$kw$displayName.cljs$core$IFn$_invoke$arity$1(fun_map);
|
||||
if(cljs.core.truth_(or__5045__auto__)){
|
||||
return or__5045__auto__;
|
||||
} else {
|
||||
return reagent.impl.component.fun_name(render_fun);
|
||||
}
|
||||
})());
|
||||
var name_SINGLEQUOTE_ = ((cljs.core.empty_QMARK_(name))?cljs.core.str.cljs$core$IFn$_invoke$arity$1(cljs.core.gensym.cljs$core$IFn$_invoke$arity$1("reagent")):clojure.string.replace(name,/\$/,"."));
|
||||
var fmap__$1 = reagent.impl.component.add_render(cljs.core.assoc.cljs$core$IFn$_invoke$arity$3(fun_map,cljs.core.cst$kw$displayName,name_SINGLEQUOTE_),render_fun,name_SINGLEQUOTE_);
|
||||
return cljs.core.reduce_kv((function (m,k,v){
|
||||
return cljs.core.assoc.cljs$core$IFn$_invoke$arity$3(m,k,reagent.impl.component.get_wrapper(k,v,name_SINGLEQUOTE_));
|
||||
}),cljs.core.PersistentArrayMap.EMPTY,fmap__$1);
|
||||
});
|
||||
reagent.impl.component.map_to_js = (function reagent$impl$component$map_to_js(m){
|
||||
return cljs.core.reduce_kv((function (o,k,v){
|
||||
var G__7435 = o;
|
||||
(G__7435[cljs.core.name(k)] = v);
|
||||
|
||||
return G__7435;
|
||||
}),({}),m);
|
||||
});
|
||||
reagent.impl.component.cljsify = (function reagent$impl$component$cljsify(body){
|
||||
return reagent.impl.component.map_to_js(reagent.impl.component.wrap_funs(reagent.impl.component.add_obligatory(reagent.impl.component.camelify_map_keys(body))));
|
||||
});
|
||||
reagent.impl.component.create_class = (function reagent$impl$component$create_class(body){
|
||||
if(cljs.core.map_QMARK_(body)){
|
||||
} else {
|
||||
throw (new Error("Assert failed: (map? body)"));
|
||||
}
|
||||
|
||||
var spec = reagent.impl.component.cljsify(body);
|
||||
var res = (React["createClass"])(spec);
|
||||
var f = (function() {
|
||||
var G__7436__delegate = function (args){
|
||||
if((typeof console !== 'undefined')){
|
||||
console.warn(["Warning: ","Calling the result of create-class as a function is ","deprecated in ",cljs.core.str.cljs$core$IFn$_invoke$arity$1((res["displayName"])),". Use a vector ","instead."].join(''));
|
||||
} else {
|
||||
}
|
||||
|
||||
return reagent.impl.component.as_element(cljs.core.apply.cljs$core$IFn$_invoke$arity$3(cljs.core.vector,res,args));
|
||||
};
|
||||
var G__7436 = function (var_args){
|
||||
var args = null;
|
||||
if (arguments.length > 0) {
|
||||
var G__7437__i = 0, G__7437__a = new Array(arguments.length - 0);
|
||||
while (G__7437__i < G__7437__a.length) {G__7437__a[G__7437__i] = arguments[G__7437__i + 0]; ++G__7437__i;}
|
||||
args = new cljs.core.IndexedSeq(G__7437__a,0,null);
|
||||
}
|
||||
return G__7436__delegate.call(this,args);};
|
||||
G__7436.cljs$lang$maxFixedArity = 0;
|
||||
G__7436.cljs$lang$applyTo = (function (arglist__7438){
|
||||
var args = cljs.core.seq(arglist__7438);
|
||||
return G__7436__delegate(args);
|
||||
});
|
||||
G__7436.cljs$core$IFn$_invoke$arity$variadic = G__7436__delegate;
|
||||
return G__7436;
|
||||
})()
|
||||
;
|
||||
reagent.impl.util.cache_react_class(f,res);
|
||||
|
||||
reagent.impl.util.cache_react_class(res,res);
|
||||
|
||||
return f;
|
||||
});
|
||||
reagent.impl.component.component_path = (function reagent$impl$component$component_path(c){
|
||||
var elem = (function (){var G__7439 = (function (){var or__5045__auto__ = (function (){var G__7440 = c;
|
||||
if((G__7440 == null)){
|
||||
return null;
|
||||
} else {
|
||||
return (G__7440["_reactInternalInstance"]);
|
||||
}
|
||||
})();
|
||||
if(cljs.core.truth_(or__5045__auto__)){
|
||||
return or__5045__auto__;
|
||||
} else {
|
||||
return c;
|
||||
}
|
||||
})();
|
||||
if((G__7439 == null)){
|
||||
return null;
|
||||
} else {
|
||||
return (G__7439["_currentElement"]);
|
||||
}
|
||||
})();
|
||||
var name = (function (){var G__7441 = elem;
|
||||
var G__7441__$1 = (((G__7441 == null))?null:(G__7441["type"]));
|
||||
if((G__7441__$1 == null)){
|
||||
return null;
|
||||
} else {
|
||||
return (G__7441__$1["displayName"]);
|
||||
}
|
||||
})();
|
||||
var path = (function (){var G__7442 = elem;
|
||||
var G__7442__$1 = (((G__7442 == null))?null:(G__7442["_owner"]));
|
||||
var G__7442__$2 = (((G__7442__$1 == null))?null:(reagent.impl.component.component_path.cljs$core$IFn$_invoke$arity$1 ? reagent.impl.component.component_path.cljs$core$IFn$_invoke$arity$1(G__7442__$1) : reagent.impl.component.component_path.call(null,G__7442__$1)));
|
||||
if((G__7442__$2 == null)){
|
||||
return null;
|
||||
} else {
|
||||
return [cljs.core.str.cljs$core$IFn$_invoke$arity$1(G__7442__$2)," > "].join('');
|
||||
}
|
||||
})();
|
||||
var res = [path,cljs.core.str.cljs$core$IFn$_invoke$arity$1(name)].join('');
|
||||
if(cljs.core.empty_QMARK_(res)){
|
||||
return null;
|
||||
} else {
|
||||
return res;
|
||||
}
|
||||
});
|
||||
reagent.impl.component.comp_name = (function reagent$impl$component$comp_name(){
|
||||
var c = reagent.impl.component._STAR_current_component_STAR_;
|
||||
var n = (function (){var or__5045__auto__ = reagent.impl.component.component_path(c);
|
||||
if(cljs.core.truth_(or__5045__auto__)){
|
||||
return or__5045__auto__;
|
||||
} else {
|
||||
var G__7443 = c;
|
||||
if((G__7443 == null)){
|
||||
return null;
|
||||
} else {
|
||||
return (G__7443["cljsName"])();
|
||||
}
|
||||
}
|
||||
})();
|
||||
if((!(cljs.core.empty_QMARK_(n)))){
|
||||
return [" (in ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(n),")"].join('');
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
|
||||
});
|
||||
reagent.impl.component.shallow_obj_to_map = (function reagent$impl$component$shallow_obj_to_map(o){
|
||||
return cljs.core.into.cljs$core$IFn$_invoke$arity$2(cljs.core.PersistentArrayMap.EMPTY,(function (){var iter__5523__auto__ = (function reagent$impl$component$shallow_obj_to_map_$_iter__7444(s__7445){
|
||||
return (new cljs.core.LazySeq(null,(function (){
|
||||
var s__7445__$1 = s__7445;
|
||||
while(true){
|
||||
var temp__4657__auto__ = cljs.core.seq(s__7445__$1);
|
||||
if(temp__4657__auto__){
|
||||
var s__7445__$2 = temp__4657__auto__;
|
||||
if(cljs.core.chunked_seq_QMARK_(s__7445__$2)){
|
||||
var c__5521__auto__ = cljs.core.chunk_first(s__7445__$2);
|
||||
var size__5522__auto__ = cljs.core.count(c__5521__auto__);
|
||||
var b__7447 = cljs.core.chunk_buffer(size__5522__auto__);
|
||||
if((function (){var i__7446 = (0);
|
||||
while(true){
|
||||
if((i__7446 < size__5522__auto__)){
|
||||
var k = cljs.core._nth.cljs$core$IFn$_invoke$arity$2(c__5521__auto__,i__7446);
|
||||
cljs.core.chunk_append(b__7447,new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.keyword.cljs$core$IFn$_invoke$arity$1(k),(o[k])], null));
|
||||
|
||||
var G__7448 = (i__7446 + (1));
|
||||
i__7446 = G__7448;
|
||||
continue;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
})()){
|
||||
return cljs.core.chunk_cons(cljs.core.chunk(b__7447),reagent$impl$component$shallow_obj_to_map_$_iter__7444(cljs.core.chunk_rest(s__7445__$2)));
|
||||
} else {
|
||||
return cljs.core.chunk_cons(cljs.core.chunk(b__7447),null);
|
||||
}
|
||||
} else {
|
||||
var k = cljs.core.first(s__7445__$2);
|
||||
return cljs.core.cons(new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.keyword.cljs$core$IFn$_invoke$arity$1(k),(o[k])], null),reagent$impl$component$shallow_obj_to_map_$_iter__7444(cljs.core.rest(s__7445__$2)));
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}),null,null));
|
||||
});
|
||||
return iter__5523__auto__(cljs.core.js_keys(o));
|
||||
})());
|
||||
});
|
||||
reagent.impl.component.elem_counter = (0);
|
||||
reagent.impl.component.reactify_component = (function reagent$impl$component$reactify_component(comp){
|
||||
return (React["createClass"])(({"displayName": "react-wrapper", "render": (function (){
|
||||
var this$ = this;
|
||||
return reagent.impl.component.as_element(new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [comp,cljs.core.assoc.cljs$core$IFn$_invoke$arity$3(reagent.impl.component.shallow_obj_to_map((this$["props"])),cljs.core.cst$kw$_DASH_elem_DASH_count,(reagent.impl.component.elem_counter = (reagent.impl.component.elem_counter + (1))))], null));
|
||||
})}));
|
||||
});
|
||||
Executable
+346
@@ -0,0 +1,346 @@
|
||||
(ns reagent.impl.template
|
||||
(:require [clojure.string :as string]
|
||||
[reagent.impl.util :as util :refer [is-client]]
|
||||
[reagent.impl.component :as comp]
|
||||
[reagent.impl.batching :as batch]
|
||||
[reagent.ratom :as ratom]
|
||||
[reagent.interop :refer-macros [.' .!]]
|
||||
[reagent.debug :refer-macros [dbg prn println log dev?
|
||||
warn warn-unless]]))
|
||||
|
||||
;; From Weavejester's Hiccup, via pump:
|
||||
(def ^{:doc "Regular expression that parses a CSS-style id and class
|
||||
from a tag name."}
|
||||
re-tag #"([^\s\.#]+)(?:#([^\s\.#]+))?(?:\.([^\s#]+))?")
|
||||
|
||||
(deftype NativeWrapper [comp])
|
||||
|
||||
|
||||
;;; Common utilities
|
||||
|
||||
(defn named? [x]
|
||||
(or (keyword? x)
|
||||
(symbol? x)))
|
||||
|
||||
(defn hiccup-tag? [x]
|
||||
(or (named? x)
|
||||
(string? x)))
|
||||
|
||||
(defn valid-tag? [x]
|
||||
(or (hiccup-tag? x)
|
||||
(ifn? x)
|
||||
(instance? NativeWrapper x)))
|
||||
|
||||
|
||||
;;; Props conversion
|
||||
|
||||
(def prop-name-cache #js{:class "className"
|
||||
:for "htmlFor"
|
||||
:charset "charSet"})
|
||||
|
||||
(defn obj-get [o k]
|
||||
(when (.hasOwnProperty o k)
|
||||
(aget o k)))
|
||||
|
||||
(defn cached-prop-name [k]
|
||||
(if (named? k)
|
||||
(if-some [k' (obj-get prop-name-cache (name k))]
|
||||
k'
|
||||
(aset prop-name-cache (name k)
|
||||
(util/dash-to-camel k)))
|
||||
k))
|
||||
|
||||
(defn convert-prop-value [x]
|
||||
(cond (or (string? x) (number? x) (fn? x)) x
|
||||
(named? x) (name x)
|
||||
(map? x) (reduce-kv (fn [o k v]
|
||||
(doto o
|
||||
(aset (cached-prop-name k)
|
||||
(convert-prop-value v))))
|
||||
#js{} x)
|
||||
(coll? x) (clj->js x)
|
||||
(ifn? x) (fn [& args] (apply x args))
|
||||
true (clj->js x)))
|
||||
|
||||
(defn set-id-class [props id class]
|
||||
(let [p (if (nil? props) #js{} props)]
|
||||
(when (and (some? id) (nil? (.' p :id)))
|
||||
(.! p :id id))
|
||||
(when (some? class)
|
||||
(let [old (.' p :className)]
|
||||
(.! p :className (if (some? old)
|
||||
(str class " " old)
|
||||
class))))
|
||||
p))
|
||||
|
||||
(defn convert-props [props id-class]
|
||||
(let [id (.' id-class :id)
|
||||
class (.' id-class :className)
|
||||
no-id-class (and (nil? id) (nil? class))]
|
||||
(if (and no-id-class (empty? props))
|
||||
nil
|
||||
(let [objprops (convert-prop-value props)]
|
||||
(if no-id-class
|
||||
objprops
|
||||
(set-id-class objprops id class))))))
|
||||
|
||||
|
||||
;;; Specialization for input components
|
||||
|
||||
(defn input-unmount [this]
|
||||
(.! this :cljsInputValue nil))
|
||||
|
||||
;; <input type="??" >
|
||||
;; The properites 'selectionStart' and 'selectionEnd' only exist on some inputs
|
||||
;; See: https://html.spec.whatwg.org/multipage/forms.html#do-not-apply
|
||||
(def these-inputs-have-selection-api #{"text" "textarea" "password" "search" "tel" "url"})
|
||||
|
||||
(defn has-selection-api?
|
||||
[input-type]
|
||||
(contains? these-inputs-have-selection-api input-type))
|
||||
|
||||
(defn input-set-value [this]
|
||||
(when-some [value (.' this :cljsInputValue)]
|
||||
(.! this :cljsInputDirty false)
|
||||
(let [node (.' this getDOMNode)
|
||||
node-value (.' node :value)]
|
||||
(when (not= value node-value)
|
||||
(if-not (and (identical? node (.-activeElement js/document))
|
||||
(has-selection-api? (.' node :type))
|
||||
(string? value)
|
||||
(string? node-value))
|
||||
; just set the value, no need to worry about a cursor
|
||||
(.! node :value value)
|
||||
|
||||
;; Setting "value" (below) moves the cursor position to the end which
|
||||
;; gives the user a jarring experience.
|
||||
;;
|
||||
;; But repositioning the cursor within the text, turns out
|
||||
;; to be quite a challenge because changes in the text can be
|
||||
;; triggered by various events like:
|
||||
;; - a validation function rejecting a certain user inputted char
|
||||
;; - the user enters a lower case char, but is transformed to upper.
|
||||
;; - the user selects multiple chars and deletes text
|
||||
;; - the user pastes in multiple chars, and some of them are rejected
|
||||
;; by a validator.
|
||||
;; - the user selects multiple chars and then types in a single
|
||||
;; new char to repalce them all.
|
||||
;; Coming up with a sane cursor repositioning strategy hasn't been easy
|
||||
;; ALTHOUGH in the end, it kinda fell out nicely, and it appears to sanely
|
||||
;; handle all the cases we could think of.
|
||||
;; So this is just a warning. The code below is simple enough, but if
|
||||
;; you are tempted to change it, be aware of all the scenarios you have handle.
|
||||
(let [existing-offset-from-end (- (count node-value) (.' node :selectionStart))
|
||||
new-cursor-offset (- (count value) existing-offset-from-end)]
|
||||
(.! node :value value)
|
||||
(.! node :selectionStart new-cursor-offset)
|
||||
(.! node :selectionEnd new-cursor-offset)))))))
|
||||
|
||||
(defn input-handle-change [this on-change e]
|
||||
(let [res (on-change e)]
|
||||
;; Make sure the input is re-rendered, in case on-change
|
||||
;; wants to keep the value unchanged
|
||||
(when-not (.' this :cljsInputDirty)
|
||||
(.! this :cljsInputDirty true)
|
||||
(batch/do-later #(input-set-value this)))
|
||||
res))
|
||||
|
||||
(defn input-render-setup [this jsprops]
|
||||
;; Don't rely on React for updating "controlled inputs", since it
|
||||
;; doesn't play well with async rendering (misses keystrokes).
|
||||
(if (and (.' jsprops hasOwnProperty "onChange")
|
||||
(.' jsprops hasOwnProperty "value"))
|
||||
(let [v (.' jsprops :value)
|
||||
value (if (nil? v) "" v)
|
||||
on-change (.' jsprops :onChange)]
|
||||
(.! this :cljsInputValue value)
|
||||
(js-delete jsprops "value")
|
||||
(doto jsprops
|
||||
(.! :defaultValue value)
|
||||
(.! :onChange #(input-handle-change this on-change %))))
|
||||
(.! this :cljsInputValue nil)))
|
||||
|
||||
(defn input-component? [x]
|
||||
(or (identical? x "input")
|
||||
(identical? x "textarea")))
|
||||
|
||||
(def reagent-input-class nil)
|
||||
|
||||
(declare make-element)
|
||||
|
||||
(def input-spec
|
||||
{:display-name "ReagentInput"
|
||||
:component-did-update input-set-value
|
||||
:component-will-unmount input-unmount
|
||||
:reagent-render
|
||||
(fn [argv comp jsprops first-child]
|
||||
(let [this comp/*current-component*]
|
||||
(input-render-setup this jsprops)
|
||||
(make-element argv comp jsprops first-child)))})
|
||||
|
||||
(defn reagent-input []
|
||||
(when (nil? reagent-input-class)
|
||||
(set! reagent-input-class (comp/create-class input-spec)))
|
||||
reagent-input-class)
|
||||
|
||||
|
||||
;;; Conversion from Hiccup forms
|
||||
|
||||
(defn parse-tag [hiccup-tag]
|
||||
(let [[tag id class] (->> hiccup-tag name (re-matches re-tag) next)
|
||||
class' (when class
|
||||
(string/replace class #"\." " "))]
|
||||
(assert tag (str "Invalid tag: '" hiccup-tag "'"
|
||||
(comp/comp-name)))
|
||||
#js{:name tag
|
||||
:id id
|
||||
:className class'}))
|
||||
|
||||
(defn fn-to-class [f]
|
||||
(assert (ifn? f) (str "Expected a function, not " (pr-str f)))
|
||||
(warn-unless (not (and (fn? f)
|
||||
(some? (.' f :type))))
|
||||
"Using native React classes directly in Hiccup forms "
|
||||
"is not supported. Use create-element or "
|
||||
"adapt-react-class instead: " (.' f :type)
|
||||
(comp/comp-name))
|
||||
(let [spec (meta f)
|
||||
withrender (assoc spec :reagent-render f)
|
||||
res (comp/create-class withrender)
|
||||
wrapf (util/cached-react-class res)]
|
||||
(util/cache-react-class f wrapf)
|
||||
wrapf))
|
||||
|
||||
(defn as-class [tag]
|
||||
(if-some [cached-class (util/cached-react-class tag)]
|
||||
cached-class
|
||||
(fn-to-class tag)))
|
||||
|
||||
(defn get-key [x]
|
||||
(when (map? x)
|
||||
;; try catch to avoid clojurescript peculiarity with
|
||||
;; sorted-maps with keys that are numbers
|
||||
(try (get x :key)
|
||||
(catch :default e))))
|
||||
|
||||
(defn key-from-vec [v]
|
||||
(if-some [k (some-> (meta v) get-key)]
|
||||
k
|
||||
(-> v (nth 1 nil) get-key)))
|
||||
|
||||
(defn reag-element [tag v]
|
||||
(let [c (as-class tag)
|
||||
jsprops #js{:argv v}]
|
||||
(some->> v key-from-vec (.! jsprops :key))
|
||||
(.' js/React createElement c jsprops)))
|
||||
|
||||
(defn adapt-react-class [c]
|
||||
(NativeWrapper. #js{:name c
|
||||
:id nil
|
||||
:class nil}))
|
||||
|
||||
(def tag-name-cache #js{})
|
||||
|
||||
(defn cached-parse [x]
|
||||
(if-some [s (obj-get tag-name-cache x)]
|
||||
s
|
||||
(aset tag-name-cache x (parse-tag x))))
|
||||
|
||||
(declare as-element)
|
||||
|
||||
(defn native-element [parsed argv]
|
||||
(let [comp (.' parsed :name)]
|
||||
(let [props (nth argv 1 nil)
|
||||
hasprops (or (nil? props) (map? props))
|
||||
jsprops (convert-props (if hasprops props) parsed)
|
||||
first-child (if hasprops 2 1)]
|
||||
(if (input-component? comp)
|
||||
(-> [(reagent-input) argv comp jsprops first-child]
|
||||
(with-meta (meta argv))
|
||||
as-element)
|
||||
(let [p (if-some [key (some-> (meta argv) get-key)]
|
||||
(doto (if (nil? jsprops) #js{} jsprops)
|
||||
(.! :key key))
|
||||
jsprops)]
|
||||
(make-element argv comp p first-child))))))
|
||||
|
||||
(defn vec-to-elem [v]
|
||||
(assert (pos? (count v))
|
||||
(str "Hiccup form should not be empty: "
|
||||
(pr-str v) (comp/comp-name)))
|
||||
(let [tag (nth v 0)]
|
||||
(assert (valid-tag? tag)
|
||||
(str "Invalid Hiccup form: "
|
||||
(pr-str v) (comp/comp-name)))
|
||||
(cond
|
||||
(hiccup-tag? tag)
|
||||
(let [n (name tag)
|
||||
pos (.indexOf n ">")]
|
||||
(if (== pos -1)
|
||||
(native-element (cached-parse n) v)
|
||||
;; Support extended hiccup syntax, i.e :div.bar>a.foo
|
||||
(recur [(subs n 0 pos)
|
||||
(assoc v 0 (subs n (inc pos)))])))
|
||||
|
||||
(instance? NativeWrapper tag)
|
||||
(native-element (.-comp tag) v)
|
||||
|
||||
:else (reag-element tag v))))
|
||||
|
||||
(declare expand-seq)
|
||||
(declare expand-seq-check)
|
||||
|
||||
(defn as-element [x]
|
||||
(cond (string? x) x
|
||||
(vector? x) (vec-to-elem x)
|
||||
(seq? x) (if (dev?)
|
||||
(expand-seq-check x)
|
||||
(expand-seq x))
|
||||
true x))
|
||||
|
||||
(defn expand-seq [s]
|
||||
(let [a (into-array s)]
|
||||
(dotimes [i (alength a)]
|
||||
(aset a i (as-element (aget a i))))
|
||||
a))
|
||||
|
||||
(defn expand-seq-dev [s o]
|
||||
(let [a (into-array s)]
|
||||
(dotimes [i (alength a)]
|
||||
(let [val (aget a i)]
|
||||
(when (and (vector? val)
|
||||
(nil? (key-from-vec val)))
|
||||
(.! o :no-key true))
|
||||
(aset a i (as-element val))))
|
||||
a))
|
||||
|
||||
(defn expand-seq-check [x]
|
||||
(let [ctx #js{}
|
||||
res (if (nil? ratom/*ratom-context*)
|
||||
(expand-seq-dev x ctx)
|
||||
(ratom/capture-derefed #(expand-seq-dev x ctx)
|
||||
ctx))]
|
||||
(when (ratom/captured ctx)
|
||||
(warn "Reactive deref not supported in lazy seq, "
|
||||
"it should be wrapped in doall"
|
||||
(comp/comp-name) ". Value:\n" (pr-str x)))
|
||||
(when (and (not comp/*non-reactive*)
|
||||
(.' ctx :no-key))
|
||||
(warn "Every element in a seq should have a unique "
|
||||
":key" (comp/comp-name) ". Value: " (pr-str x)))
|
||||
res))
|
||||
|
||||
(defn make-element [argv comp jsprops first-child]
|
||||
(case (- (count argv) first-child)
|
||||
;; Optimize cases of zero or one child
|
||||
0 (.' js/React createElement comp jsprops)
|
||||
|
||||
1 (.' js/React createElement comp jsprops
|
||||
(as-element (nth argv first-child)))
|
||||
|
||||
(.apply (.' js/React :createElement) nil
|
||||
(reduce-kv (fn [a k v]
|
||||
(when (>= k first-child)
|
||||
(.push a (as-element v)))
|
||||
a)
|
||||
#js[comp jsprops] argv))))
|
||||
Executable
+509
@@ -0,0 +1,509 @@
|
||||
// Compiled by ClojureScript 1.11.60 {:static-fns true, :optimize-constants true, :optimizations :advanced}
|
||||
goog.provide('reagent.impl.template');
|
||||
goog.require('cljs.core');
|
||||
goog.require('cljs.core.constants');
|
||||
goog.require('clojure.string');
|
||||
goog.require('reagent.impl.util');
|
||||
goog.require('reagent.impl.component');
|
||||
goog.require('reagent.impl.batching');
|
||||
goog.require('reagent.ratom');
|
||||
goog.require('reagent.interop');
|
||||
goog.require('reagent.debug');
|
||||
/**
|
||||
* Regular expression that parses a CSS-style id and class
|
||||
* from a tag name.
|
||||
*/
|
||||
reagent.impl.template.re_tag = /([^\s\.#]+)(?:#([^\s\.#]+))?(?:\.([^\s#]+))?/;
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*/
|
||||
reagent.impl.template.NativeWrapper = (function (comp){
|
||||
this.comp = comp;
|
||||
});
|
||||
|
||||
(reagent.impl.template.NativeWrapper.getBasis = (function (){
|
||||
return new cljs.core.PersistentVector(null, 1, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.cst$sym$comp], null);
|
||||
}));
|
||||
|
||||
(reagent.impl.template.NativeWrapper.cljs$lang$type = true);
|
||||
|
||||
(reagent.impl.template.NativeWrapper.cljs$lang$ctorStr = "reagent.impl.template/NativeWrapper");
|
||||
|
||||
(reagent.impl.template.NativeWrapper.cljs$lang$ctorPrWriter = (function (this__5330__auto__,writer__5331__auto__,opt__5332__auto__){
|
||||
return cljs.core._write(writer__5331__auto__,"reagent.impl.template/NativeWrapper");
|
||||
}));
|
||||
|
||||
/**
|
||||
* Positional factory function for reagent.impl.template/NativeWrapper.
|
||||
*/
|
||||
reagent.impl.template.__GT_NativeWrapper = (function reagent$impl$template$__GT_NativeWrapper(comp){
|
||||
return (new reagent.impl.template.NativeWrapper(comp));
|
||||
});
|
||||
|
||||
reagent.impl.template.named_QMARK_ = (function reagent$impl$template$named_QMARK_(x){
|
||||
return (((x instanceof cljs.core.Keyword)) || ((x instanceof cljs.core.Symbol)));
|
||||
});
|
||||
reagent.impl.template.hiccup_tag_QMARK_ = (function reagent$impl$template$hiccup_tag_QMARK_(x){
|
||||
return ((reagent.impl.template.named_QMARK_(x)) || (typeof x === 'string'));
|
||||
});
|
||||
reagent.impl.template.valid_tag_QMARK_ = (function reagent$impl$template$valid_tag_QMARK_(x){
|
||||
return ((reagent.impl.template.hiccup_tag_QMARK_(x)) || (((cljs.core.ifn_QMARK_(x)) || ((x instanceof reagent.impl.template.NativeWrapper)))));
|
||||
});
|
||||
reagent.impl.template.prop_name_cache = ({"class": "className", "for": "htmlFor", "charset": "charSet"});
|
||||
reagent.impl.template.obj_get = (function reagent$impl$template$obj_get(o,k){
|
||||
if(cljs.core.truth_(o.hasOwnProperty(k))){
|
||||
return (o[k]);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
reagent.impl.template.cached_prop_name = (function reagent$impl$template$cached_prop_name(k){
|
||||
if(reagent.impl.template.named_QMARK_(k)){
|
||||
var temp__4659__auto__ = reagent.impl.template.obj_get(reagent.impl.template.prop_name_cache,cljs.core.name(k));
|
||||
if((temp__4659__auto__ == null)){
|
||||
return (reagent.impl.template.prop_name_cache[cljs.core.name(k)] = reagent.impl.util.dash_to_camel(k));
|
||||
} else {
|
||||
var k_SINGLEQUOTE_ = temp__4659__auto__;
|
||||
return k_SINGLEQUOTE_;
|
||||
}
|
||||
} else {
|
||||
return k;
|
||||
}
|
||||
});
|
||||
reagent.impl.template.convert_prop_value = (function reagent$impl$template$convert_prop_value(x){
|
||||
if(((typeof x === 'string') || (((typeof x === 'number') || (cljs.core.fn_QMARK_(x)))))){
|
||||
return x;
|
||||
} else {
|
||||
if(reagent.impl.template.named_QMARK_(x)){
|
||||
return cljs.core.name(x);
|
||||
} else {
|
||||
if(cljs.core.map_QMARK_(x)){
|
||||
return cljs.core.reduce_kv((function (o,k,v){
|
||||
var G__7451 = o;
|
||||
(G__7451[reagent.impl.template.cached_prop_name(k)] = (reagent.impl.template.convert_prop_value.cljs$core$IFn$_invoke$arity$1 ? reagent.impl.template.convert_prop_value.cljs$core$IFn$_invoke$arity$1(v) : reagent.impl.template.convert_prop_value.call(null,v)));
|
||||
|
||||
return G__7451;
|
||||
}),({}),x);
|
||||
} else {
|
||||
if(cljs.core.coll_QMARK_(x)){
|
||||
return cljs.core.clj__GT_js(x);
|
||||
} else {
|
||||
if(cljs.core.ifn_QMARK_(x)){
|
||||
return (function() {
|
||||
var G__7452__delegate = function (args){
|
||||
return cljs.core.apply.cljs$core$IFn$_invoke$arity$2(x,args);
|
||||
};
|
||||
var G__7452 = function (var_args){
|
||||
var args = null;
|
||||
if (arguments.length > 0) {
|
||||
var G__7453__i = 0, G__7453__a = new Array(arguments.length - 0);
|
||||
while (G__7453__i < G__7453__a.length) {G__7453__a[G__7453__i] = arguments[G__7453__i + 0]; ++G__7453__i;}
|
||||
args = new cljs.core.IndexedSeq(G__7453__a,0,null);
|
||||
}
|
||||
return G__7452__delegate.call(this,args);};
|
||||
G__7452.cljs$lang$maxFixedArity = 0;
|
||||
G__7452.cljs$lang$applyTo = (function (arglist__7454){
|
||||
var args = cljs.core.seq(arglist__7454);
|
||||
return G__7452__delegate(args);
|
||||
});
|
||||
G__7452.cljs$core$IFn$_invoke$arity$variadic = G__7452__delegate;
|
||||
return G__7452;
|
||||
})()
|
||||
;
|
||||
} else {
|
||||
return cljs.core.clj__GT_js(x);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
reagent.impl.template.set_id_class = (function reagent$impl$template$set_id_class(props,id,class$){
|
||||
var p = (((props == null))?({}):props);
|
||||
if((((!((id == null)))) && (((p["id"]) == null)))){
|
||||
(p["id"] = id);
|
||||
} else {
|
||||
}
|
||||
|
||||
if((!((class$ == null)))){
|
||||
var old_7455 = (p["className"]);
|
||||
(p["className"] = (((!((old_7455 == null))))?[cljs.core.str.cljs$core$IFn$_invoke$arity$1(class$)," ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(old_7455)].join(''):class$));
|
||||
} else {
|
||||
}
|
||||
|
||||
return p;
|
||||
});
|
||||
reagent.impl.template.convert_props = (function reagent$impl$template$convert_props(props,id_class){
|
||||
var id = (id_class["id"]);
|
||||
var class$ = (id_class["className"]);
|
||||
var no_id_class = (((id == null)) && ((class$ == null)));
|
||||
if(((no_id_class) && (cljs.core.empty_QMARK_(props)))){
|
||||
return null;
|
||||
} else {
|
||||
var objprops = reagent.impl.template.convert_prop_value(props);
|
||||
if(no_id_class){
|
||||
return objprops;
|
||||
} else {
|
||||
return reagent.impl.template.set_id_class(objprops,id,class$);
|
||||
}
|
||||
}
|
||||
});
|
||||
reagent.impl.template.input_unmount = (function reagent$impl$template$input_unmount(this$){
|
||||
return (this$["cljsInputValue"] = null);
|
||||
});
|
||||
reagent.impl.template.these_inputs_have_selection_api = new cljs.core.PersistentHashSet(null, new cljs.core.PersistentArrayMap(null, 6, ["url",null,"tel",null,"text",null,"textarea",null,"password",null,"search",null], null), null);
|
||||
reagent.impl.template.has_selection_api_QMARK_ = (function reagent$impl$template$has_selection_api_QMARK_(input_type){
|
||||
return cljs.core.contains_QMARK_(reagent.impl.template.these_inputs_have_selection_api,input_type);
|
||||
});
|
||||
reagent.impl.template.input_set_value = (function reagent$impl$template$input_set_value(this$){
|
||||
var temp__4661__auto__ = (this$["cljsInputValue"]);
|
||||
if((temp__4661__auto__ == null)){
|
||||
return null;
|
||||
} else {
|
||||
var value = temp__4661__auto__;
|
||||
(this$["cljsInputDirty"] = false);
|
||||
|
||||
var node = (this$["getDOMNode"])();
|
||||
var node_value = (node["value"]);
|
||||
if(cljs.core.not_EQ_.cljs$core$IFn$_invoke$arity$2(value,node_value)){
|
||||
if((!((((node === document.activeElement)) && (((reagent.impl.template.has_selection_api_QMARK_((node["type"]))) && (((typeof value === 'string') && (typeof node_value === 'string'))))))))){
|
||||
return (node["value"] = value);
|
||||
} else {
|
||||
var existing_offset_from_end = (cljs.core.count(node_value) - (node["selectionStart"]));
|
||||
var new_cursor_offset = (cljs.core.count(value) - existing_offset_from_end);
|
||||
(node["value"] = value);
|
||||
|
||||
(node["selectionStart"] = new_cursor_offset);
|
||||
|
||||
return (node["selectionEnd"] = new_cursor_offset);
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
});
|
||||
reagent.impl.template.input_handle_change = (function reagent$impl$template$input_handle_change(this$,on_change,e){
|
||||
var res = (on_change.cljs$core$IFn$_invoke$arity$1 ? on_change.cljs$core$IFn$_invoke$arity$1(e) : on_change.call(null,e));
|
||||
if(cljs.core.truth_((this$["cljsInputDirty"]))){
|
||||
} else {
|
||||
(this$["cljsInputDirty"] = true);
|
||||
|
||||
reagent.impl.batching.do_later((function (){
|
||||
return reagent.impl.template.input_set_value(this$);
|
||||
}));
|
||||
}
|
||||
|
||||
return res;
|
||||
});
|
||||
reagent.impl.template.input_render_setup = (function reagent$impl$template$input_render_setup(this$,jsprops){
|
||||
if(cljs.core.truth_((function (){var and__5043__auto__ = (jsprops["hasOwnProperty"])("onChange");
|
||||
if(cljs.core.truth_(and__5043__auto__)){
|
||||
return (jsprops["hasOwnProperty"])("value");
|
||||
} else {
|
||||
return and__5043__auto__;
|
||||
}
|
||||
})())){
|
||||
var v = (jsprops["value"]);
|
||||
var value = (((v == null))?"":v);
|
||||
var on_change = (jsprops["onChange"]);
|
||||
(this$["cljsInputValue"] = value);
|
||||
|
||||
delete jsprops["value"];
|
||||
|
||||
var G__7457 = jsprops;
|
||||
(G__7457["defaultValue"] = value);
|
||||
|
||||
(G__7457["onChange"] = (function (p1__7456_SHARP_){
|
||||
return reagent.impl.template.input_handle_change(this$,on_change,p1__7456_SHARP_);
|
||||
}));
|
||||
|
||||
return G__7457;
|
||||
} else {
|
||||
return (this$["cljsInputValue"] = null);
|
||||
}
|
||||
});
|
||||
reagent.impl.template.input_component_QMARK_ = (function reagent$impl$template$input_component_QMARK_(x){
|
||||
return (((x === "input")) || ((x === "textarea")));
|
||||
});
|
||||
reagent.impl.template.reagent_input_class = null;
|
||||
reagent.impl.template.input_spec = new cljs.core.PersistentArrayMap(null, 4, [cljs.core.cst$kw$display_DASH_name,"ReagentInput",cljs.core.cst$kw$component_DASH_did_DASH_update,reagent.impl.template.input_set_value,cljs.core.cst$kw$component_DASH_will_DASH_unmount,reagent.impl.template.input_unmount,cljs.core.cst$kw$reagent_DASH_render,(function (argv,comp,jsprops,first_child){
|
||||
var this$ = reagent.impl.component._STAR_current_component_STAR_;
|
||||
reagent.impl.template.input_render_setup(this$,jsprops);
|
||||
|
||||
return (reagent.impl.template.make_element.cljs$core$IFn$_invoke$arity$4 ? reagent.impl.template.make_element.cljs$core$IFn$_invoke$arity$4(argv,comp,jsprops,first_child) : reagent.impl.template.make_element.call(null,argv,comp,jsprops,first_child));
|
||||
})], null);
|
||||
reagent.impl.template.reagent_input = (function reagent$impl$template$reagent_input(){
|
||||
if((reagent.impl.template.reagent_input_class == null)){
|
||||
(reagent.impl.template.reagent_input_class = reagent.impl.component.create_class(reagent.impl.template.input_spec));
|
||||
} else {
|
||||
}
|
||||
|
||||
return reagent.impl.template.reagent_input_class;
|
||||
});
|
||||
reagent.impl.template.parse_tag = (function reagent$impl$template$parse_tag(hiccup_tag){
|
||||
var vec__7458 = cljs.core.next(cljs.core.re_matches(reagent.impl.template.re_tag,cljs.core.name(hiccup_tag)));
|
||||
var tag = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__7458,(0),null);
|
||||
var id = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__7458,(1),null);
|
||||
var class$ = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__7458,(2),null);
|
||||
var class_SINGLEQUOTE_ = (cljs.core.truth_(class$)?clojure.string.replace(class$,/\./," "):null);
|
||||
if(cljs.core.truth_(tag)){
|
||||
} else {
|
||||
throw (new Error(["Assert failed: ",["Invalid tag: '",cljs.core.str.cljs$core$IFn$_invoke$arity$1(hiccup_tag),"'",reagent.impl.component.comp_name()].join(''),"\n","tag"].join('')));
|
||||
}
|
||||
|
||||
return ({"name": tag, "id": id, "className": class_SINGLEQUOTE_});
|
||||
});
|
||||
reagent.impl.template.fn_to_class = (function reagent$impl$template$fn_to_class(f){
|
||||
if(cljs.core.ifn_QMARK_(f)){
|
||||
} else {
|
||||
throw (new Error(["Assert failed: ",["Expected a function, not ",cljs.core.pr_str.cljs$core$IFn$_invoke$arity$variadic(cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2([f], 0))].join(''),"\n","(ifn? f)"].join('')));
|
||||
}
|
||||
|
||||
if((((!((!(((cljs.core.fn_QMARK_(f)) && ((!(((f["type"]) == null)))))))))) && ((typeof console !== 'undefined')))){
|
||||
console.warn(["Warning: ","Using native React classes directly in Hiccup forms ","is not supported. Use create-element or ","adapt-react-class instead: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1((f["type"])),reagent.impl.component.comp_name()].join(''));
|
||||
} else {
|
||||
}
|
||||
|
||||
var spec = cljs.core.meta(f);
|
||||
var withrender = cljs.core.assoc.cljs$core$IFn$_invoke$arity$3(spec,cljs.core.cst$kw$reagent_DASH_render,f);
|
||||
var res = reagent.impl.component.create_class(withrender);
|
||||
var wrapf = reagent.impl.util.cached_react_class(res);
|
||||
reagent.impl.util.cache_react_class(f,wrapf);
|
||||
|
||||
return wrapf;
|
||||
});
|
||||
reagent.impl.template.as_class = (function reagent$impl$template$as_class(tag){
|
||||
var temp__4659__auto__ = reagent.impl.util.cached_react_class(tag);
|
||||
if((temp__4659__auto__ == null)){
|
||||
return reagent.impl.template.fn_to_class(tag);
|
||||
} else {
|
||||
var cached_class = temp__4659__auto__;
|
||||
return cached_class;
|
||||
}
|
||||
});
|
||||
reagent.impl.template.get_key = (function reagent$impl$template$get_key(x){
|
||||
if(cljs.core.map_QMARK_(x)){
|
||||
try{return cljs.core.get.cljs$core$IFn$_invoke$arity$2(x,cljs.core.cst$kw$key);
|
||||
}catch (e7461){var e = e7461;
|
||||
return null;
|
||||
}} else {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
reagent.impl.template.key_from_vec = (function reagent$impl$template$key_from_vec(v){
|
||||
var temp__4659__auto__ = (function (){var G__7462 = cljs.core.meta(v);
|
||||
if((G__7462 == null)){
|
||||
return null;
|
||||
} else {
|
||||
return reagent.impl.template.get_key(G__7462);
|
||||
}
|
||||
})();
|
||||
if((temp__4659__auto__ == null)){
|
||||
return reagent.impl.template.get_key(cljs.core.nth.cljs$core$IFn$_invoke$arity$3(v,(1),null));
|
||||
} else {
|
||||
var k = temp__4659__auto__;
|
||||
return k;
|
||||
}
|
||||
});
|
||||
reagent.impl.template.reag_element = (function reagent$impl$template$reag_element(tag,v){
|
||||
var c = reagent.impl.template.as_class(tag);
|
||||
var jsprops = ({"argv": v});
|
||||
var G__7463_7464 = v;
|
||||
var G__7463_7465__$1 = (((G__7463_7464 == null))?null:reagent.impl.template.key_from_vec(G__7463_7464));
|
||||
if((G__7463_7465__$1 == null)){
|
||||
} else {
|
||||
(jsprops["key"] = G__7463_7465__$1);
|
||||
}
|
||||
|
||||
return (React["createElement"])(c,jsprops);
|
||||
});
|
||||
reagent.impl.template.adapt_react_class = (function reagent$impl$template$adapt_react_class(c){
|
||||
return (new reagent.impl.template.NativeWrapper(({"name": c, "id": null, "class": null})));
|
||||
});
|
||||
reagent.impl.template.tag_name_cache = ({});
|
||||
reagent.impl.template.cached_parse = (function reagent$impl$template$cached_parse(x){
|
||||
var temp__4659__auto__ = reagent.impl.template.obj_get(reagent.impl.template.tag_name_cache,x);
|
||||
if((temp__4659__auto__ == null)){
|
||||
return (reagent.impl.template.tag_name_cache[x] = reagent.impl.template.parse_tag(x));
|
||||
} else {
|
||||
var s = temp__4659__auto__;
|
||||
return s;
|
||||
}
|
||||
});
|
||||
reagent.impl.template.native_element = (function reagent$impl$template$native_element(parsed,argv){
|
||||
var comp = (parsed["name"]);
|
||||
var props = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(argv,(1),null);
|
||||
var hasprops = (((props == null)) || (cljs.core.map_QMARK_(props)));
|
||||
var jsprops = reagent.impl.template.convert_props(((hasprops)?props:null),parsed);
|
||||
var first_child = ((hasprops)?(2):(1));
|
||||
if(reagent.impl.template.input_component_QMARK_(comp)){
|
||||
var G__7466 = cljs.core.with_meta(new cljs.core.PersistentVector(null, 5, 5, cljs.core.PersistentVector.EMPTY_NODE, [reagent.impl.template.reagent_input(),argv,comp,jsprops,first_child], null),cljs.core.meta(argv));
|
||||
return (reagent.impl.template.as_element.cljs$core$IFn$_invoke$arity$1 ? reagent.impl.template.as_element.cljs$core$IFn$_invoke$arity$1(G__7466) : reagent.impl.template.as_element.call(null,G__7466));
|
||||
} else {
|
||||
var p = (function (){var temp__4659__auto__ = (function (){var G__7467 = cljs.core.meta(argv);
|
||||
if((G__7467 == null)){
|
||||
return null;
|
||||
} else {
|
||||
return reagent.impl.template.get_key(G__7467);
|
||||
}
|
||||
})();
|
||||
if((temp__4659__auto__ == null)){
|
||||
return jsprops;
|
||||
} else {
|
||||
var key = temp__4659__auto__;
|
||||
var G__7468 = (((jsprops == null))?({}):jsprops);
|
||||
(G__7468["key"] = key);
|
||||
|
||||
return G__7468;
|
||||
}
|
||||
})();
|
||||
return (reagent.impl.template.make_element.cljs$core$IFn$_invoke$arity$4 ? reagent.impl.template.make_element.cljs$core$IFn$_invoke$arity$4(argv,comp,p,first_child) : reagent.impl.template.make_element.call(null,argv,comp,p,first_child));
|
||||
}
|
||||
});
|
||||
reagent.impl.template.vec_to_elem = (function reagent$impl$template$vec_to_elem(v){
|
||||
while(true){
|
||||
if((cljs.core.count(v) > (0))){
|
||||
} else {
|
||||
throw (new Error(["Assert failed: ",["Hiccup form should not be empty: ",cljs.core.pr_str.cljs$core$IFn$_invoke$arity$variadic(cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2([v], 0)),reagent.impl.component.comp_name()].join(''),"\n","(pos? (count v))"].join('')));
|
||||
}
|
||||
|
||||
var tag = cljs.core.nth.cljs$core$IFn$_invoke$arity$2(v,(0));
|
||||
if(reagent.impl.template.valid_tag_QMARK_(tag)){
|
||||
} else {
|
||||
throw (new Error(["Assert failed: ",["Invalid Hiccup form: ",cljs.core.pr_str.cljs$core$IFn$_invoke$arity$variadic(cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2([v], 0)),reagent.impl.component.comp_name()].join(''),"\n","(valid-tag? tag)"].join('')));
|
||||
}
|
||||
|
||||
if(reagent.impl.template.hiccup_tag_QMARK_(tag)){
|
||||
var n = cljs.core.name(tag);
|
||||
var pos = n.indexOf(">");
|
||||
if((pos === (-1))){
|
||||
return reagent.impl.template.native_element(reagent.impl.template.cached_parse(n),v);
|
||||
} else {
|
||||
var G__7469 = new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.subs.cljs$core$IFn$_invoke$arity$3(n,(0),pos),cljs.core.assoc.cljs$core$IFn$_invoke$arity$3(v,(0),cljs.core.subs.cljs$core$IFn$_invoke$arity$2(n,(pos + (1))))], null);
|
||||
v = G__7469;
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
if((tag instanceof reagent.impl.template.NativeWrapper)){
|
||||
return reagent.impl.template.native_element(tag.comp,v);
|
||||
} else {
|
||||
return reagent.impl.template.reag_element(tag,v);
|
||||
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
});
|
||||
reagent.impl.template.as_element = (function reagent$impl$template$as_element(x){
|
||||
if(typeof x === 'string'){
|
||||
return x;
|
||||
} else {
|
||||
if(cljs.core.vector_QMARK_(x)){
|
||||
return reagent.impl.template.vec_to_elem(x);
|
||||
} else {
|
||||
if(cljs.core.seq_QMARK_(x)){
|
||||
return (reagent.impl.template.expand_seq_check.cljs$core$IFn$_invoke$arity$1 ? reagent.impl.template.expand_seq_check.cljs$core$IFn$_invoke$arity$1(x) : reagent.impl.template.expand_seq_check.call(null,x));
|
||||
|
||||
} else {
|
||||
return x;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
reagent.impl.template.expand_seq = (function reagent$impl$template$expand_seq(s){
|
||||
var a = cljs.core.into_array.cljs$core$IFn$_invoke$arity$1(s);
|
||||
var n__5636__auto___7470 = a.length;
|
||||
var i_7471 = (0);
|
||||
while(true){
|
||||
if((i_7471 < n__5636__auto___7470)){
|
||||
(a[i_7471] = reagent.impl.template.as_element((a[i_7471])));
|
||||
|
||||
var G__7472 = (i_7471 + (1));
|
||||
i_7471 = G__7472;
|
||||
continue;
|
||||
} else {
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return a;
|
||||
});
|
||||
reagent.impl.template.expand_seq_dev = (function reagent$impl$template$expand_seq_dev(s,o){
|
||||
var a = cljs.core.into_array.cljs$core$IFn$_invoke$arity$1(s);
|
||||
var n__5636__auto___7473 = a.length;
|
||||
var i_7474 = (0);
|
||||
while(true){
|
||||
if((i_7474 < n__5636__auto___7473)){
|
||||
var val_7475 = (a[i_7474]);
|
||||
if(((cljs.core.vector_QMARK_(val_7475)) && ((reagent.impl.template.key_from_vec(val_7475) == null)))){
|
||||
(o["no-key"] = true);
|
||||
} else {
|
||||
}
|
||||
|
||||
(a[i_7474] = reagent.impl.template.as_element(val_7475));
|
||||
|
||||
var G__7476 = (i_7474 + (1));
|
||||
i_7474 = G__7476;
|
||||
continue;
|
||||
} else {
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return a;
|
||||
});
|
||||
reagent.impl.template.expand_seq_check = (function reagent$impl$template$expand_seq_check(x){
|
||||
var ctx = ({});
|
||||
var res = (((reagent.ratom._STAR_ratom_context_STAR_ == null))?reagent.impl.template.expand_seq_dev(x,ctx):reagent.ratom.capture_derefed((function (){
|
||||
return reagent.impl.template.expand_seq_dev(x,ctx);
|
||||
}),ctx));
|
||||
if(cljs.core.truth_(reagent.ratom.captured(ctx))){
|
||||
if((typeof console !== 'undefined')){
|
||||
console.warn(["Warning: ","Reactive deref not supported in lazy seq, ","it should be wrapped in doall",reagent.impl.component.comp_name(),". Value:\n",cljs.core.pr_str.cljs$core$IFn$_invoke$arity$variadic(cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2([x], 0))].join(''));
|
||||
} else {
|
||||
}
|
||||
} else {
|
||||
}
|
||||
|
||||
if(cljs.core.truth_((function (){var and__5043__auto__ = cljs.core.not(reagent.impl.component._STAR_non_reactive_STAR_);
|
||||
if(and__5043__auto__){
|
||||
return (ctx["no-key"]);
|
||||
} else {
|
||||
return and__5043__auto__;
|
||||
}
|
||||
})())){
|
||||
if((typeof console !== 'undefined')){
|
||||
console.warn(["Warning: ","Every element in a seq should have a unique ",":key",reagent.impl.component.comp_name(),". Value: ",cljs.core.pr_str.cljs$core$IFn$_invoke$arity$variadic(cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2([x], 0))].join(''));
|
||||
} else {
|
||||
}
|
||||
} else {
|
||||
}
|
||||
|
||||
return res;
|
||||
});
|
||||
reagent.impl.template.make_element = (function reagent$impl$template$make_element(argv,comp,jsprops,first_child){
|
||||
var G__7477 = (cljs.core.count(argv) - first_child);
|
||||
switch (G__7477) {
|
||||
case (0):
|
||||
return (React["createElement"])(comp,jsprops);
|
||||
|
||||
break;
|
||||
case (1):
|
||||
return (React["createElement"])(comp,jsprops,reagent.impl.template.as_element(cljs.core.nth.cljs$core$IFn$_invoke$arity$2(argv,first_child)));
|
||||
|
||||
break;
|
||||
default:
|
||||
return (React["createElement"]).apply(null,cljs.core.reduce_kv((function (a,k,v){
|
||||
if((k >= first_child)){
|
||||
a.push(reagent.impl.template.as_element(v));
|
||||
} else {
|
||||
}
|
||||
|
||||
return a;
|
||||
}),[comp,jsprops],argv));
|
||||
|
||||
}
|
||||
});
|
||||
Executable
+144
@@ -0,0 +1,144 @@
|
||||
(ns reagent.impl.util
|
||||
(:require [reagent.debug :refer-macros [dbg log warn]]
|
||||
[reagent.interop :refer-macros [.' .!]]
|
||||
[clojure.string :as string]))
|
||||
|
||||
(def is-client (and (exists? js/window)
|
||||
(-> js/window (.' :document) nil? not)))
|
||||
|
||||
;;; Props accessors
|
||||
|
||||
(defn extract-props [v]
|
||||
(let [p (nth v 1 nil)]
|
||||
(if (map? p) p)))
|
||||
|
||||
(defn extract-children [v]
|
||||
(let [p (nth v 1 nil)
|
||||
first-child (if (or (nil? p) (map? p)) 2 1)]
|
||||
(if (> (count v) first-child)
|
||||
(subvec v first-child))))
|
||||
|
||||
(defn get-argv [c]
|
||||
(.' c :props.argv))
|
||||
|
||||
(defn get-props [c]
|
||||
(-> (.' c :props.argv) extract-props))
|
||||
|
||||
(defn get-children [c]
|
||||
(-> (.' c :props.argv) extract-children))
|
||||
|
||||
(defn reagent-component? [c]
|
||||
(-> (.' c :props.argv) nil? not))
|
||||
|
||||
(defn cached-react-class [c]
|
||||
(.' c :cljsReactClass))
|
||||
|
||||
(defn cache-react-class [c constructor]
|
||||
(.! c :cljsReactClass constructor))
|
||||
|
||||
;; Misc utilities
|
||||
|
||||
(defn memoize-1 [f]
|
||||
(let [mem (atom {})]
|
||||
(fn [arg]
|
||||
(let [v (get @mem arg)]
|
||||
(if-not (nil? v)
|
||||
v
|
||||
(let [ret (f arg)]
|
||||
(swap! mem assoc arg ret)
|
||||
ret))))))
|
||||
|
||||
(def dont-camel-case #{"aria" "data"})
|
||||
|
||||
(defn capitalize [s]
|
||||
(if (< (count s) 2)
|
||||
(string/upper-case s)
|
||||
(str (string/upper-case (subs s 0 1)) (subs s 1))))
|
||||
|
||||
(defn dash-to-camel [dashed]
|
||||
(if (string? dashed)
|
||||
dashed
|
||||
(let [name-str (name dashed)
|
||||
[start & parts] (string/split name-str #"-")]
|
||||
(if (dont-camel-case start)
|
||||
name-str
|
||||
(apply str start (map capitalize parts))))))
|
||||
|
||||
|
||||
(deftype partial-ifn [f args ^:mutable p]
|
||||
IFn
|
||||
(-invoke [_ & a]
|
||||
(or p (set! p (apply clojure.core/partial f args)))
|
||||
(apply p a))
|
||||
IEquiv
|
||||
(-equiv [_ other]
|
||||
(and (= f (.-f other)) (= args (.-args other))))
|
||||
IHash
|
||||
(-hash [_] (hash [f args])))
|
||||
|
||||
(defn- merge-class [p1 p2]
|
||||
(let [class (when-let [c1 (:class p1)]
|
||||
(when-let [c2 (:class p2)]
|
||||
(str c1 " " c2)))]
|
||||
(if (nil? class)
|
||||
p2
|
||||
(assoc p2 :class class))))
|
||||
|
||||
(defn- merge-style [p1 p2]
|
||||
(let [style (when-let [s1 (:style p1)]
|
||||
(when-let [s2 (:style p2)]
|
||||
(merge s1 s2)))]
|
||||
(if (nil? style)
|
||||
p2
|
||||
(assoc p2 :style style))))
|
||||
|
||||
(defn merge-props [p1 p2]
|
||||
(if (nil? p1)
|
||||
p2
|
||||
(do
|
||||
(assert (map? p1))
|
||||
(merge-style p1 (merge-class p1 (merge p1 p2))))))
|
||||
|
||||
|
||||
(def ^:dynamic *always-update* false)
|
||||
|
||||
(defonce roots (atom {}))
|
||||
|
||||
(defn clear-container [node]
|
||||
;; If render throws, React may get confused, and throw on
|
||||
;; unmount as well, so try to force React to start over.
|
||||
(some-> node
|
||||
(.! :innerHTML "")))
|
||||
|
||||
(defn render-component [comp container callback]
|
||||
(let [rendered (volatile! nil)]
|
||||
(try
|
||||
(binding [*always-update* true]
|
||||
(->> (.' js/React render (comp) container
|
||||
(fn []
|
||||
(binding [*always-update* false]
|
||||
(swap! roots assoc container [comp container])
|
||||
(if (some? callback)
|
||||
(callback)))))
|
||||
(vreset! rendered)))
|
||||
(finally
|
||||
(when-not @rendered
|
||||
(clear-container container))))))
|
||||
|
||||
(defn re-render-component [comp container]
|
||||
(render-component comp container nil))
|
||||
|
||||
(defn unmount-component-at-node [container]
|
||||
(swap! roots dissoc container)
|
||||
(.' js/React unmountComponentAtNode container))
|
||||
|
||||
(defn force-update-all []
|
||||
(doseq [v (vals @roots)]
|
||||
(apply re-render-component v))
|
||||
"Updated")
|
||||
|
||||
(defn force-update [comp deep]
|
||||
(if deep
|
||||
(binding [*always-update* true]
|
||||
(.' comp forceUpdate))
|
||||
(.' comp forceUpdate)))
|
||||
Executable
+374
@@ -0,0 +1,374 @@
|
||||
// Compiled by ClojureScript 1.11.60 {:static-fns true, :optimize-constants true, :optimizations :advanced}
|
||||
goog.provide('reagent.impl.util');
|
||||
goog.require('cljs.core');
|
||||
goog.require('cljs.core.constants');
|
||||
goog.require('reagent.debug');
|
||||
goog.require('reagent.interop');
|
||||
goog.require('clojure.string');
|
||||
reagent.impl.util.is_client = (((typeof window !== 'undefined')) && ((!(((window["document"]) == null)))));
|
||||
reagent.impl.util.extract_props = (function reagent$impl$util$extract_props(v){
|
||||
var p = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(v,(1),null);
|
||||
if(cljs.core.map_QMARK_(p)){
|
||||
return p;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
reagent.impl.util.extract_children = (function reagent$impl$util$extract_children(v){
|
||||
var p = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(v,(1),null);
|
||||
var first_child = (((((p == null)) || (cljs.core.map_QMARK_(p))))?(2):(1));
|
||||
if((cljs.core.count(v) > first_child)){
|
||||
return cljs.core.subvec.cljs$core$IFn$_invoke$arity$2(v,first_child);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
reagent.impl.util.get_argv = (function reagent$impl$util$get_argv(c){
|
||||
return (c["props"]["argv"]);
|
||||
});
|
||||
reagent.impl.util.get_props = (function reagent$impl$util$get_props(c){
|
||||
return reagent.impl.util.extract_props((c["props"]["argv"]));
|
||||
});
|
||||
reagent.impl.util.get_children = (function reagent$impl$util$get_children(c){
|
||||
return reagent.impl.util.extract_children((c["props"]["argv"]));
|
||||
});
|
||||
reagent.impl.util.reagent_component_QMARK_ = (function reagent$impl$util$reagent_component_QMARK_(c){
|
||||
return (!(((c["props"]["argv"]) == null)));
|
||||
});
|
||||
reagent.impl.util.cached_react_class = (function reagent$impl$util$cached_react_class(c){
|
||||
return (c["cljsReactClass"]);
|
||||
});
|
||||
reagent.impl.util.cache_react_class = (function reagent$impl$util$cache_react_class(c,constructor$){
|
||||
return (c["cljsReactClass"] = constructor$);
|
||||
});
|
||||
reagent.impl.util.memoize_1 = (function reagent$impl$util$memoize_1(f){
|
||||
var mem = cljs.core.atom.cljs$core$IFn$_invoke$arity$1(cljs.core.PersistentArrayMap.EMPTY);
|
||||
return (function (arg){
|
||||
var v = cljs.core.get.cljs$core$IFn$_invoke$arity$2(cljs.core.deref(mem),arg);
|
||||
if((!((v == null)))){
|
||||
return v;
|
||||
} else {
|
||||
var ret = (f.cljs$core$IFn$_invoke$arity$1 ? f.cljs$core$IFn$_invoke$arity$1(arg) : f.call(null,arg));
|
||||
cljs.core.swap_BANG_.cljs$core$IFn$_invoke$arity$4(mem,cljs.core.assoc,arg,ret);
|
||||
|
||||
return ret;
|
||||
}
|
||||
});
|
||||
});
|
||||
reagent.impl.util.dont_camel_case = new cljs.core.PersistentHashSet(null, new cljs.core.PersistentArrayMap(null, 2, ["aria",null,"data",null], null), null);
|
||||
reagent.impl.util.capitalize = (function reagent$impl$util$capitalize(s){
|
||||
if((cljs.core.count(s) < (2))){
|
||||
return clojure.string.upper_case(s);
|
||||
} else {
|
||||
return [clojure.string.upper_case(cljs.core.subs.cljs$core$IFn$_invoke$arity$3(s,(0),(1))),cljs.core.subs.cljs$core$IFn$_invoke$arity$2(s,(1))].join('');
|
||||
}
|
||||
});
|
||||
reagent.impl.util.dash_to_camel = (function reagent$impl$util$dash_to_camel(dashed){
|
||||
if(typeof dashed === 'string'){
|
||||
return dashed;
|
||||
} else {
|
||||
var name_str = cljs.core.name(dashed);
|
||||
var vec__5642 = clojure.string.split.cljs$core$IFn$_invoke$arity$2(name_str,/-/);
|
||||
var seq__5643 = cljs.core.seq(vec__5642);
|
||||
var first__5644 = cljs.core.first(seq__5643);
|
||||
var seq__5643__$1 = cljs.core.next(seq__5643);
|
||||
var start = first__5644;
|
||||
var parts = seq__5643__$1;
|
||||
if(cljs.core.truth_((reagent.impl.util.dont_camel_case.cljs$core$IFn$_invoke$arity$1 ? reagent.impl.util.dont_camel_case.cljs$core$IFn$_invoke$arity$1(start) : reagent.impl.util.dont_camel_case.call(null,start)))){
|
||||
return name_str;
|
||||
} else {
|
||||
return cljs.core.apply.cljs$core$IFn$_invoke$arity$3(cljs.core.str,start,cljs.core.map.cljs$core$IFn$_invoke$arity$2(reagent.impl.util.capitalize,parts));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @implements {cljs.core.IEquiv}
|
||||
* @implements {cljs.core.IHash}
|
||||
* @implements {cljs.core.IFn}
|
||||
*/
|
||||
reagent.impl.util.partial_ifn = (function (f,args,p){
|
||||
this.f = f;
|
||||
this.args = args;
|
||||
this.p = p;
|
||||
this.cljs$lang$protocol_mask$partition0$ = 6291457;
|
||||
this.cljs$lang$protocol_mask$partition1$ = 0;
|
||||
});
|
||||
(reagent.impl.util.partial_ifn.prototype.call = (function() {
|
||||
var G__5647__delegate = function (self__,a){
|
||||
var self__ = this;
|
||||
var self____$1 = this;
|
||||
var _ = self____$1;
|
||||
var or__5045__auto___5648 = self__.p;
|
||||
if(cljs.core.truth_(or__5045__auto___5648)){
|
||||
} else {
|
||||
(self__.p = cljs.core.apply.cljs$core$IFn$_invoke$arity$3(cljs.core.partial,self__.f,self__.args));
|
||||
}
|
||||
|
||||
return cljs.core.apply.cljs$core$IFn$_invoke$arity$2(self__.p,a);
|
||||
};
|
||||
var G__5647 = function (self__,var_args){
|
||||
var self__ = this;
|
||||
var a = null;
|
||||
if (arguments.length > 1) {
|
||||
var G__5649__i = 0, G__5649__a = new Array(arguments.length - 1);
|
||||
while (G__5649__i < G__5649__a.length) {G__5649__a[G__5649__i] = arguments[G__5649__i + 1]; ++G__5649__i;}
|
||||
a = new cljs.core.IndexedSeq(G__5649__a,0,null);
|
||||
}
|
||||
return G__5647__delegate.call(this,self__,a);};
|
||||
G__5647.cljs$lang$maxFixedArity = 1;
|
||||
G__5647.cljs$lang$applyTo = (function (arglist__5650){
|
||||
var self__ = cljs.core.first(arglist__5650);
|
||||
var a = cljs.core.rest(arglist__5650);
|
||||
return G__5647__delegate(self__,a);
|
||||
});
|
||||
G__5647.cljs$core$IFn$_invoke$arity$variadic = G__5647__delegate;
|
||||
return G__5647;
|
||||
})()
|
||||
);
|
||||
|
||||
(reagent.impl.util.partial_ifn.prototype.apply = (function (self__,args5645){
|
||||
var self__ = this;
|
||||
var self____$1 = this;
|
||||
var args__5260__auto__ = cljs.core.aclone(args5645);
|
||||
return self____$1.call.apply(self____$1,[self____$1].concat((((args__5260__auto__.length > (20)))?(function (){var G__5646 = args__5260__auto__.slice((0),(20));
|
||||
G__5646.push(args__5260__auto__.slice((20)));
|
||||
|
||||
return G__5646;
|
||||
})():args__5260__auto__)));
|
||||
}));
|
||||
|
||||
(reagent.impl.util.partial_ifn.prototype.cljs$core$IFn$_invoke$arity$2 = (function() {
|
||||
var G__5651__delegate = function (a){
|
||||
var self__ = this;
|
||||
var _ = this;
|
||||
var or__5045__auto___5652 = self__.p;
|
||||
if(cljs.core.truth_(or__5045__auto___5652)){
|
||||
} else {
|
||||
(self__.p = cljs.core.apply.cljs$core$IFn$_invoke$arity$3(cljs.core.partial,self__.f,self__.args));
|
||||
}
|
||||
|
||||
return cljs.core.apply.cljs$core$IFn$_invoke$arity$2(self__.p,a);
|
||||
};
|
||||
var G__5651 = function (var_args){
|
||||
var self__ = this;
|
||||
var a = null;
|
||||
if (arguments.length > 0) {
|
||||
var G__5653__i = 0, G__5653__a = new Array(arguments.length - 0);
|
||||
while (G__5653__i < G__5653__a.length) {G__5653__a[G__5653__i] = arguments[G__5653__i + 0]; ++G__5653__i;}
|
||||
a = new cljs.core.IndexedSeq(G__5653__a,0,null);
|
||||
}
|
||||
return G__5651__delegate.call(this,a);};
|
||||
G__5651.cljs$lang$maxFixedArity = 0;
|
||||
G__5651.cljs$lang$applyTo = (function (arglist__5654){
|
||||
var a = cljs.core.seq(arglist__5654);
|
||||
return G__5651__delegate(a);
|
||||
});
|
||||
G__5651.cljs$core$IFn$_invoke$arity$variadic = G__5651__delegate;
|
||||
return G__5651;
|
||||
})()
|
||||
);
|
||||
|
||||
(reagent.impl.util.partial_ifn.prototype.cljs$core$IEquiv$_equiv$arity$2 = (function (_,other){
|
||||
var self__ = this;
|
||||
var ___$1 = this;
|
||||
return ((cljs.core._EQ_.cljs$core$IFn$_invoke$arity$2(self__.f,other.f)) && (cljs.core._EQ_.cljs$core$IFn$_invoke$arity$2(self__.args,other.args)));
|
||||
}));
|
||||
|
||||
(reagent.impl.util.partial_ifn.prototype.cljs$core$IHash$_hash$arity$1 = (function (_){
|
||||
var self__ = this;
|
||||
var ___$1 = this;
|
||||
return cljs.core.hash(new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [self__.f,self__.args], null));
|
||||
}));
|
||||
|
||||
(reagent.impl.util.partial_ifn.getBasis = (function (){
|
||||
return new cljs.core.PersistentVector(null, 3, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.cst$sym$f,cljs.core.cst$sym$args,cljs.core.with_meta(cljs.core.cst$sym$p,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null))], null);
|
||||
}));
|
||||
|
||||
(reagent.impl.util.partial_ifn.cljs$lang$type = true);
|
||||
|
||||
(reagent.impl.util.partial_ifn.cljs$lang$ctorStr = "reagent.impl.util/partial-ifn");
|
||||
|
||||
(reagent.impl.util.partial_ifn.cljs$lang$ctorPrWriter = (function (this__5330__auto__,writer__5331__auto__,opt__5332__auto__){
|
||||
return cljs.core._write(writer__5331__auto__,"reagent.impl.util/partial-ifn");
|
||||
}));
|
||||
|
||||
/**
|
||||
* Positional factory function for reagent.impl.util/partial-ifn.
|
||||
*/
|
||||
reagent.impl.util.__GT_partial_ifn = (function reagent$impl$util$__GT_partial_ifn(f,args,p){
|
||||
return (new reagent.impl.util.partial_ifn(f,args,p));
|
||||
});
|
||||
|
||||
reagent.impl.util.merge_class = (function reagent$impl$util$merge_class(p1,p2){
|
||||
var class$ = (function (){var temp__4657__auto__ = cljs.core.cst$kw$class.cljs$core$IFn$_invoke$arity$1(p1);
|
||||
if(cljs.core.truth_(temp__4657__auto__)){
|
||||
var c1 = temp__4657__auto__;
|
||||
var temp__4657__auto____$1 = cljs.core.cst$kw$class.cljs$core$IFn$_invoke$arity$1(p2);
|
||||
if(cljs.core.truth_(temp__4657__auto____$1)){
|
||||
var c2 = temp__4657__auto____$1;
|
||||
return [cljs.core.str.cljs$core$IFn$_invoke$arity$1(c1)," ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(c2)].join('');
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
})();
|
||||
if((class$ == null)){
|
||||
return p2;
|
||||
} else {
|
||||
return cljs.core.assoc.cljs$core$IFn$_invoke$arity$3(p2,cljs.core.cst$kw$class,class$);
|
||||
}
|
||||
});
|
||||
reagent.impl.util.merge_style = (function reagent$impl$util$merge_style(p1,p2){
|
||||
var style = (function (){var temp__4657__auto__ = cljs.core.cst$kw$style.cljs$core$IFn$_invoke$arity$1(p1);
|
||||
if(cljs.core.truth_(temp__4657__auto__)){
|
||||
var s1 = temp__4657__auto__;
|
||||
var temp__4657__auto____$1 = cljs.core.cst$kw$style.cljs$core$IFn$_invoke$arity$1(p2);
|
||||
if(cljs.core.truth_(temp__4657__auto____$1)){
|
||||
var s2 = temp__4657__auto____$1;
|
||||
return cljs.core.merge.cljs$core$IFn$_invoke$arity$variadic(cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2([s1,s2], 0));
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
})();
|
||||
if((style == null)){
|
||||
return p2;
|
||||
} else {
|
||||
return cljs.core.assoc.cljs$core$IFn$_invoke$arity$3(p2,cljs.core.cst$kw$style,style);
|
||||
}
|
||||
});
|
||||
reagent.impl.util.merge_props = (function reagent$impl$util$merge_props(p1,p2){
|
||||
if((p1 == null)){
|
||||
return p2;
|
||||
} else {
|
||||
if(cljs.core.map_QMARK_(p1)){
|
||||
} else {
|
||||
throw (new Error("Assert failed: (map? p1)"));
|
||||
}
|
||||
|
||||
return reagent.impl.util.merge_style(p1,reagent.impl.util.merge_class(p1,cljs.core.merge.cljs$core$IFn$_invoke$arity$variadic(cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2([p1,p2], 0))));
|
||||
}
|
||||
});
|
||||
reagent.impl.util._STAR_always_update_STAR_ = false;
|
||||
if((typeof reagent !== 'undefined') && (typeof reagent.impl !== 'undefined') && (typeof reagent.impl.util !== 'undefined') && (typeof reagent.impl.util.roots !== 'undefined')){
|
||||
} else {
|
||||
reagent.impl.util.roots = cljs.core.atom.cljs$core$IFn$_invoke$arity$1(cljs.core.PersistentArrayMap.EMPTY);
|
||||
}
|
||||
reagent.impl.util.clear_container = (function reagent$impl$util$clear_container(node){
|
||||
var G__5655 = node;
|
||||
if((G__5655 == null)){
|
||||
return null;
|
||||
} else {
|
||||
return (G__5655["innerHTML"] = "");
|
||||
}
|
||||
});
|
||||
reagent.impl.util.render_component = (function reagent$impl$util$render_component(comp,container,callback){
|
||||
var rendered = cljs.core.volatile_BANG_(null);
|
||||
try{var _STAR_always_update_STAR__orig_val__5656 = reagent.impl.util._STAR_always_update_STAR_;
|
||||
var _STAR_always_update_STAR__temp_val__5657 = true;
|
||||
(reagent.impl.util._STAR_always_update_STAR_ = _STAR_always_update_STAR__temp_val__5657);
|
||||
|
||||
try{return cljs.core.vreset_BANG_(rendered,(React["render"])((comp.cljs$core$IFn$_invoke$arity$0 ? comp.cljs$core$IFn$_invoke$arity$0() : comp.call(null)),container,(function (){
|
||||
var _STAR_always_update_STAR__orig_val__5658 = reagent.impl.util._STAR_always_update_STAR_;
|
||||
var _STAR_always_update_STAR__temp_val__5659 = false;
|
||||
(reagent.impl.util._STAR_always_update_STAR_ = _STAR_always_update_STAR__temp_val__5659);
|
||||
|
||||
try{cljs.core.swap_BANG_.cljs$core$IFn$_invoke$arity$4(reagent.impl.util.roots,cljs.core.assoc,container,new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [comp,container], null));
|
||||
|
||||
if((!((callback == null)))){
|
||||
return (callback.cljs$core$IFn$_invoke$arity$0 ? callback.cljs$core$IFn$_invoke$arity$0() : callback.call(null));
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}finally {(reagent.impl.util._STAR_always_update_STAR_ = _STAR_always_update_STAR__orig_val__5658);
|
||||
}})));
|
||||
}finally {(reagent.impl.util._STAR_always_update_STAR_ = _STAR_always_update_STAR__orig_val__5656);
|
||||
}}finally {if(cljs.core.truth_(cljs.core.deref(rendered))){
|
||||
} else {
|
||||
reagent.impl.util.clear_container(container);
|
||||
}
|
||||
}});
|
||||
reagent.impl.util.re_render_component = (function reagent$impl$util$re_render_component(comp,container){
|
||||
return reagent.impl.util.render_component(comp,container,null);
|
||||
});
|
||||
reagent.impl.util.unmount_component_at_node = (function reagent$impl$util$unmount_component_at_node(container){
|
||||
cljs.core.swap_BANG_.cljs$core$IFn$_invoke$arity$3(reagent.impl.util.roots,cljs.core.dissoc,container);
|
||||
|
||||
return (React["unmountComponentAtNode"])(container);
|
||||
});
|
||||
reagent.impl.util.force_update_all = (function reagent$impl$util$force_update_all(){
|
||||
var seq__5660_5664 = cljs.core.seq(cljs.core.vals(cljs.core.deref(reagent.impl.util.roots)));
|
||||
var chunk__5661_5665 = null;
|
||||
var count__5662_5666 = (0);
|
||||
var i__5663_5667 = (0);
|
||||
while(true){
|
||||
if((i__5663_5667 < count__5662_5666)){
|
||||
var v_5668 = chunk__5661_5665.cljs$core$IIndexed$_nth$arity$2(null,i__5663_5667);
|
||||
cljs.core.apply.cljs$core$IFn$_invoke$arity$2(reagent.impl.util.re_render_component,v_5668);
|
||||
|
||||
|
||||
var G__5669 = seq__5660_5664;
|
||||
var G__5670 = chunk__5661_5665;
|
||||
var G__5671 = count__5662_5666;
|
||||
var G__5672 = (i__5663_5667 + (1));
|
||||
seq__5660_5664 = G__5669;
|
||||
chunk__5661_5665 = G__5670;
|
||||
count__5662_5666 = G__5671;
|
||||
i__5663_5667 = G__5672;
|
||||
continue;
|
||||
} else {
|
||||
var temp__4657__auto___5673 = cljs.core.seq(seq__5660_5664);
|
||||
if(temp__4657__auto___5673){
|
||||
var seq__5660_5674__$1 = temp__4657__auto___5673;
|
||||
if(cljs.core.chunked_seq_QMARK_(seq__5660_5674__$1)){
|
||||
var c__5568__auto___5675 = cljs.core.chunk_first(seq__5660_5674__$1);
|
||||
var G__5676 = cljs.core.chunk_rest(seq__5660_5674__$1);
|
||||
var G__5677 = c__5568__auto___5675;
|
||||
var G__5678 = cljs.core.count(c__5568__auto___5675);
|
||||
var G__5679 = (0);
|
||||
seq__5660_5664 = G__5676;
|
||||
chunk__5661_5665 = G__5677;
|
||||
count__5662_5666 = G__5678;
|
||||
i__5663_5667 = G__5679;
|
||||
continue;
|
||||
} else {
|
||||
var v_5680 = cljs.core.first(seq__5660_5674__$1);
|
||||
cljs.core.apply.cljs$core$IFn$_invoke$arity$2(reagent.impl.util.re_render_component,v_5680);
|
||||
|
||||
|
||||
var G__5681 = cljs.core.next(seq__5660_5674__$1);
|
||||
var G__5682 = null;
|
||||
var G__5683 = (0);
|
||||
var G__5684 = (0);
|
||||
seq__5660_5664 = G__5681;
|
||||
chunk__5661_5665 = G__5682;
|
||||
count__5662_5666 = G__5683;
|
||||
i__5663_5667 = G__5684;
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return "Updated";
|
||||
});
|
||||
reagent.impl.util.force_update = (function reagent$impl$util$force_update(comp,deep){
|
||||
if(cljs.core.truth_(deep)){
|
||||
var _STAR_always_update_STAR__orig_val__5685 = reagent.impl.util._STAR_always_update_STAR_;
|
||||
var _STAR_always_update_STAR__temp_val__5686 = true;
|
||||
(reagent.impl.util._STAR_always_update_STAR_ = _STAR_always_update_STAR__temp_val__5686);
|
||||
|
||||
try{return (comp["forceUpdate"])();
|
||||
}finally {(reagent.impl.util._STAR_always_update_STAR_ = _STAR_always_update_STAR__orig_val__5685);
|
||||
}} else {
|
||||
return (comp["forceUpdate"])();
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user