Added compiled JavaScript to repository for GitHub pages

This feels like a mistake...
This commit is contained in:
Simon Brooke 2020-10-20 14:44:11 +01:00
parent 3d5a2fb322
commit dc226b1f25
468 changed files with 212152 additions and 2 deletions

View file

@ -0,0 +1,359 @@
(ns reagent.core
(:require-macros [reagent.core])
(:refer-clojure :exclude [partial atom flush])
(:require [reagent.impl.template :as tmpl]
[reagent.impl.component :as comp]
[reagent.impl.util :as util]
[reagent.impl.batching :as batch]
[reagent.ratom :as ratom]
[reagent.debug :as deb :refer-macros [dbg prn]]
[reagent.interop :refer-macros [$ $!]]
[reagent.dom :as dom]
[reagent.dom.server :as server]))
(def is-client util/is-client)
(def react util/react)
(defn create-element
"Create a native React element, by calling React.createElement directly.
That means the second argument must be a javascript object (or nil), and
that any Reagent hiccup forms must be processed with as-element. For example
like this:
(r/create-element \"div\" #js{:className \"foo\"}
\"Hi \" (r/as-element [:strong \"world!\"])
which is equivalent to
[:div.foo \"Hi\" [:strong \"world!\"]]"
([type]
(create-element type nil))
([type props]
(assert (not (map? props)))
($ react createElement type props))
([type props child]
(assert (not (map? props)))
($ react createElement type props child))
([type props child & children]
(assert (not (map? props)))
(apply ($ react :createElement) type props child children)))
(defn as-element
"Turns a vector of Hiccup syntax into a React element. Returns form
unchanged if it is not a vector."
[form]
(tmpl/as-element form))
(defn adapt-react-class
"Returns an adapter for a native React class, that may be used
just like a Reagent component function or class in Hiccup forms."
[c]
(assert c)
(tmpl/adapt-react-class c))
(defn reactify-component
"Returns an adapter for a Reagent component, that may be used from
React, for example in JSX. A single argument, props, is passed to
the component, converted to a map."
[c]
(assert c)
(comp/reactify-component c))
(defn render
"Render a Reagent component into the DOM. The first argument may be
either a vector (using Reagent's Hiccup syntax), or a React element.
The second argument should be a DOM node.
Optionally takes a callback that is called when the component is in place.
Returns the mounted component instance."
([comp container]
(dom/render comp container))
([comp container callback]
(dom/render comp container callback)))
(defn unmount-component-at-node
"Remove a component from the given DOM node."
[container]
(dom/unmount-component-at-node container))
(defn render-to-string
"Turns a component into an HTML string."
[component]
(server/render-to-string component))
;; For backward compatibility
(def as-component as-element)
(def render-component render)
(def render-component-to-string render-to-string)
(defn render-to-static-markup
"Turns a component into an HTML string, without data-react-id attributes, etc."
[component]
(server/render-to-static-markup component))
(defn ^:export force-update-all
"Force re-rendering of all mounted Reagent components. This is
probably only useful in a development environment, when you want to
update components in response to some dynamic changes to code.
Note that force-update-all may not update root components. This
happens if a component 'foo' is mounted with `(render [foo])` (since
functions are passed by value, and not by reference, in
ClojureScript). To get around this you'll have to introduce a layer
of indirection, for example by using `(render [#'foo])` instead."
[]
(ratom/flush!)
(dom/force-update-all)
(batch/flush-after-render))
(defn create-class
"Create a component, React style. Should be called with a map,
looking like this:
{:get-initial-state (fn [this])
:component-will-receive-props (fn [this new-argv])
:should-component-update (fn [this old-argv new-argv])
:component-will-mount (fn [this])
:component-did-mount (fn [this])
:component-will-update (fn [this new-argv])
:component-did-update (fn [this old-argv])
:component-will-unmount (fn [this])
:reagent-render (fn [args....])} ;; or :render (fn [this])
Everything is optional, except either :reagent-render or :render."
[spec]
(comp/create-class spec))
(defn current-component
"Returns the current React component (a.k.a this) in a component
function."
[]
comp/*current-component*)
(defn state-atom
"Returns an atom containing a components state."
[this]
(assert (comp/reagent-component? this))
(comp/state-atom this))
(defn state
"Returns the state of a component, as set with replace-state or set-state.
Equivalent to (deref (r/state-atom this))"
[this]
(assert (comp/reagent-component? this))
(deref (state-atom this)))
(defn replace-state
"Set state of a component.
Equivalent to (reset! (state-atom this) new-state)"
[this new-state]
(assert (comp/reagent-component? this))
(assert (or (nil? new-state) (map? new-state)))
(reset! (state-atom this) new-state))
(defn set-state
"Merge component state with new-state.
Equivalent to (swap! (state-atom this) merge new-state)"
[this new-state]
(assert (comp/reagent-component? this))
(assert (or (nil? new-state) (map? new-state)))
(swap! (state-atom this) merge new-state))
(defn force-update
"Force a component to re-render immediately.
If the second argument is true, child components will also be
re-rendered, even is their arguments have not changed."
([this]
(force-update this false))
([this deep]
(ratom/flush!)
(util/force-update this deep)
(batch/flush-after-render)))
(defn props
"Returns the props passed to a component."
[this]
(assert (comp/reagent-component? this))
(comp/get-props this))
(defn children
"Returns the children passed to a component."
[this]
(assert (comp/reagent-component? this))
(comp/get-children this))
(defn argv
"Returns the entire Hiccup form passed to the component."
[this]
(assert (comp/reagent-component? this))
(comp/get-argv this))
(defn dom-node
"Returns the root DOM node of a mounted component."
[this]
(dom/dom-node this))
(defn merge-props
"Utility function that merges two maps, handling :class and :style
specially, like React's transferPropsTo."
[defaults props]
(util/merge-props defaults props))
(defn flush
"Render dirty components immediately to the DOM.
Note that this may not work in event handlers, since React.js does
batching of updates there."
[]
(batch/flush))
;; Ratom
(defn atom
"Like clojure.core/atom, except that it keeps track of derefs.
Reagent components that derefs one of these are automatically
re-rendered."
([x] (ratom/atom x))
([x & rest] (apply ratom/atom x rest)))
(defn track
"Takes a function and optional arguments, and returns a derefable
containing the output of that function. If the function derefs
Reagent atoms (or track, etc), the value will be updated whenever
the atom changes.
In other words, @(track foo bar) will produce the same result
as (foo bar), but foo will only be called again when the atoms it
depends on changes, and will only trigger updates of components when
its result changes.
track is lazy, i.e the function is only evaluated on deref."
[f & args]
{:pre [(ifn? f)]}
(ratom/make-track f args))
(defn track!
"An eager version of track. The function passed is called
immediately, and continues to be called when needed, until stopped
with dispose!."
[f & args]
{:pre [(ifn? f)]}
(ratom/make-track! f args))
(defn dispose!
"Stop the result of track! from updating."
[x]
(ratom/dispose! x))
(defn wrap
"Provide a combination of value and callback, that looks like an atom.
The first argument can be any value, that will be returned when the
result is deref'ed.
The second argument should be a function, that is called with the
optional extra arguments provided to wrap, and the new value of the
resulting 'atom'.
Use for example like this:
(wrap (:foo @state)
swap! state assoc :foo)
Probably useful only for passing to child components."
[value reset-fn & args]
(assert (ifn? reset-fn))
(ratom/make-wrapper value reset-fn args))
;; RCursor
(defn cursor
"Provide a cursor into a Reagent atom.
Behaves like a Reagent atom but focuses updates and derefs to
the specified path within the wrapped Reagent atom. e.g.,
(let [c (cursor ra [:nested :content])]
... @c ;; equivalent to (get-in @ra [:nested :content])
... (reset! c 42) ;; equivalent to (swap! ra assoc-in [:nested :content] 42)
... (swap! c inc) ;; equivalence to (swap! ra update-in [:nested :content] inc)
)
The first parameter can also be a function, that should look
something like this:
(defn set-get
([k] (get-in @state k))
([k v] (swap! state assoc-in k v)))
The function will be called with one argument the path passed to
cursor when the cursor is deref'ed, and two arguments (path and
new value) when the cursor is modified.
Given that set-get function, (and that state is a Reagent atom, or
another cursor) these cursors are equivalent:
(cursor state [:foo]) and (cursor set-get [:foo]).
Note that a cursor is lazy: its value will not change until it is
used. This may be noticed with add-watch."
([src path]
(ratom/cursor src path)))
;; Utilities
(defn rswap!
"Swaps the value of a to be (apply f current-value-of-atom args).
rswap! works like swap!, except that recursive calls to rswap! on
the same atom are allowed and it always returns nil."
[a f & args]
{:pre [(satisfies? IAtom a)
(ifn? f)]}
(if a.rswapping
(-> (or a.rswapfs (set! a.rswapfs (array)))
(.push #(apply f % args)))
(do (set! a.rswapping true)
(try (swap! a (fn [state]
(loop [s (apply f state args)]
(if-some [sf (some-> a.rswapfs .shift)]
(recur (sf s))
s))))
(finally
(set! a.rswapping false)))))
nil)
(defn next-tick
"Run f using requestAnimationFrame or equivalent.
f will be called just before components are rendered."
[f]
(batch/do-before-flush f))
(defn after-render
"Run f using requestAnimationFrame or equivalent.
f will be called just after any queued renders in the next animation
frame (and even if no renders actually occur)."
[f]
(batch/do-after-render f))
(defn partial
"Works just like clojure.core/partial, except that it is an IFn, and
the result can be compared with ="
[f & args]
(util/partial-ifn. f args nil))
(defn component-path
;; Try to return the path of component c as a string.
;; Maybe useful for debugging and error reporting, but may break
;; with future versions of React (and return nil).
[c]
(comp/component-path c))

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,802 @@
// Compiled by ClojureScript 1.9.229 {}
goog.provide('reagent.core');
goog.require('cljs.core');
goog.require('reagent.impl.util');
goog.require('reagent.dom.server');
goog.require('reagent.dom');
goog.require('reagent.impl.component');
goog.require('reagent.interop');
goog.require('reagent.ratom');
goog.require('reagent.impl.template');
goog.require('reagent.impl.batching');
goog.require('reagent.debug');
reagent.core.is_client = reagent.impl.util.is_client;
reagent.core.react = reagent.impl.util.react;
/**
* Create a native React element, by calling React.createElement directly.
*
* That means the second argument must be a javascript object (or nil), and
* that any Reagent hiccup forms must be processed with as-element. For example
* like this:
*
* (r/create-element "div" #js{:className "foo"}
* "Hi " (r/as-element [:strong "world!"])
*
* which is equivalent to
*
* [:div.foo "Hi" [:strong "world!"]]
*/
reagent.core.create_element = (function reagent$core$create_element(var_args){
var args26961 = [];
var len__26205__auto___26968 = arguments.length;
var i__26206__auto___26969 = (0);
while(true){
if((i__26206__auto___26969 < len__26205__auto___26968)){
args26961.push((arguments[i__26206__auto___26969]));
var G__26970 = (i__26206__auto___26969 + (1));
i__26206__auto___26969 = G__26970;
continue;
} else {
}
break;
}
var G__26967 = args26961.length;
switch (G__26967) {
case 1:
return reagent.core.create_element.cljs$core$IFn$_invoke$arity$1((arguments[(0)]));
break;
case 2:
return reagent.core.create_element.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)]));
break;
case 3:
return reagent.core.create_element.cljs$core$IFn$_invoke$arity$3((arguments[(0)]),(arguments[(1)]),(arguments[(2)]));
break;
default:
var argseq__26224__auto__ = (new cljs.core.IndexedSeq(args26961.slice((3)),(0),null));
return reagent.core.create_element.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),argseq__26224__auto__);
}
});
reagent.core.create_element.cljs$core$IFn$_invoke$arity$1 = (function (type){
return reagent.core.create_element.call(null,type,null);
});
reagent.core.create_element.cljs$core$IFn$_invoke$arity$2 = (function (type,props){
if(!(cljs.core.map_QMARK_.call(null,props))){
} else {
throw (new Error("Assert failed: (not (map? props))"));
}
return (reagent.core.react["createElement"])(type,props);
});
reagent.core.create_element.cljs$core$IFn$_invoke$arity$3 = (function (type,props,child){
if(!(cljs.core.map_QMARK_.call(null,props))){
} else {
throw (new Error("Assert failed: (not (map? props))"));
}
return (reagent.core.react["createElement"])(type,props,child);
});
reagent.core.create_element.cljs$core$IFn$_invoke$arity$variadic = (function (type,props,child,children){
if(!(cljs.core.map_QMARK_.call(null,props))){
} else {
throw (new Error("Assert failed: (not (map? props))"));
}
return cljs.core.apply.call(null,(reagent.core.react["createElement"]),type,props,child,children);
});
reagent.core.create_element.cljs$lang$applyTo = (function (seq26962){
var G__26963 = cljs.core.first.call(null,seq26962);
var seq26962__$1 = cljs.core.next.call(null,seq26962);
var G__26964 = cljs.core.first.call(null,seq26962__$1);
var seq26962__$2 = cljs.core.next.call(null,seq26962__$1);
var G__26965 = cljs.core.first.call(null,seq26962__$2);
var seq26962__$3 = cljs.core.next.call(null,seq26962__$2);
return reagent.core.create_element.cljs$core$IFn$_invoke$arity$variadic(G__26963,G__26964,G__26965,seq26962__$3);
});
reagent.core.create_element.cljs$lang$maxFixedArity = (3);
/**
* Turns a vector of Hiccup syntax into a React element. Returns form
* unchanged if it is not a vector.
*/
reagent.core.as_element = (function reagent$core$as_element(form){
return reagent.impl.template.as_element.call(null,form);
});
/**
* Returns an adapter for a native React class, that may be used
* just like a Reagent component function or class in Hiccup forms.
*/
reagent.core.adapt_react_class = (function reagent$core$adapt_react_class(c){
if(cljs.core.truth_(c)){
} else {
throw (new Error("Assert failed: c"));
}
return reagent.impl.template.adapt_react_class.call(null,c);
});
/**
* Returns an adapter for a Reagent component, that may be used from
* React, for example in JSX. A single argument, props, is passed to
* the component, converted to a map.
*/
reagent.core.reactify_component = (function reagent$core$reactify_component(c){
if(cljs.core.truth_(c)){
} else {
throw (new Error("Assert failed: c"));
}
return reagent.impl.component.reactify_component.call(null,c);
});
/**
* Render a Reagent component into the DOM. The first argument may be
* either a vector (using Reagent's Hiccup syntax), or a React element.
* The second argument should be a DOM node.
*
* Optionally takes a callback that is called when the component is in place.
*
* Returns the mounted component instance.
*/
reagent.core.render = (function reagent$core$render(var_args){
var args26972 = [];
var len__26205__auto___26975 = arguments.length;
var i__26206__auto___26976 = (0);
while(true){
if((i__26206__auto___26976 < len__26205__auto___26975)){
args26972.push((arguments[i__26206__auto___26976]));
var G__26977 = (i__26206__auto___26976 + (1));
i__26206__auto___26976 = G__26977;
continue;
} else {
}
break;
}
var G__26974 = args26972.length;
switch (G__26974) {
case 2:
return reagent.core.render.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)]));
break;
case 3:
return reagent.core.render.cljs$core$IFn$_invoke$arity$3((arguments[(0)]),(arguments[(1)]),(arguments[(2)]));
break;
default:
throw (new Error([cljs.core.str("Invalid arity: "),cljs.core.str(args26972.length)].join('')));
}
});
reagent.core.render.cljs$core$IFn$_invoke$arity$2 = (function (comp,container){
return reagent.dom.render.call(null,comp,container);
});
reagent.core.render.cljs$core$IFn$_invoke$arity$3 = (function (comp,container,callback){
return reagent.dom.render.call(null,comp,container,callback);
});
reagent.core.render.cljs$lang$maxFixedArity = 3;
/**
* Remove a component from the given DOM node.
*/
reagent.core.unmount_component_at_node = (function reagent$core$unmount_component_at_node(container){
return reagent.dom.unmount_component_at_node.call(null,container);
});
/**
* Turns a component into an HTML string.
*/
reagent.core.render_to_string = (function reagent$core$render_to_string(component){
return reagent.dom.server.render_to_string.call(null,component);
});
reagent.core.as_component = reagent.core.as_element;
reagent.core.render_component = reagent.core.render;
reagent.core.render_component_to_string = reagent.core.render_to_string;
/**
* Turns a component into an HTML string, without data-react-id attributes, etc.
*/
reagent.core.render_to_static_markup = (function reagent$core$render_to_static_markup(component){
return reagent.dom.server.render_to_static_markup.call(null,component);
});
/**
* Force re-rendering of all mounted Reagent components. This is
* probably only useful in a development environment, when you want to
* update components in response to some dynamic changes to code.
*
* Note that force-update-all may not update root components. This
* happens if a component 'foo' is mounted with `(render [foo])` (since
* functions are passed by value, and not by reference, in
* ClojureScript). To get around this you'll have to introduce a layer
* of indirection, for example by using `(render [#'foo])` instead.
*/
reagent.core.force_update_all = (function reagent$core$force_update_all(){
reagent.ratom.flush_BANG_.call(null);
reagent.dom.force_update_all.call(null);
return reagent.impl.batching.flush_after_render.call(null);
});
goog.exportSymbol('reagent.core.force_update_all', reagent.core.force_update_all);
/**
* Create a component, React style. Should be called with a map,
* looking like this:
*
* {:get-initial-state (fn [this])
* :component-will-receive-props (fn [this new-argv])
* :should-component-update (fn [this old-argv new-argv])
* :component-will-mount (fn [this])
* :component-did-mount (fn [this])
* :component-will-update (fn [this new-argv])
* :component-did-update (fn [this old-argv])
* :component-will-unmount (fn [this])
* :reagent-render (fn [args....])} ;; or :render (fn [this])
*
* Everything is optional, except either :reagent-render or :render.
*/
reagent.core.create_class = (function reagent$core$create_class(spec){
return reagent.impl.component.create_class.call(null,spec);
});
/**
* Returns the current React component (a.k.a this) in a component
* function.
*/
reagent.core.current_component = (function reagent$core$current_component(){
return reagent.impl.component._STAR_current_component_STAR_;
});
/**
* Returns an atom containing a components state.
*/
reagent.core.state_atom = (function reagent$core$state_atom(this$){
if(reagent.impl.component.reagent_component_QMARK_.call(null,this$)){
} else {
throw (new Error("Assert failed: (comp/reagent-component? this)"));
}
return reagent.impl.component.state_atom.call(null,this$);
});
/**
* Returns the state of a component, as set with replace-state or set-state.
* Equivalent to (deref (r/state-atom this))
*/
reagent.core.state = (function reagent$core$state(this$){
if(reagent.impl.component.reagent_component_QMARK_.call(null,this$)){
} else {
throw (new Error("Assert failed: (comp/reagent-component? this)"));
}
return cljs.core.deref.call(null,reagent.core.state_atom.call(null,this$));
});
/**
* Set state of a component.
* Equivalent to (reset! (state-atom this) new-state)
*/
reagent.core.replace_state = (function reagent$core$replace_state(this$,new_state){
if(reagent.impl.component.reagent_component_QMARK_.call(null,this$)){
} else {
throw (new Error("Assert failed: (comp/reagent-component? this)"));
}
if(((new_state == null)) || (cljs.core.map_QMARK_.call(null,new_state))){
} else {
throw (new Error("Assert failed: (or (nil? new-state) (map? new-state))"));
}
return cljs.core.reset_BANG_.call(null,reagent.core.state_atom.call(null,this$),new_state);
});
/**
* Merge component state with new-state.
* Equivalent to (swap! (state-atom this) merge new-state)
*/
reagent.core.set_state = (function reagent$core$set_state(this$,new_state){
if(reagent.impl.component.reagent_component_QMARK_.call(null,this$)){
} else {
throw (new Error("Assert failed: (comp/reagent-component? this)"));
}
if(((new_state == null)) || (cljs.core.map_QMARK_.call(null,new_state))){
} else {
throw (new Error("Assert failed: (or (nil? new-state) (map? new-state))"));
}
return cljs.core.swap_BANG_.call(null,reagent.core.state_atom.call(null,this$),cljs.core.merge,new_state);
});
/**
* Force a component to re-render immediately.
*
* If the second argument is true, child components will also be
* re-rendered, even is their arguments have not changed.
*/
reagent.core.force_update = (function reagent$core$force_update(var_args){
var args26979 = [];
var len__26205__auto___26982 = arguments.length;
var i__26206__auto___26983 = (0);
while(true){
if((i__26206__auto___26983 < len__26205__auto___26982)){
args26979.push((arguments[i__26206__auto___26983]));
var G__26984 = (i__26206__auto___26983 + (1));
i__26206__auto___26983 = G__26984;
continue;
} else {
}
break;
}
var G__26981 = args26979.length;
switch (G__26981) {
case 1:
return reagent.core.force_update.cljs$core$IFn$_invoke$arity$1((arguments[(0)]));
break;
case 2:
return reagent.core.force_update.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)]));
break;
default:
throw (new Error([cljs.core.str("Invalid arity: "),cljs.core.str(args26979.length)].join('')));
}
});
reagent.core.force_update.cljs$core$IFn$_invoke$arity$1 = (function (this$){
return reagent.core.force_update.call(null,this$,false);
});
reagent.core.force_update.cljs$core$IFn$_invoke$arity$2 = (function (this$,deep){
reagent.ratom.flush_BANG_.call(null);
reagent.impl.util.force_update.call(null,this$,deep);
return reagent.impl.batching.flush_after_render.call(null);
});
reagent.core.force_update.cljs$lang$maxFixedArity = 2;
/**
* Returns the props passed to a component.
*/
reagent.core.props = (function reagent$core$props(this$){
if(reagent.impl.component.reagent_component_QMARK_.call(null,this$)){
} else {
throw (new Error("Assert failed: (comp/reagent-component? this)"));
}
return reagent.impl.component.get_props.call(null,this$);
});
/**
* Returns the children passed to a component.
*/
reagent.core.children = (function reagent$core$children(this$){
if(reagent.impl.component.reagent_component_QMARK_.call(null,this$)){
} else {
throw (new Error("Assert failed: (comp/reagent-component? this)"));
}
return reagent.impl.component.get_children.call(null,this$);
});
/**
* Returns the entire Hiccup form passed to the component.
*/
reagent.core.argv = (function reagent$core$argv(this$){
if(reagent.impl.component.reagent_component_QMARK_.call(null,this$)){
} else {
throw (new Error("Assert failed: (comp/reagent-component? this)"));
}
return reagent.impl.component.get_argv.call(null,this$);
});
/**
* Returns the root DOM node of a mounted component.
*/
reagent.core.dom_node = (function reagent$core$dom_node(this$){
return reagent.dom.dom_node.call(null,this$);
});
/**
* Utility function that merges two maps, handling :class and :style
* specially, like React's transferPropsTo.
*/
reagent.core.merge_props = (function reagent$core$merge_props(defaults,props){
return reagent.impl.util.merge_props.call(null,defaults,props);
});
/**
* Render dirty components immediately to the DOM.
*
* Note that this may not work in event handlers, since React.js does
* batching of updates there.
*/
reagent.core.flush = (function reagent$core$flush(){
return reagent.impl.batching.flush.call(null);
});
/**
* Like clojure.core/atom, except that it keeps track of derefs.
* Reagent components that derefs one of these are automatically
* re-rendered.
*/
reagent.core.atom = (function reagent$core$atom(var_args){
var args26986 = [];
var len__26205__auto___26991 = arguments.length;
var i__26206__auto___26992 = (0);
while(true){
if((i__26206__auto___26992 < len__26205__auto___26991)){
args26986.push((arguments[i__26206__auto___26992]));
var G__26993 = (i__26206__auto___26992 + (1));
i__26206__auto___26992 = G__26993;
continue;
} else {
}
break;
}
var G__26990 = args26986.length;
switch (G__26990) {
case 1:
return reagent.core.atom.cljs$core$IFn$_invoke$arity$1((arguments[(0)]));
break;
default:
var argseq__26224__auto__ = (new cljs.core.IndexedSeq(args26986.slice((1)),(0),null));
return reagent.core.atom.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),argseq__26224__auto__);
}
});
reagent.core.atom.cljs$core$IFn$_invoke$arity$1 = (function (x){
return reagent.ratom.atom.call(null,x);
});
reagent.core.atom.cljs$core$IFn$_invoke$arity$variadic = (function (x,rest){
return cljs.core.apply.call(null,reagent.ratom.atom,x,rest);
});
reagent.core.atom.cljs$lang$applyTo = (function (seq26987){
var G__26988 = cljs.core.first.call(null,seq26987);
var seq26987__$1 = cljs.core.next.call(null,seq26987);
return reagent.core.atom.cljs$core$IFn$_invoke$arity$variadic(G__26988,seq26987__$1);
});
reagent.core.atom.cljs$lang$maxFixedArity = (1);
/**
* Takes a function and optional arguments, and returns a derefable
* containing the output of that function. If the function derefs
* Reagent atoms (or track, etc), the value will be updated whenever
* the atom changes.
*
* In other words, @(track foo bar) will produce the same result
* as (foo bar), but foo will only be called again when the atoms it
* depends on changes, and will only trigger updates of components when
* its result changes.
*
* track is lazy, i.e the function is only evaluated on deref.
*/
reagent.core.track = (function reagent$core$track(var_args){
var args__26212__auto__ = [];
var len__26205__auto___26997 = arguments.length;
var i__26206__auto___26998 = (0);
while(true){
if((i__26206__auto___26998 < len__26205__auto___26997)){
args__26212__auto__.push((arguments[i__26206__auto___26998]));
var G__26999 = (i__26206__auto___26998 + (1));
i__26206__auto___26998 = G__26999;
continue;
} else {
}
break;
}
var argseq__26213__auto__ = ((((1) < args__26212__auto__.length))?(new cljs.core.IndexedSeq(args__26212__auto__.slice((1)),(0),null)):null);
return reagent.core.track.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),argseq__26213__auto__);
});
reagent.core.track.cljs$core$IFn$_invoke$arity$variadic = (function (f,args){
if(cljs.core.ifn_QMARK_.call(null,f)){
} else {
throw (new Error("Assert failed: (ifn? f)"));
}
return reagent.ratom.make_track.call(null,f,args);
});
reagent.core.track.cljs$lang$maxFixedArity = (1);
reagent.core.track.cljs$lang$applyTo = (function (seq26995){
var G__26996 = cljs.core.first.call(null,seq26995);
var seq26995__$1 = cljs.core.next.call(null,seq26995);
return reagent.core.track.cljs$core$IFn$_invoke$arity$variadic(G__26996,seq26995__$1);
});
/**
* An eager version of track. The function passed is called
* immediately, and continues to be called when needed, until stopped
* with dispose!.
*/
reagent.core.track_BANG_ = (function reagent$core$track_BANG_(var_args){
var args__26212__auto__ = [];
var len__26205__auto___27002 = arguments.length;
var i__26206__auto___27003 = (0);
while(true){
if((i__26206__auto___27003 < len__26205__auto___27002)){
args__26212__auto__.push((arguments[i__26206__auto___27003]));
var G__27004 = (i__26206__auto___27003 + (1));
i__26206__auto___27003 = G__27004;
continue;
} else {
}
break;
}
var argseq__26213__auto__ = ((((1) < args__26212__auto__.length))?(new cljs.core.IndexedSeq(args__26212__auto__.slice((1)),(0),null)):null);
return reagent.core.track_BANG_.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),argseq__26213__auto__);
});
reagent.core.track_BANG_.cljs$core$IFn$_invoke$arity$variadic = (function (f,args){
if(cljs.core.ifn_QMARK_.call(null,f)){
} else {
throw (new Error("Assert failed: (ifn? f)"));
}
return reagent.ratom.make_track_BANG_.call(null,f,args);
});
reagent.core.track_BANG_.cljs$lang$maxFixedArity = (1);
reagent.core.track_BANG_.cljs$lang$applyTo = (function (seq27000){
var G__27001 = cljs.core.first.call(null,seq27000);
var seq27000__$1 = cljs.core.next.call(null,seq27000);
return reagent.core.track_BANG_.cljs$core$IFn$_invoke$arity$variadic(G__27001,seq27000__$1);
});
/**
* Stop the result of track! from updating.
*/
reagent.core.dispose_BANG_ = (function reagent$core$dispose_BANG_(x){
return reagent.ratom.dispose_BANG_.call(null,x);
});
/**
* Provide a combination of value and callback, that looks like an atom.
*
* The first argument can be any value, that will be returned when the
* result is deref'ed.
*
* The second argument should be a function, that is called with the
* optional extra arguments provided to wrap, and the new value of the
* resulting 'atom'.
*
* Use for example like this:
*
* (wrap (:foo @state)
* swap! state assoc :foo)
*
* Probably useful only for passing to child components.
*/
reagent.core.wrap = (function reagent$core$wrap(var_args){
var args__26212__auto__ = [];
var len__26205__auto___27008 = arguments.length;
var i__26206__auto___27009 = (0);
while(true){
if((i__26206__auto___27009 < len__26205__auto___27008)){
args__26212__auto__.push((arguments[i__26206__auto___27009]));
var G__27010 = (i__26206__auto___27009 + (1));
i__26206__auto___27009 = G__27010;
continue;
} else {
}
break;
}
var argseq__26213__auto__ = ((((2) < args__26212__auto__.length))?(new cljs.core.IndexedSeq(args__26212__auto__.slice((2)),(0),null)):null);
return reagent.core.wrap.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),(arguments[(1)]),argseq__26213__auto__);
});
reagent.core.wrap.cljs$core$IFn$_invoke$arity$variadic = (function (value,reset_fn,args){
if(cljs.core.ifn_QMARK_.call(null,reset_fn)){
} else {
throw (new Error("Assert failed: (ifn? reset-fn)"));
}
return reagent.ratom.make_wrapper.call(null,value,reset_fn,args);
});
reagent.core.wrap.cljs$lang$maxFixedArity = (2);
reagent.core.wrap.cljs$lang$applyTo = (function (seq27005){
var G__27006 = cljs.core.first.call(null,seq27005);
var seq27005__$1 = cljs.core.next.call(null,seq27005);
var G__27007 = cljs.core.first.call(null,seq27005__$1);
var seq27005__$2 = cljs.core.next.call(null,seq27005__$1);
return reagent.core.wrap.cljs$core$IFn$_invoke$arity$variadic(G__27006,G__27007,seq27005__$2);
});
/**
* Provide a cursor into a Reagent atom.
*
* Behaves like a Reagent atom but focuses updates and derefs to
* the specified path within the wrapped Reagent atom. e.g.,
* (let [c (cursor ra [:nested :content])]
* ... @c ;; equivalent to (get-in @ra [:nested :content])
* ... (reset! c 42) ;; equivalent to (swap! ra assoc-in [:nested :content] 42)
* ... (swap! c inc) ;; equivalence to (swap! ra update-in [:nested :content] inc)
* )
*
* The first parameter can also be a function, that should look
* something like this:
*
* (defn set-get
* ([k] (get-in @state k))
* ([k v] (swap! state assoc-in k v)))
*
* The function will be called with one argument the path passed to
* cursor when the cursor is deref'ed, and two arguments (path and
* new value) when the cursor is modified.
*
* Given that set-get function, (and that state is a Reagent atom, or
* another cursor) these cursors are equivalent:
* (cursor state [:foo]) and (cursor set-get [:foo]).
*
* Note that a cursor is lazy: its value will not change until it is
* used. This may be noticed with add-watch.
*/
reagent.core.cursor = (function reagent$core$cursor(src,path){
return reagent.ratom.cursor.call(null,src,path);
});
/**
* Swaps the value of a to be (apply f current-value-of-atom args).
*
* rswap! works like swap!, except that recursive calls to rswap! on
* the same atom are allowed and it always returns nil.
*/
reagent.core.rswap_BANG_ = (function reagent$core$rswap_BANG_(var_args){
var args__26212__auto__ = [];
var len__26205__auto___27017 = arguments.length;
var i__26206__auto___27018 = (0);
while(true){
if((i__26206__auto___27018 < len__26205__auto___27017)){
args__26212__auto__.push((arguments[i__26206__auto___27018]));
var G__27019 = (i__26206__auto___27018 + (1));
i__26206__auto___27018 = G__27019;
continue;
} else {
}
break;
}
var argseq__26213__auto__ = ((((2) < args__26212__auto__.length))?(new cljs.core.IndexedSeq(args__26212__auto__.slice((2)),(0),null)):null);
return reagent.core.rswap_BANG_.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),(arguments[(1)]),argseq__26213__auto__);
});
reagent.core.rswap_BANG_.cljs$core$IFn$_invoke$arity$variadic = (function (a,f,args){
if(((!((a == null)))?((((a.cljs$lang$protocol_mask$partition1$ & (16384))) || (a.cljs$core$IAtom$))?true:(((!a.cljs$lang$protocol_mask$partition1$))?cljs.core.native_satisfies_QMARK_.call(null,cljs.core.IAtom,a):false)):cljs.core.native_satisfies_QMARK_.call(null,cljs.core.IAtom,a))){
} else {
throw (new Error("Assert failed: (satisfies? IAtom a)"));
}
if(cljs.core.ifn_QMARK_.call(null,f)){
} else {
throw (new Error("Assert failed: (ifn? f)"));
}
if(cljs.core.truth_(a.rswapping)){
(function (){var or__25130__auto__ = a.rswapfs;
if(cljs.core.truth_(or__25130__auto__)){
return or__25130__auto__;
} else {
return a.rswapfs = [];
}
})().push((function (p1__27011_SHARP_){
return cljs.core.apply.call(null,f,p1__27011_SHARP_,args);
}));
} else {
a.rswapping = true;
try{cljs.core.swap_BANG_.call(null,a,(function (state){
var s = cljs.core.apply.call(null,f,state,args);
while(true){
var temp__4659__auto__ = (function (){var G__27016 = a.rswapfs;
if((G__27016 == null)){
return null;
} else {
return G__27016.shift();
}
})();
if((temp__4659__auto__ == null)){
return s;
} else {
var sf = temp__4659__auto__;
var G__27020 = sf.call(null,s);
s = G__27020;
continue;
}
break;
}
}));
}finally {a.rswapping = false;
}}
return null;
});
reagent.core.rswap_BANG_.cljs$lang$maxFixedArity = (2);
reagent.core.rswap_BANG_.cljs$lang$applyTo = (function (seq27012){
var G__27013 = cljs.core.first.call(null,seq27012);
var seq27012__$1 = cljs.core.next.call(null,seq27012);
var G__27014 = cljs.core.first.call(null,seq27012__$1);
var seq27012__$2 = cljs.core.next.call(null,seq27012__$1);
return reagent.core.rswap_BANG_.cljs$core$IFn$_invoke$arity$variadic(G__27013,G__27014,seq27012__$2);
});
/**
* Run f using requestAnimationFrame or equivalent.
*
* f will be called just before components are rendered.
*/
reagent.core.next_tick = (function reagent$core$next_tick(f){
return reagent.impl.batching.do_before_flush.call(null,f);
});
/**
* Run f using requestAnimationFrame or equivalent.
*
* f will be called just after any queued renders in the next animation
* frame (and even if no renders actually occur).
*/
reagent.core.after_render = (function reagent$core$after_render(f){
return reagent.impl.batching.do_after_render.call(null,f);
});
/**
* Works just like clojure.core/partial, except that it is an IFn, and
* the result can be compared with =
*/
reagent.core.partial = (function reagent$core$partial(var_args){
var args__26212__auto__ = [];
var len__26205__auto___27023 = arguments.length;
var i__26206__auto___27024 = (0);
while(true){
if((i__26206__auto___27024 < len__26205__auto___27023)){
args__26212__auto__.push((arguments[i__26206__auto___27024]));
var G__27025 = (i__26206__auto___27024 + (1));
i__26206__auto___27024 = G__27025;
continue;
} else {
}
break;
}
var argseq__26213__auto__ = ((((1) < args__26212__auto__.length))?(new cljs.core.IndexedSeq(args__26212__auto__.slice((1)),(0),null)):null);
return reagent.core.partial.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),argseq__26213__auto__);
});
reagent.core.partial.cljs$core$IFn$_invoke$arity$variadic = (function (f,args){
return (new reagent.impl.util.partial_ifn(f,args,null));
});
reagent.core.partial.cljs$lang$maxFixedArity = (1);
reagent.core.partial.cljs$lang$applyTo = (function (seq27021){
var G__27022 = cljs.core.first.call(null,seq27021);
var seq27021__$1 = cljs.core.next.call(null,seq27021);
return reagent.core.partial.cljs$core$IFn$_invoke$arity$variadic(G__27022,seq27021__$1);
});
reagent.core.component_path = (function reagent$core$component_path(c){
return reagent.impl.component.component_path.call(null,c);
});
//# sourceMappingURL=core.js.map?rel=1603199189067

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,27 @@
(ns reagent.debug
(:require-macros [reagent.debug]))
(def ^:const has-console (exists? js/console))
(def ^boolean tracking false)
(defonce warnings (atom nil))
(defonce track-console
(let [o #js{}]
(set! (.-warn o)
(fn [& args]
(swap! warnings update-in [:warn] conj (apply str args))))
(set! (.-error o)
(fn [& args]
(swap! warnings update-in [:error] conj (apply str args))))
o))
(defn track-warnings [f]
(set! tracking true)
(reset! warnings nil)
(f)
(let [warns @warnings]
(reset! warnings nil)
(set! tracking false)
warns))

View file

@ -0,0 +1 @@
{:rename-macros {}, :renames {}, :use-macros {}, :excludes #{}, :name reagent.debug, :imports nil, :requires nil, :uses nil, :defs {has-console {:name reagent.debug/has-console, :file "docs/js/compiled/out/reagent/debug.cljs", :line 4, :column 1, :end-line 4, :end-column 25, :const true, :meta {:file "/Users/simon/workspace/swinging-needle-meter/docs/js/compiled/out/reagent/debug.cljs", :line 4, :column 14, :end-line 4, :end-column 25, :const true}}, tracking {:name reagent.debug/tracking, :file "docs/js/compiled/out/reagent/debug.cljs", :line 6, :column 1, :end-line 6, :end-column 23, :tag boolean, :meta {:file "/Users/simon/workspace/swinging-needle-meter/docs/js/compiled/out/reagent/debug.cljs", :line 6, :column 15, :end-line 6, :end-column 23, :tag boolean}}, warnings {:name reagent.debug/warnings, :file "docs/js/compiled/out/reagent/debug.cljs", :line 8, :column 1, :end-line 8, :end-column 18, :meta {:file "/Users/simon/workspace/swinging-needle-meter/docs/js/compiled/out/reagent/debug.cljs", :line 8, :column 10, :end-line 8, :end-column 18}}, track-console {:name reagent.debug/track-console, :file "docs/js/compiled/out/reagent/debug.cljs", :line 10, :column 1, :end-line 10, :end-column 23, :meta {:file "/Users/simon/workspace/swinging-needle-meter/docs/js/compiled/out/reagent/debug.cljs", :line 10, :column 10, :end-line 10, :end-column 23}}, track-warnings {:protocol-inline nil, :meta {:file "/Users/simon/workspace/swinging-needle-meter/docs/js/compiled/out/reagent/debug.cljs", :line 20, :column 7, :end-line 20, :end-column 21, :arglists (quote ([f]))}, :name reagent.debug/track-warnings, :variadic false, :file "docs/js/compiled/out/reagent/debug.cljs", :end-column 21, :method-params ([f]), :protocol-impl nil, :arglists-meta (nil nil), :column 1, :line 20, :end-line 20, :max-fixed-arity 1, :fn-var true, :arglists (quote ([f]))}}, :require-macros {reagent.debug reagent.debug}, :cljs.analyzer/constants {:seen #{:warn :error}, :order [:warn :error]}, :doc nil}

View file

@ -0,0 +1,79 @@
// Compiled by ClojureScript 1.9.229 {}
goog.provide('reagent.debug');
goog.require('cljs.core');
reagent.debug.has_console = typeof console !== 'undefined';
reagent.debug.tracking = false;
if(typeof reagent.debug.warnings !== 'undefined'){
} else {
reagent.debug.warnings = cljs.core.atom.call(null,null);
}
if(typeof reagent.debug.track_console !== 'undefined'){
} else {
reagent.debug.track_console = (function (){var o = ({});
o.warn = ((function (o){
return (function() {
var G__26360__delegate = function (args){
return cljs.core.swap_BANG_.call(null,reagent.debug.warnings,cljs.core.update_in,new cljs.core.PersistentVector(null, 1, 5, cljs.core.PersistentVector.EMPTY_NODE, [new cljs.core.Keyword(null,"warn","warn",-436710552)], null),cljs.core.conj,cljs.core.apply.call(null,cljs.core.str,args));
};
var G__26360 = function (var_args){
var args = null;
if (arguments.length > 0) {
var G__26361__i = 0, G__26361__a = new Array(arguments.length - 0);
while (G__26361__i < G__26361__a.length) {G__26361__a[G__26361__i] = arguments[G__26361__i + 0]; ++G__26361__i;}
args = new cljs.core.IndexedSeq(G__26361__a,0);
}
return G__26360__delegate.call(this,args);};
G__26360.cljs$lang$maxFixedArity = 0;
G__26360.cljs$lang$applyTo = (function (arglist__26362){
var args = cljs.core.seq(arglist__26362);
return G__26360__delegate(args);
});
G__26360.cljs$core$IFn$_invoke$arity$variadic = G__26360__delegate;
return G__26360;
})()
;})(o))
;
o.error = ((function (o){
return (function() {
var G__26363__delegate = function (args){
return cljs.core.swap_BANG_.call(null,reagent.debug.warnings,cljs.core.update_in,new cljs.core.PersistentVector(null, 1, 5, cljs.core.PersistentVector.EMPTY_NODE, [new cljs.core.Keyword(null,"error","error",-978969032)], null),cljs.core.conj,cljs.core.apply.call(null,cljs.core.str,args));
};
var G__26363 = function (var_args){
var args = null;
if (arguments.length > 0) {
var G__26364__i = 0, G__26364__a = new Array(arguments.length - 0);
while (G__26364__i < G__26364__a.length) {G__26364__a[G__26364__i] = arguments[G__26364__i + 0]; ++G__26364__i;}
args = new cljs.core.IndexedSeq(G__26364__a,0);
}
return G__26363__delegate.call(this,args);};
G__26363.cljs$lang$maxFixedArity = 0;
G__26363.cljs$lang$applyTo = (function (arglist__26365){
var args = cljs.core.seq(arglist__26365);
return G__26363__delegate(args);
});
G__26363.cljs$core$IFn$_invoke$arity$variadic = G__26363__delegate;
return G__26363;
})()
;})(o))
;
return o;
})();
}
reagent.debug.track_warnings = (function reagent$debug$track_warnings(f){
reagent.debug.tracking = true;
cljs.core.reset_BANG_.call(null,reagent.debug.warnings,null);
f.call(null);
var warns = cljs.core.deref.call(null,reagent.debug.warnings);
cljs.core.reset_BANG_.call(null,reagent.debug.warnings,null);
reagent.debug.tracking = false;
return warns;
});
//# sourceMappingURL=debug.js.map?rel=1603199186726

View file

@ -0,0 +1 @@
{"version":3,"file":"\/Users\/simon\/workspace\/swinging-needle-meter\/docs\/js\/compiled\/out\/reagent\/debug.js","sources":["debug.cljs?rel=1603199186728"],"lineCount":79,"mappings":";AAAA;;AAGA,AAAaA,4BAAY,OAASC;AAElC,yBAAA,zBAAcC;AAEd,GAAA,OAASC;AAAT;AAAA,AAAA,AAASA,yBAAS,yBAAA,zBAACC;;AAEnB,GAAA,OAASC;AAAT;AAAA,AAAA,AAASA,8BACP,qBAAA,JAAMC;AAAN,AACE,AAAM,AAAQA,SACR;;mCAAOC;AAAP,AACE,iFAAA,mFAAA,7JAACC,+BAAML,uBAASM,oKAAkBC,eAAK,AAACC,0BAAMC,cAAIL;;;IAD7CA;;;;EAAAA;;oCAAAA;;;IAAAA;0BAAAA;;;;;;;;AAEb,AAAM,AAASD,UACT;;mCAAOC;AAAP,AACE,iFAAA,mFAAA,7JAACC,+BAAML,uBAASM,sKAAmBC,eAAK,AAACC,0BAAMC,cAAIL;;;IAD9CA;;;;EAAAA;;oCAAAA;;;IAAAA;0BAAAA;;;;;;;;AAEbD;;;AAEJ,+BAAA,\/BAAMO,sEAAgBC;AAAtB,AACE,yBAAA,zBAAMZ;;AACN,uDAAA,vDAACa,gCAAOZ;;AACR,AAACW;;AACD,YAAA,AAAAE,RAAMC,kCAAOd;AAAb,AACE,uDAAA,vDAACY,gCAAOZ;;AACR,yBAAA,zBAAMD;;AACNe","names":["reagent.debug\/has-console","js\/console","reagent.debug\/tracking","reagent.debug\/warnings","cljs.core\/atom","reagent.debug\/track-console","o","args","cljs.core\/swap!","cljs.core\/update-in","cljs.core\/conj","cljs.core\/apply","cljs.core\/str","reagent.debug\/track-warnings","f","cljs.core\/reset!","cljs.core\/deref","warns"]}

View file

@ -0,0 +1,78 @@
(ns reagent.dom
(:require [cljsjs.react.dom]
[reagent.impl.util :as util]
[reagent.impl.template :as tmpl]
[reagent.impl.batching :as batch]
[reagent.ratom :as ratom]
[reagent.debug :refer-macros [dbg]]
[reagent.interop :refer-macros [$ $!]]))
(defonce ^:private imported nil)
(defn module []
(cond
(some? imported) imported
(exists? js/ReactDOM) (set! imported js/ReactDOM)
(exists? js/require) (or (set! imported (js/require "react-dom"))
(throw (js/Error. "require('react-dom') failed")))
:else
(throw (js/Error. "js/ReactDOM is missing"))))
(defonce ^:private roots (atom {}))
(defn- unmount-comp [container]
(swap! roots dissoc container)
($ (module) unmountComponentAtNode container))
(defn- render-comp [comp container callback]
(binding [util/*always-update* true]
(->> ($ (module) render (comp) container
(fn []
(binding [util/*always-update* false]
(swap! roots assoc container [comp container])
(batch/flush-after-render)
(if (some? callback)
(callback))))))))
(defn- re-render-component [comp container]
(render-comp comp container nil))
(defn render
"Render a Reagent component into the DOM. The first argument may be
either a vector (using Reagent's Hiccup syntax), or a React element. The second argument should be a DOM node.
Optionally takes a callback that is called when the component is in place.
Returns the mounted component instance."
([comp container]
(render comp container nil))
([comp container callback]
(ratom/flush!)
(let [f (fn []
(tmpl/as-element (if (fn? comp) (comp) comp)))]
(render-comp f container callback))))
(defn unmount-component-at-node [container]
(unmount-comp container))
(defn dom-node
"Returns the root DOM node of a mounted component."
[this]
($ (module) findDOMNode this))
(defn force-update-all
"Force re-rendering of all mounted Reagent components. This is
probably only useful in a development environment, when you want to
update components in response to some dynamic changes to code.
Note that force-update-all may not update root components. This
happens if a component 'foo' is mounted with `(render [foo])` (since
functions are passed by value, and not by reference, in
ClojureScript). To get around this you'll have to introduce a layer
of indirection, for example by using `(render [#'foo])` instead."
[]
(ratom/flush!)
(doseq [v (vals @roots)]
(apply re-render-component v))
"Updated")

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,205 @@
// Compiled by ClojureScript 1.9.229 {}
goog.provide('reagent.dom');
goog.require('cljs.core');
goog.require('reagent.impl.util');
goog.require('reagent.interop');
goog.require('reagent.ratom');
goog.require('reagent.impl.template');
goog.require('reagent.impl.batching');
goog.require('cljsjs.react.dom');
goog.require('reagent.debug');
if(typeof reagent.dom.imported !== 'undefined'){
} else {
reagent.dom.imported = null;
}
reagent.dom.module = (function reagent$dom$module(){
if(cljs.core.some_QMARK_.call(null,reagent.dom.imported)){
return reagent.dom.imported;
} else {
if(typeof ReactDOM !== 'undefined'){
return reagent.dom.imported = ReactDOM;
} else {
if(typeof require !== 'undefined'){
var or__25130__auto__ = reagent.dom.imported = require("react-dom");
if(cljs.core.truth_(or__25130__auto__)){
return or__25130__auto__;
} else {
throw (new Error("require('react-dom') failed"));
}
} else {
throw (new Error("js/ReactDOM is missing"));
}
}
}
});
if(typeof reagent.dom.roots !== 'undefined'){
} else {
reagent.dom.roots = cljs.core.atom.call(null,cljs.core.PersistentArrayMap.EMPTY);
}
reagent.dom.unmount_comp = (function reagent$dom$unmount_comp(container){
cljs.core.swap_BANG_.call(null,reagent.dom.roots,cljs.core.dissoc,container);
return (reagent.dom.module.call(null)["unmountComponentAtNode"])(container);
});
reagent.dom.render_comp = (function reagent$dom$render_comp(comp,container,callback){
var _STAR_always_update_STAR_26906 = reagent.impl.util._STAR_always_update_STAR_;
reagent.impl.util._STAR_always_update_STAR_ = true;
try{return (reagent.dom.module.call(null)["render"])(comp.call(null),container,((function (_STAR_always_update_STAR_26906){
return (function (){
var _STAR_always_update_STAR_26907 = reagent.impl.util._STAR_always_update_STAR_;
reagent.impl.util._STAR_always_update_STAR_ = false;
try{cljs.core.swap_BANG_.call(null,reagent.dom.roots,cljs.core.assoc,container,new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [comp,container], null));
reagent.impl.batching.flush_after_render.call(null);
if(cljs.core.some_QMARK_.call(null,callback)){
return callback.call(null);
} else {
return null;
}
}finally {reagent.impl.util._STAR_always_update_STAR_ = _STAR_always_update_STAR_26907;
}});})(_STAR_always_update_STAR_26906))
);
}finally {reagent.impl.util._STAR_always_update_STAR_ = _STAR_always_update_STAR_26906;
}});
reagent.dom.re_render_component = (function reagent$dom$re_render_component(comp,container){
return reagent.dom.render_comp.call(null,comp,container,null);
});
/**
* Render a Reagent component into the DOM. The first argument may be
* either a vector (using Reagent's Hiccup syntax), or a React element. The second argument should be a DOM node.
*
* Optionally takes a callback that is called when the component is in place.
*
* Returns the mounted component instance.
*/
reagent.dom.render = (function reagent$dom$render(var_args){
var args26908 = [];
var len__26205__auto___26911 = arguments.length;
var i__26206__auto___26912 = (0);
while(true){
if((i__26206__auto___26912 < len__26205__auto___26911)){
args26908.push((arguments[i__26206__auto___26912]));
var G__26913 = (i__26206__auto___26912 + (1));
i__26206__auto___26912 = G__26913;
continue;
} else {
}
break;
}
var G__26910 = args26908.length;
switch (G__26910) {
case 2:
return reagent.dom.render.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)]));
break;
case 3:
return reagent.dom.render.cljs$core$IFn$_invoke$arity$3((arguments[(0)]),(arguments[(1)]),(arguments[(2)]));
break;
default:
throw (new Error([cljs.core.str("Invalid arity: "),cljs.core.str(args26908.length)].join('')));
}
});
reagent.dom.render.cljs$core$IFn$_invoke$arity$2 = (function (comp,container){
return reagent.dom.render.call(null,comp,container,null);
});
reagent.dom.render.cljs$core$IFn$_invoke$arity$3 = (function (comp,container,callback){
reagent.ratom.flush_BANG_.call(null);
var f = (function (){
return reagent.impl.template.as_element.call(null,((cljs.core.fn_QMARK_.call(null,comp))?comp.call(null):comp));
});
return reagent.dom.render_comp.call(null,f,container,callback);
});
reagent.dom.render.cljs$lang$maxFixedArity = 3;
reagent.dom.unmount_component_at_node = (function reagent$dom$unmount_component_at_node(container){
return reagent.dom.unmount_comp.call(null,container);
});
/**
* Returns the root DOM node of a mounted component.
*/
reagent.dom.dom_node = (function reagent$dom$dom_node(this$){
return (reagent.dom.module.call(null)["findDOMNode"])(this$);
});
/**
* Force re-rendering of all mounted Reagent components. This is
* probably only useful in a development environment, when you want to
* update components in response to some dynamic changes to code.
*
* Note that force-update-all may not update root components. This
* happens if a component 'foo' is mounted with `(render [foo])` (since
* functions are passed by value, and not by reference, in
* ClojureScript). To get around this you'll have to introduce a layer
* of indirection, for example by using `(render [#'foo])` instead.
*/
reagent.dom.force_update_all = (function reagent$dom$force_update_all(){
reagent.ratom.flush_BANG_.call(null);
var seq__26919_26923 = cljs.core.seq.call(null,cljs.core.vals.call(null,cljs.core.deref.call(null,reagent.dom.roots)));
var chunk__26920_26924 = null;
var count__26921_26925 = (0);
var i__26922_26926 = (0);
while(true){
if((i__26922_26926 < count__26921_26925)){
var v_26927 = cljs.core._nth.call(null,chunk__26920_26924,i__26922_26926);
cljs.core.apply.call(null,reagent.dom.re_render_component,v_26927);
var G__26928 = seq__26919_26923;
var G__26929 = chunk__26920_26924;
var G__26930 = count__26921_26925;
var G__26931 = (i__26922_26926 + (1));
seq__26919_26923 = G__26928;
chunk__26920_26924 = G__26929;
count__26921_26925 = G__26930;
i__26922_26926 = G__26931;
continue;
} else {
var temp__4657__auto___26932 = cljs.core.seq.call(null,seq__26919_26923);
if(temp__4657__auto___26932){
var seq__26919_26933__$1 = temp__4657__auto___26932;
if(cljs.core.chunked_seq_QMARK_.call(null,seq__26919_26933__$1)){
var c__25941__auto___26934 = cljs.core.chunk_first.call(null,seq__26919_26933__$1);
var G__26935 = cljs.core.chunk_rest.call(null,seq__26919_26933__$1);
var G__26936 = c__25941__auto___26934;
var G__26937 = cljs.core.count.call(null,c__25941__auto___26934);
var G__26938 = (0);
seq__26919_26923 = G__26935;
chunk__26920_26924 = G__26936;
count__26921_26925 = G__26937;
i__26922_26926 = G__26938;
continue;
} else {
var v_26939 = cljs.core.first.call(null,seq__26919_26933__$1);
cljs.core.apply.call(null,reagent.dom.re_render_component,v_26939);
var G__26940 = cljs.core.next.call(null,seq__26919_26933__$1);
var G__26941 = null;
var G__26942 = (0);
var G__26943 = (0);
seq__26919_26923 = G__26940;
chunk__26920_26924 = G__26941;
count__26921_26925 = G__26942;
i__26922_26926 = G__26943;
continue;
}
} else {
}
}
break;
}
return "Updated";
});
//# sourceMappingURL=dom.js.map?rel=1603199188899

View file

@ -0,0 +1 @@
{"version":3,"file":"\/Users\/simon\/workspace\/swinging-needle-meter\/docs\/js\/compiled\/out\/reagent\/dom.js","sources":["dom.cljs?rel=1603199188900"],"lineCount":205,"mappings":";AAAA;;;;;;;;;AASA,GAAA,OAAmBA;AAAnB;AAAA,AAAA,uBAAA,vBAAmBA;;AAEnB,qBAAA,rBAAMC;AAAN,AACE,GACE,AAACC,gCAAMF;AAAUA;;AADnB,GAEE,OAASG;AAAa,OAAMH,uBAASG;;AAFvC,GAGE,OAASC;AAAY,IAAAC,oBAAI,AAAML,uBAAS,QAAA,RAACI;AAApB,AAAA,oBAAAC;AAAAA;;AACI,MAAO,KAAAC,MAAA;;;AAJlC,AAME,MAAO,KAAAA,MAAA;;;;;;AAGX,GAAA,OAAmBC;AAAnB;AAAA,AAAA,AAAmBA,oBAAM,yBAAA,zBAACC;;AAE1B,2BAAA,3BAAOC,8DAAcC;AAArB,AACE,AAACC,+BAAMJ,kBAAMK,iBAAOF;;AACpB,OAAA,+BAAA,9BAAG,AAACT,yDAA+BS;;AAErC,0BAAA,1BAAOG,4DAAaC,KAAKJ,UAAUK;AAAnC,AACE,IAAAC,iCAAUC;AAAV,AAAA,8CAAA,9CAAUA;;AAAV,IAAA,AACO,OAAA,+BAAA,9BAAG,AAAChB,yCAAe,AAACa,gBAAMJ,UACvB;;AAAA,AACE,IAAAQ,iCAAUD;AAAV,AAAA,8CAAA,9CAAUA;;AAAV,IAAA,AACE,2EAAA,3EAACN,+BAAMJ,kBAAMY,gBAAMT,6FAAWI,KAAKJ;;AACnC,AAACU;;AACD,GAAI,AAAClB,gCAAMa;AACT,OAACA;;AADH;;UAHF,AAAA,8CAAAG,9CAAUD;;;UAHtB,AAAA,8CAAAD,9CAAUC;;AASZ,kCAAA,lCAAOI,4EAAqBP,KAAKJ;AAAjC,AACE,wDAAA,jDAACG,kCAAYC,KAAKJ;;AAEpB,AAAA;;;;;;;;qBAAA,6BAAAY,lDAAMK;AAAN,AAAA,IAAAJ,YAAA;AAAA,AAAA,IAAAC,2BAAA,AAAA;AAAA,AAAA,IAAAC,yBAAA;;AAAA,AAAA,GAAA,CAAAA,yBAAAD;AAAA,AAAA,AAAAD,eAAA,CAAA,UAAAE;;AAAA,eAAA,CAAAA,yBAAA;;;;AAAA;;;;AAAA,IAAAC,WAAA,AAAAH;AAAA,AAAA,QAAAG;KAAA;AAAA,OAAAC,iDAAA,CAAA,UAAA,MAAA,CAAA,UAAA;;;KAAA;AAAA,OAAAA,iDAAA,CAAA,UAAA,MAAA,CAAA,UAAA,MAAA,CAAA,UAAA;;;;AAAA,MAAA,KAAArB,MAAA,eAAA,iCAAA,AAAAiB;;;;;AAAA,AAAA,mDAAA,nDAAMI,8DAOFb,KAAKJ;AAPT,AAQG,mDAAA,5CAACiB,6BAAOb,KAAKJ;;;AARhB,AAAA,mDAAA,nDAAMiB,8DASFb,KAAKJ,UAAUK;AATnB,AAUG,AAACa;;AACD,IAAMC,IAAE;AAAA,AACE,OAACC,2CAAgB,EAAI,AAACC,8BAAIjB,OAAM,AAACA,gBAAMA;;AADjD,AAEE,OAACD,kCAAYgB,EAAEnB,UAAUK;;;AAb9B,AAAA,6CAAA,7CAAMY;;AAAN,AAeA,wCAAA,xCAAMK,wFAA2BtB;AAAjC,AACE,OAACD,mCAAaC;;AAEhB;;;uBAAA,vBAAMuB,sDAEHC;AAFH,AAGE,OAAA,+BAAA,9BAAG,AAACjC,8CAAoBiC;;AAE1B;;;;;;;;;;;+BAAA,\/BAAMC;AAAN,AAWE,AAACP;;AACD,IAAAQ,mBAAA,AAAAC,wBAAU,yBAAA,AAAAc,zBAACC,mDAAM7C;IAAjB+B,qBAAA;IAAAC,qBAAA;IAAAC,iBAAA;;AAAA,AAAA,GAAA,AAAA,CAAAA,iBAAAD;AAAA,cAAA,AAAAE,yBAAAH,mBAAAE,tDAAQU;AAAR,AAAA,AACE,AAACG,0BAAMhC,gCAAoB6B;;AAD7B,eAAAd;eAAAE;eAAAC;eAAA,CAAAC,iBAAA;;;;;;;AAAA,IAAAE,2BAAA,AAAAL,wBAAAD;AAAA,AAAA,GAAAM;AAAA,AAAA,IAAAN,uBAAAM;AAAA,AAAA,GAAA,AAAAC,uCAAAP;AAAA,IAAAQ,yBAAA,AAAAC,gCAAAT;AAAA,AAAA,eAAA,AAAAU,+BAAAV;eAAAQ;eAAA,AAAAG,0BAAAH;eAAA;;;;;;;AAAA,cAAA,AAAAI,0BAAAZ,pCAAQc;AAAR,AAAA,AACE,AAACG,0BAAMhC,gCAAoB6B;;AAD7B,eAAA,AAAAD,yBAAAb;eAAA;eAAA;eAAA;;;;;;;;AAAA;;;;;AAZF","names":["reagent.dom\/imported","reagent.dom\/module","cljs.core\/some?","js\/ReactDOM","js\/require","or__25130__auto__","js\/Error","reagent.dom\/roots","cljs.core\/atom","reagent.dom\/unmount-comp","container","cljs.core\/swap!","cljs.core\/dissoc","reagent.dom\/render-comp","comp","callback","*always-update*26906","reagent.impl.util\/*always-update*","*always-update*26907","cljs.core\/assoc","reagent.impl.batching\/flush-after-render","reagent.dom\/re-render-component","var_args","args26908","len__26205__auto__","i__26206__auto__","G__26910","reagent.dom\/render","reagent.ratom\/flush!","f","reagent.impl.template\/as-element","cljs.core\/fn?","reagent.dom\/unmount-component-at-node","reagent.dom\/dom-node","this","reagent.dom\/force-update-all","seq__26919","cljs.core\/seq","chunk__26920","count__26921","i__26922","cljs.core\/-nth","temp__4657__auto__","cljs.core\/chunked-seq?","c__25941__auto__","cljs.core\/chunk-first","cljs.core\/chunk-rest","cljs.core\/count","cljs.core\/first","cljs.core\/next","v","cljs.core\/deref","cljs.core\/vals","cljs.core\/apply"]}

View file

@ -0,0 +1,33 @@
(ns reagent.dom.server
(:require [cljsjs.react.dom.server]
[reagent.impl.util :as util]
[reagent.impl.template :as tmpl]
[reagent.ratom :as ratom]
[reagent.interop :refer-macros [$ $!]]))
(defonce ^:private imported nil)
(defn module []
(cond
(some? imported) imported
(exists? js/ReactDOMServer) (set! imported js/ReactDOMServer)
(exists? js/require) (or (set! imported (js/require "react-dom/server"))
(throw (js/Error.
"require('react-dom/server') failed")))
:else
(throw (js/Error. "js/ReactDOMServer is missing"))))
(defn render-to-string
"Turns a component into an HTML string."
[component]
(ratom/flush!)
(binding [util/*non-reactive* true]
($ (module) renderToString (tmpl/as-element component))))
(defn render-to-static-markup
"Turns a component into an HTML string, without data-react-id attributes, etc."
[component]
(ratom/flush!)
(binding [util/*non-reactive* true]
($ (module) renderToStaticMarkup (tmpl/as-element component))))

View file

@ -0,0 +1 @@
{:rename-macros {}, :renames {}, :use-macros {$! reagent.interop, $ reagent.interop}, :excludes #{}, :name reagent.dom.server, :imports nil, :requires {cljsjs.react.dom.server cljsjs.react.dom.server, util reagent.impl.util, reagent.impl.util reagent.impl.util, tmpl reagent.impl.template, reagent.impl.template reagent.impl.template, ratom reagent.ratom, reagent.ratom reagent.ratom, reagent.interop reagent.interop}, :uses nil, :defs {imported {:name reagent.dom.server/imported, :file "docs/js/compiled/out/reagent/dom/server.cljs", :line 8, :column 1, :end-line 8, :end-column 28, :private true, :meta {:file "/Users/simon/workspace/swinging-needle-meter/docs/js/compiled/out/reagent/dom/server.cljs", :line 8, :column 20, :end-line 8, :end-column 28, :private true}}, module {:protocol-inline nil, :meta {:file "/Users/simon/workspace/swinging-needle-meter/docs/js/compiled/out/reagent/dom/server.cljs", :line 10, :column 7, :end-line 10, :end-column 13, :arglists (quote ([]))}, :name reagent.dom.server/module, :variadic false, :file "docs/js/compiled/out/reagent/dom/server.cljs", :end-column 13, :method-params ([]), :protocol-impl nil, :arglists-meta (nil nil), :column 1, :line 10, :end-line 10, :max-fixed-arity 0, :fn-var true, :arglists (quote ([]))}, render-to-string {:protocol-inline nil, :meta {:file "/Users/simon/workspace/swinging-needle-meter/docs/js/compiled/out/reagent/dom/server.cljs", :line 21, :column 7, :end-line 21, :end-column 23, :arglists (quote ([component])), :doc "Turns a component into an HTML string."}, :name reagent.dom.server/render-to-string, :variadic false, :file "docs/js/compiled/out/reagent/dom/server.cljs", :end-column 23, :method-params ([component]), :protocol-impl nil, :arglists-meta (nil nil), :column 1, :line 21, :end-line 21, :max-fixed-arity 1, :fn-var true, :arglists (quote ([component])), :doc "Turns a component into an HTML string."}, render-to-static-markup {:protocol-inline nil, :meta {:file "/Users/simon/workspace/swinging-needle-meter/docs/js/compiled/out/reagent/dom/server.cljs", :line 28, :column 7, :end-line 28, :end-column 30, :arglists (quote ([component])), :doc "Turns a component into an HTML string, without data-react-id attributes, etc."}, :name reagent.dom.server/render-to-static-markup, :variadic false, :file "docs/js/compiled/out/reagent/dom/server.cljs", :end-column 30, :method-params ([component]), :protocol-impl nil, :arglists-meta (nil nil), :column 1, :line 28, :end-line 28, :max-fixed-arity 1, :fn-var true, :arglists (quote ([component])), :doc "Turns a component into an HTML string, without data-react-id attributes, etc."}}, :require-macros {ratom reagent.ratom, reagent.ratom reagent.ratom, reagent.interop reagent.interop}, :cljs.analyzer/constants {:seen #{:else}, :order [:else]}, :doc nil}

View file

@ -0,0 +1,59 @@
// Compiled by ClojureScript 1.9.229 {}
goog.provide('reagent.dom.server');
goog.require('cljs.core');
goog.require('cljsjs.react.dom.server');
goog.require('reagent.impl.util');
goog.require('reagent.impl.template');
goog.require('reagent.ratom');
goog.require('reagent.interop');
if(typeof reagent.dom.server.imported !== 'undefined'){
} else {
reagent.dom.server.imported = null;
}
reagent.dom.server.module = (function reagent$dom$server$module(){
if(cljs.core.some_QMARK_.call(null,reagent.dom.server.imported)){
return reagent.dom.server.imported;
} else {
if(typeof ReactDOMServer !== 'undefined'){
return reagent.dom.server.imported = ReactDOMServer;
} else {
if(typeof require !== 'undefined'){
var or__25130__auto__ = reagent.dom.server.imported = require("react-dom/server");
if(cljs.core.truth_(or__25130__auto__)){
return or__25130__auto__;
} else {
throw (new Error("require('react-dom/server') failed"));
}
} else {
throw (new Error("js/ReactDOMServer is missing"));
}
}
}
});
/**
* Turns a component into an HTML string.
*/
reagent.dom.server.render_to_string = (function reagent$dom$server$render_to_string(component){
reagent.ratom.flush_BANG_.call(null);
var _STAR_non_reactive_STAR_26899 = reagent.impl.util._STAR_non_reactive_STAR_;
reagent.impl.util._STAR_non_reactive_STAR_ = true;
try{return (reagent.dom.server.module.call(null)["renderToString"])(reagent.impl.template.as_element.call(null,component));
}finally {reagent.impl.util._STAR_non_reactive_STAR_ = _STAR_non_reactive_STAR_26899;
}});
/**
* Turns a component into an HTML string, without data-react-id attributes, etc.
*/
reagent.dom.server.render_to_static_markup = (function reagent$dom$server$render_to_static_markup(component){
reagent.ratom.flush_BANG_.call(null);
var _STAR_non_reactive_STAR_26901 = reagent.impl.util._STAR_non_reactive_STAR_;
reagent.impl.util._STAR_non_reactive_STAR_ = true;
try{return (reagent.dom.server.module.call(null)["renderToStaticMarkup"])(reagent.impl.template.as_element.call(null,component));
}finally {reagent.impl.util._STAR_non_reactive_STAR_ = _STAR_non_reactive_STAR_26901;
}});
//# sourceMappingURL=server.js.map?rel=1603199188840

View file

@ -0,0 +1 @@
{"version":3,"file":"\/Users\/simon\/workspace\/swinging-needle-meter\/docs\/js\/compiled\/out\/reagent\/dom\/server.js","sources":["server.cljs?rel=1603199188841"],"lineCount":59,"mappings":";AAAA;;;;;;;AAOA,GAAA,OAAmBA;AAAnB;AAAA,AAAA,8BAAA,9BAAmBA;;AAEnB,4BAAA,5BAAMC;AAAN,AACE,GACE,AAACC,gCAAMF;AAAUA;;AADnB,GAEE,OAASG;AAAmB,OAAMH,8BAASG;;AAF7C,GAGE,OAASC;AAAY,IAAAC,oBAAI,AAAML,8BAAS,QAAA,RAACI;AAApB,AAAA,oBAAAC;AAAAA;;AACI,MAAO,KAAAC,MAAA;;;AAJlC,AAOE,MAAO,KAAAA,MAAA;;;;;;AAGX;;;sCAAA,tCAAMC,oFAEHC;AAFH,AAGE,AAACC;;AACD,IAAAC,gCAAUC;AAAV,AAAA,6CAAA,7CAAUA;;AAAV,IAAA,AACE,OAAA,sCAAA,rCAAG,AAACV,wDAAuB,AAACW,2CAAgBJ;UAD9C,AAAA,6CAAAE,7CAAUC;;AAGZ;;;6CAAA,7CAAME,kGAEHL;AAFH,AAGE,AAACC;;AACD,IAAAK,gCAAUH;AAAV,AAAA,6CAAA,7CAAUA;;AAAV,IAAA,AACE,OAAA,sCAAA,rCAAG,AAACV,8DAA6B,AAACW,2CAAgBJ;UADpD,AAAA,6CAAAM,7CAAUH","names":["reagent.dom.server\/imported","reagent.dom.server\/module","cljs.core\/some?","js\/ReactDOMServer","js\/require","or__25130__auto__","js\/Error","reagent.dom.server\/render-to-string","component","reagent.ratom\/flush!","*non-reactive*26899","reagent.impl.util\/*non-reactive*","reagent.impl.template\/as-element","reagent.dom.server\/render-to-static-markup","*non-reactive*26901"]}

View file

@ -0,0 +1,113 @@
(ns reagent.impl.batching
(:refer-clojure :exclude [flush])
(:require [reagent.debug :refer-macros [dbg]]
[reagent.interop :refer-macros [$ $!]]
[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 (true? ($ c :cljsIsDirty))
($ c forceUpdate)))))
;; Set from ratom.cljs
(defonce ratom-flush (fn []))
(deftype RenderQueue [^:mutable ^boolean scheduled?]
Object
(enqueue [this k f]
(assert (some? f))
(when (nil? (aget this k))
(aset this k (array)))
(.push (aget this k) f)
(.schedule this))
(run-funs [this k]
(when-some [fs (aget this k)]
(aset this k nil)
(dotimes [i (alength fs)]
((aget fs i)))))
(schedule [this]
(when-not scheduled?
(set! scheduled? true)
(next-tick #(.run-queues this))))
(queue-render [this c]
(.enqueue this "componentQueue" c))
(add-before-flush [this f]
(.enqueue this "beforeFlush" f))
(add-after-render [this f]
(.enqueue this "afterRender" f))
(run-queues [this]
(set! scheduled? false)
(.flush-queues this))
(flush-after-render [this]
(.run-funs this "afterRender"))
(flush-queues [this]
(.run-funs this "beforeFlush")
(ratom-flush)
(when-some [cs (aget this "componentQueue")]
(aset this "componentQueue" nil)
(run-queue cs))
(.flush-after-render this)))
(defonce render-queue (RenderQueue. false))
(defn flush []
(.flush-queues render-queue))
(defn flush-after-render []
(.flush-after-render render-queue))
(defn queue-render [c]
(when-not ($ c :cljsIsDirty)
($! c :cljsIsDirty true)
(.queue-render render-queue c)))
(defn mark-rendered [c]
($! c :cljsIsDirty false))
(defn do-before-flush [f]
(.add-before-flush render-queue f))
(defn do-after-render [f]
(.add-after-render render-queue f))
(defn schedule []
(when (false? (.-scheduled? render-queue))
(.schedule render-queue)))

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,244 @@
// Compiled by ClojureScript 1.9.229 {}
goog.provide('reagent.impl.batching');
goog.require('cljs.core');
goog.require('reagent.debug');
goog.require('reagent.interop');
goog.require('reagent.impl.util');
goog.require('clojure.string');
if(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 = ((cljs.core.not.call(null,reagent.impl.util.is_client))?reagent.impl.batching.fake_raf:(function (){var w = window;
var or__25130__auto__ = (w["requestAnimationFrame"]);
if(cljs.core.truth_(or__25130__auto__)){
return or__25130__auto__;
} else {
var or__25130__auto____$1 = (w["webkitRequestAnimationFrame"]);
if(cljs.core.truth_(or__25130__auto____$1)){
return or__25130__auto____$1;
} else {
var or__25130__auto____$2 = (w["mozRequestAnimationFrame"]);
if(cljs.core.truth_(or__25130__auto____$2)){
return or__25130__auto____$2;
} else {
var or__25130__auto____$3 = (w["msRequestAnimationFrame"]);
if(cljs.core.truth_(or__25130__auto____$3)){
return or__25130__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__26045__auto__ = a.length;
var i = (0);
while(true){
if((i < n__26045__auto__)){
var c_26444 = (a[i]);
if((c_26444["cljsIsDirty"]) === true){
(c_26444["forceUpdate"])();
} else {
}
var G__26445 = (i + (1));
i = G__26445;
continue;
} else {
return null;
}
break;
}
});
if(typeof reagent.impl.batching.ratom_flush !== 'undefined'){
} else {
reagent.impl.batching.ratom_flush = (function reagent$impl$batching$ratom_flush(){
return null;
});
}
/**
* @constructor
* @implements {reagent.impl.batching.Object}
*/
reagent.impl.batching.RenderQueue = (function (scheduled_QMARK_){
this.scheduled_QMARK_ = scheduled_QMARK_;
})
reagent.impl.batching.RenderQueue.prototype.run_funs = (function (k){
var self__ = this;
var this$ = this;
var temp__4661__auto__ = (this$[k]);
if((temp__4661__auto__ == null)){
return null;
} else {
var fs = temp__4661__auto__;
(this$[k] = null);
var n__26045__auto__ = fs.length;
var i = (0);
while(true){
if((i < n__26045__auto__)){
(fs[i]).call(null);
var G__26446 = (i + (1));
i = G__26446;
continue;
} else {
return null;
}
break;
}
}
});
reagent.impl.batching.RenderQueue.prototype.flush_after_render = (function (){
var self__ = this;
var this$ = this;
return this$.run_funs("afterRender");
});
reagent.impl.batching.RenderQueue.prototype.queue_render = (function (c){
var self__ = this;
var this$ = this;
return this$.enqueue("componentQueue",c);
});
reagent.impl.batching.RenderQueue.prototype.schedule = (function (){
var self__ = this;
var this$ = this;
if(self__.scheduled_QMARK_){
return null;
} else {
self__.scheduled_QMARK_ = true;
return reagent.impl.batching.next_tick.call(null,((function (this$){
return (function (){
return this$.run_queues();
});})(this$))
);
}
});
reagent.impl.batching.RenderQueue.prototype.flush_queues = (function (){
var self__ = this;
var this$ = this;
this$.run_funs("beforeFlush");
reagent.impl.batching.ratom_flush.call(null);
var temp__4661__auto___26447 = (this$["componentQueue"]);
if((temp__4661__auto___26447 == null)){
} else {
var cs_26448 = temp__4661__auto___26447;
(this$["componentQueue"] = null);
reagent.impl.batching.run_queue.call(null,cs_26448);
}
return this$.flush_after_render();
});
reagent.impl.batching.RenderQueue.prototype.run_queues = (function (){
var self__ = this;
var this$ = this;
self__.scheduled_QMARK_ = false;
return this$.flush_queues();
});
reagent.impl.batching.RenderQueue.prototype.enqueue = (function (k,f){
var self__ = this;
var this$ = this;
if(cljs.core.some_QMARK_.call(null,f)){
} else {
throw (new Error("Assert failed: (some? f)"));
}
if(((this$[k]) == null)){
(this$[k] = []);
} else {
}
(this$[k]).push(f);
return this$.schedule();
});
reagent.impl.batching.RenderQueue.prototype.add_before_flush = (function (f){
var self__ = this;
var this$ = this;
return this$.enqueue("beforeFlush",f);
});
reagent.impl.batching.RenderQueue.prototype.add_after_render = (function (f){
var self__ = this;
var this$ = this;
return this$.enqueue("afterRender",f);
});
reagent.impl.batching.RenderQueue.getBasis = (function (){
return new cljs.core.PersistentVector(null, 1, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.with_meta(new cljs.core.Symbol(null,"scheduled?","scheduled?",579986609,null),new cljs.core.PersistentArrayMap(null, 2, [new cljs.core.Keyword(null,"tag","tag",-1290361223),new cljs.core.Symbol(null,"boolean","boolean",-278886877,null),new cljs.core.Keyword(null,"mutable","mutable",875778266),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__25736__auto__,writer__25737__auto__,opt__25738__auto__){
return cljs.core._write.call(null,writer__25737__auto__,"reagent.impl.batching/RenderQueue");
});
reagent.impl.batching.__GT_RenderQueue = (function reagent$impl$batching$__GT_RenderQueue(scheduled_QMARK_){
return (new reagent.impl.batching.RenderQueue(scheduled_QMARK_));
});
if(typeof reagent.impl.batching.render_queue !== 'undefined'){
} else {
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.flush_queues();
});
reagent.impl.batching.flush_after_render = (function reagent$impl$batching$flush_after_render(){
return reagent.impl.batching.render_queue.flush_after_render();
});
reagent.impl.batching.queue_render = (function reagent$impl$batching$queue_render(c){
if(cljs.core.truth_((c["cljsIsDirty"]))){
return null;
} else {
(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_before_flush = (function reagent$impl$batching$do_before_flush(f){
return reagent.impl.batching.render_queue.add_before_flush(f);
});
reagent.impl.batching.do_after_render = (function reagent$impl$batching$do_after_render(f){
return reagent.impl.batching.render_queue.add_after_render(f);
});
reagent.impl.batching.schedule = (function reagent$impl$batching$schedule(){
if(reagent.impl.batching.render_queue.scheduled_QMARK_ === false){
return reagent.impl.batching.render_queue.schedule();
} else {
return null;
}
});
//# sourceMappingURL=batching.js.map?rel=1603199187153

View file

@ -0,0 +1 @@
{"version":3,"file":"\/Users\/simon\/workspace\/swinging-needle-meter\/docs\/js\/compiled\/out\/reagent\/impl\/batching.js","sources":["batching.cljs?rel=1603199187155"],"lineCount":244,"mappings":";AAAA;;;;;;AASA,GAAA,OAASA;AAAT;AAAA,AAAA,oCAAA,pCAASA;;AAET,yCAAA,zCAAMC;AAAN,AACE,OAAMD,oCAAY,qCAAA,pCAAKA;;AAEzB,iCAAA,jCAAME,0EAAUC;AAAhB,AACE,oBAAA,bAACC,WAAcD;;AAEjB,AAAKE,kCACH,EAAA,AAAAC,wBAAQC,8BACNL,+BACA,iBAAMM,IAAEC;AAAR,AACE,IAAAC,oBAAI,GAAA,FAAGF;AAAP,AAAA,oBAAAE;AAAAA;;AAAA,IAAAA,wBACI,GAAA,FAAGF;AADP,AAAA,oBAAAE;AAAAA;;AAAA,IAAAA,wBAEI,GAAA,FAAGF;AAFP,AAAA,oBAAAE;AAAAA;;AAAA,IAAAA,wBAGI,GAAA,FAAGF;AAHP,AAAA,oBAAAE;AAAAA;;AAIIR;;;;;;AAEV,4CAAA,5CAAMS,gGAAqBC,GAAGC;AAA9B,AACE,QAAG,IAAA,HAAGD,wBACH,IAAA,HAAGC;;AAER,kCAAA,lCAAMC,4EAAWC;AAAjB,AAGE,AAAOA,OAAEJ;;AACT,IAAAK,mBAAY,AAASD;AAArB,AAAA,QAAA,JAAUE;;AAAV,AAAA,GAAA,KAAAD,JAAUC;AAAV,AACE,IAAMC,UAAE,CAAMH,EAAEE;AAAhB,AACE,GAAM,AAAO,SAAA,RAAGC;AAAhB,AACE,AAAA,SAAA,RAAGA;;AADL;;AAFJ,eAAA,KAAA,JAAUD;;;;AAAV;;;;;AAOF,GAAA,OAASE;AAAT;AAAA,AAAA,AAASA,oCAAY;AAAA,AAAA;;;AAErB,AAAA;;;;;;;;AAAA,AAAA,AAAA,AAAA,uDAAA,vDAASK,kEASSI;;AATlB,AAAA,YAAA,RASaD;AATb,AAUI,IAAAI,qBAAe,CAAMJ,MAAKC;AAA1B,AAAA,GAAA,CAAAG,sBAAA;AAAA;;AAAA,SAAAA,LAAYC;AAAZ,AACE,YAAA,XAAML,MAAKC;;AACX,IAAAZ,mBAAY,AAASgB;AAArB,AAAA,QAAA,JAAUf;;AAAV,AAAA,GAAA,KAAAD,JAAUC;AAAV,AACE,AAAC,CAAMe,GAAGf;;AADZ,eAAA,KAAA,JAAUA;;;;AAAV;;;;;;;AAZN,AAAA,AAAA,iEAAA,jEAASO;;AAAT,AAAA,YAAA,RAiCuBG;AAjCvB,AAkCI,sBAAA,fAAWA;;;AAlCf,AAAA,AAAA,2DAAA,3DAASH,sEAoBaN;;AApBtB,AAAA,YAAA,RAoBiBS;AApBjB,AAqBI,qBAAA,dAAUA,+BAAsBT;;;AArBpC,AAAA,AAAA,uDAAA,vDAASM;;AAAT,AAAA,YAAA,RAeaG;AAfb,AAgBI,GAAUD;AAAV;;AAAA,AACE,0BAAA,1BAAMA;;AACN,iDAAA,1CAACrB;;AAAD,AAAY,OAAasB;;;;;;AAlB\/B,AAAA,AAAA,2DAAA,3DAASH;;AAAT,AAAA,YAAA,RAoCiBG;AApCjB,AAqCI,eAAA,fAAWA;;AACX,AAACR;;AACD,IAAAY,2BAAe,OAAA,NAAMJ;AAArB,AAAA,GAAA,CAAAI,4BAAA;AAAA;AAAA,eAAAA,XAAYE;AAAZ,AACE,OAAA,oBAAA,1BAAMN;;AACN,AAACb,0CAAUmB;;;AACb,OAAqBN;;;AA1CzB,AAAA,AAAA,yDAAA,zDAASH;;AAAT,AAAA,YAAA,RA6BeG;AA7Bf,AA8BI,0BAAA,1BAAMD;;AACN,OAAeC;;;AA\/BnB,AAAA,AAAA,sDAAA,tDAASH,iEAEQI,EAAEzB;;AAFnB,AAAA,YAAA,RAEYwB;AAFZ,AAGI,GAAQ,AAACG,gCAAM3B;AAAf;AAAA,AAAA,MAAA,KAAA0B,MAAA;;;AACA,GAAM,eAAA,dAAM,CAAMF,MAAKC;AAAvB,AACE,CAAMD,MAAKC,KAAE;;AADf;;AAEA,AAAO,CAAMD,MAAKC,SAAGzB;;AACrB,OAAWwB;;;AAPf,AAAA,AAAA,+DAAA,\/DAASH,0EAuBiBrB;;AAvB1B,AAAA,YAAA,RAuBqBwB;AAvBrB,AAwBI,qBAAA,dAAUA,4BAAmBxB;;;AAxBjC,AAAA,AAAA,+DAAA,\/DAASqB,0EA0BiBrB;;AA1B1B,AAAA,YAAA,RA0BqBwB;AA1BrB,AA2BI,qBAAA,dAAUA,4BAAmBxB;;;AA3BjC,AAAA,6CAAA,7CAASqB;AAAT,AAAA,0FAAA,oBAAA,oEAAA,2CAAA,oDAAA,+DAAA,0DAAA;;;AAAA,AAAA,mDAAA,nDAASA;;AAAT,AAAA,sDAAA,tDAASA;;AAAT,AAAA,2DAAA,WAAAJ,oBAAAC,sBAAAC,hHAASE;AAAT,AAAA,OAAAD,2BAAAF,sBAAA;;;AAAA,yCAAA,zCAASI,0FAAgCC;AAAzC,AAAA,YAAAF,kCAAyCE;;;AAAhCF,AA4CT,GAAA,OAASU;AAAT;AAAA,AAAA,AAASA,qCAAa,KAAAV,kCAAA;;AAEtB,8BAAA,9BAAMW;AAAN,AACE,OAAeD;;AAEjB,2CAAA,3CAAME;AAAN,AACE,OAAqBF;;AAEvB,qCAAA,rCAAMG,kFAAcnB;AAApB,AACE,oBAAU,GAAA,FAAGA;AAAb;;AAAA,AACE,GAAA,iBAAA,nBAAIA;;AACJ,OAAegB,gDAAahB;;;AAEhC,sCAAA,tCAAMoB,oFAAepB;AAArB,AACE,UAAA,iBAAA,nBAAIA;;AAEN,wCAAA,xCAAMqB,wFAAiBpC;AAAvB,AACE,OAAmB+B,oDAAa\/B;;AAElC,wCAAA,xCAAMqC,wFAAiBrC;AAAvB,AACE,OAAmB+B,oDAAa\/B;;AAElC,iCAAA,jCAAMsC;AAAN,AACE,GAAM,AAAQ,AAAcP;AAA5B,AACE,OAAWA;;AADb","names":["reagent.impl.batching\/mount-count","reagent.impl.batching\/next-mount-count","reagent.impl.batching\/fake-raf","f","js\/setTimeout","reagent.impl.batching\/next-tick","cljs.core\/not","reagent.impl.util\/is-client","w","js\/window","or__25130__auto__","reagent.impl.batching\/compare-mount-order","c1","c2","reagent.impl.batching\/run-queue","a","n__26045__auto__","i","c","reagent.impl.batching\/ratom-flush","this__25736__auto__","writer__25737__auto__","opt__25738__auto__","cljs.core\/-write","reagent.impl.batching\/RenderQueue","reagent.impl.batching\/->RenderQueue","scheduled?","this","k","js\/Error","cljs.core\/some?","temp__4661__auto__","fs","cs","reagent.impl.batching\/render-queue","reagent.impl.batching\/flush","reagent.impl.batching\/flush-after-render","reagent.impl.batching\/queue-render","reagent.impl.batching\/mark-rendered","reagent.impl.batching\/do-before-flush","reagent.impl.batching\/do-after-render","reagent.impl.batching\/schedule"]}

View file

@ -0,0 +1,317 @@
(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 error warn-unless]]))
(declare ^:dynamic *current-component*)
;;; Argv access
(defn shallow-obj-to-map [o]
(let [ks (js-keys o)
len (alength ks)]
(loop [m {} i 0]
(if (< i len)
(let [k (aget ks i)]
(recur (assoc m (keyword k) (aget o k)) (inc i)))
m))))
(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 props-argv [c p]
(if-some [a ($ p :argv)]
a
[(.-constructor c) (shallow-obj-to-map p)]))
(defn get-argv [c]
(props-argv c ($ c :props)))
(defn get-props [c]
(let [p ($ c :props)]
(if-some [v ($ p :argv)]
(extract-props v)
(shallow-obj-to-map p))))
(defn get-children [c]
(let [p ($ c :props)]
(if-some [v ($ p :argv)]
(extract-children v)
(->> ($ p :children)
($ util/react Children.toArray)
(into [])))))
(defn ^boolean reagent-class? [c]
(and (fn? c)
(some? (some-> c .-prototype ($ :reagentRender)))))
(defn ^boolean react-class? [c]
(and (fn? c)
(some? (some-> c .-prototype ($ :render)))))
(defn ^boolean reagent-component? [c]
(some? ($ c :reagentRender)))
(defn cached-react-class [c]
($ c :cljsReactClass))
(defn cache-react-class [c constructor]
($! c :cljsReactClass constructor))
;;; State
(defn state-atom [this]
(let [sa ($ this :cljsState)]
(if-not (nil? sa)
sa
($! this :cljsState (ratom/atom nil)))))
;; avoid circular dependency: this gets set from template.cljs
(defonce as-element nil)
;;; Rendering
(defn wrap-render [c]
(let [f ($ c :reagentRender)
_ (assert (ifn? f))
res (if (true? ($ c :cljsLegacyRender))
(.call f c c)
(let [v (get-argv c)
n (count v)]
(case n
1 (.call f c)
2 (.call f c (nth v 1))
3 (.call f c (nth v 1) (nth v 2))
4 (.call f c (nth v 1) (nth v 2) (nth v 3))
5 (.call f c (nth v 1) (nth v 2) (nth v 3) (nth v 4))
(.apply f c (.slice (into-array v) 1)))))]
(cond
(vector? res) (as-element res)
(ifn? res) (let [f (if (reagent-class? res)
(fn [& args]
(as-element (apply vector res args)))
res)]
($! c :reagentRender f)
(recur c))
:else 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 (wrap-render c)]
(aset ok 0 true)
res)
(finally
(when-not (aget ok 0)
(error (str "Error rendering component"
(comp-name)))))))
(wrap-render c))))
;;; Method wrapping
(def rat-opts {:no-cache true})
(def static-fns
{:render
(fn render []
(this-as c (if util/*non-reactive*
(do-render c)
(let [rat ($ c :cljsRatom)]
(batch/mark-rendered c)
(if (nil? rat)
(ratom/run-in-reaction #(do-render c) c "cljsRatom"
batch/queue-render rat-opts)
(._run rat false))))))})
(defn custom-wrapper [key f]
(case key
:getDefaultProps
(assert false "getDefaultProps not supported")
:getInitialState
(fn getInitialState []
(this-as c (reset! (state-atom c) (.call f c c))))
:componentWillReceiveProps
(fn componentWillReceiveProps [nextprops]
(this-as c (.call f c c (props-argv c nextprops))))
:shouldComponentUpdate
(fn shouldComponentUpdate [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)
noargv (or (nil? old-argv) (nil? new-argv))]
(cond
(nil? f) (or noargv (not= old-argv new-argv))
noargv (.call f c c (get-argv c) (props-argv c nextprops))
:else (.call f c c old-argv new-argv))))))
:componentWillUpdate
(fn componentWillUpdate [nextprops]
(this-as c (.call f c c (props-argv c nextprops))))
:componentDidUpdate
(fn componentDidUpdate [oldprops]
(this-as c (.call f c c (props-argv c oldprops))))
:componentWillMount
(fn componentWillMount []
(this-as c
($! c :cljsMountOrder (batch/next-mount-count))
(when-not (nil? f)
(.call f c c))))
:componentDidMount
(fn componentDidMount []
(this-as c (.call f c c)))
:componentWillUnmount
(fn componentWillUnmount []
(this-as c
(some-> ($ c :cljsRatom)
ratom/dispose!)
(batch/mark-rendered c)
(when-not (nil? f)
(.call f c c))))
nil))
(defn get-wrapper [key f name]
(let [wrap (custom-wrapper key f)]
(when (and wrap f)
(assert (ifn? f)
(str "Expected function in " name key " but got " f)))
(or wrap 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 wrap-funs [fmap]
(when (dev?)
(let [renders (select-keys fmap [:render :reagentRender :componentFunction])
render-fun (-> renders vals first)]
(assert (pos? (count renders)) "Missing reagent-render")
(assert (== 1 (count renders)) "Too many render functions supplied")
(assert (ifn? render-fun) (str "Render must be a function, not "
(pr-str render-fun)))))
(let [render-fun (or (:reagentRender fmap)
(:componentFunction fmap))
legacy-render (nil? render-fun)
render-fun (or render-fun
(:render fmap))
name (str (or (:displayName fmap)
(util/fun-name render-fun)))
name (case name
"" (str (gensym "reagent"))
name)
fmap (reduce-kv (fn [m k v]
(assoc m k (get-wrapper k v name)))
{} fmap)]
(assoc fmap
:displayName name
:autobind false
:cljsLegacyRender legacy-render
:reagentRender render-fun
:render (:render static-fns))))
(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]
{:pre [(map? body)]}
(->> body
cljsify
($ util/react createClass)))
(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 .-constructor util/fun-name))]
(if-not (empty? n)
(str " (in " n ")")
""))
""))
(defn fn-to-class [f]
(assert (ifn? f) (str "Expected a function, not " (pr-str f)))
(warn-unless (not (and (react-class? f)
(not (reagent-class? f))))
"Using native React classes directly in Hiccup forms "
"is not supported. Use create-element or "
"adapt-react-class instead: " (let [n (util/fun-name f)]
(if (empty? n) f n))
(comp-name))
(if (reagent-class? f)
(cache-react-class f f)
(let [spec (meta f)
withrender (assoc spec :reagent-render f)
res (create-class withrender)]
(cache-react-class f res))))
(defn as-class [tag]
(if-some [cached-class (cached-react-class tag)]
cached-class
(fn-to-class tag)))
(defn reactify-component [comp]
(if (react-class? comp)
comp
(as-class comp)))

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,573 @@
// Compiled by ClojureScript 1.9.229 {}
goog.provide('reagent.impl.component');
goog.require('cljs.core');
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.shallow_obj_to_map = (function reagent$impl$component$shallow_obj_to_map(o){
var ks = cljs.core.js_keys.call(null,o);
var len = ks.length;
var m = cljs.core.PersistentArrayMap.EMPTY;
var i = (0);
while(true){
if((i < len)){
var k = (ks[i]);
var G__26774 = cljs.core.assoc.call(null,m,cljs.core.keyword.call(null,k),(o[k]));
var G__26775 = (i + (1));
m = G__26774;
i = G__26775;
continue;
} else {
return m;
}
break;
}
});
reagent.impl.component.extract_props = (function reagent$impl$component$extract_props(v){
var p = cljs.core.nth.call(null,v,(1),null);
if(cljs.core.map_QMARK_.call(null,p)){
return p;
} else {
return null;
}
});
reagent.impl.component.extract_children = (function reagent$impl$component$extract_children(v){
var p = cljs.core.nth.call(null,v,(1),null);
var first_child = ((((p == null)) || (cljs.core.map_QMARK_.call(null,p)))?(2):(1));
if((cljs.core.count.call(null,v) > first_child)){
return cljs.core.subvec.call(null,v,first_child);
} else {
return null;
}
});
reagent.impl.component.props_argv = (function reagent$impl$component$props_argv(c,p){
var temp__4659__auto__ = (p["argv"]);
if((temp__4659__auto__ == null)){
return new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [c.constructor,reagent.impl.component.shallow_obj_to_map.call(null,p)], null);
} else {
var a = temp__4659__auto__;
return a;
}
});
reagent.impl.component.get_argv = (function reagent$impl$component$get_argv(c){
return reagent.impl.component.props_argv.call(null,c,(c["props"]));
});
reagent.impl.component.get_props = (function reagent$impl$component$get_props(c){
var p = (c["props"]);
var temp__4659__auto__ = (p["argv"]);
if((temp__4659__auto__ == null)){
return reagent.impl.component.shallow_obj_to_map.call(null,p);
} else {
var v = temp__4659__auto__;
return reagent.impl.component.extract_props.call(null,v);
}
});
reagent.impl.component.get_children = (function reagent$impl$component$get_children(c){
var p = (c["props"]);
var temp__4659__auto__ = (p["argv"]);
if((temp__4659__auto__ == null)){
return cljs.core.into.call(null,cljs.core.PersistentVector.EMPTY,(reagent.impl.util.react["Children"]["toArray"])((p["children"])));
} else {
var v = temp__4659__auto__;
return reagent.impl.component.extract_children.call(null,v);
}
});
reagent.impl.component.reagent_class_QMARK_ = (function reagent$impl$component$reagent_class_QMARK_(c){
return (cljs.core.fn_QMARK_.call(null,c)) && (cljs.core.some_QMARK_.call(null,(function (){var G__26779 = c;
var G__26779__$1 = (((G__26779 == null))?null:G__26779.prototype);
if((G__26779__$1 == null)){
return null;
} else {
return (G__26779__$1["reagentRender"]);
}
})()));
});
reagent.impl.component.react_class_QMARK_ = (function reagent$impl$component$react_class_QMARK_(c){
return (cljs.core.fn_QMARK_.call(null,c)) && (cljs.core.some_QMARK_.call(null,(function (){var G__26783 = c;
var G__26783__$1 = (((G__26783 == null))?null:G__26783.prototype);
if((G__26783__$1 == null)){
return null;
} else {
return (G__26783__$1["render"]);
}
})()));
});
reagent.impl.component.reagent_component_QMARK_ = (function reagent$impl$component$reagent_component_QMARK_(c){
return cljs.core.some_QMARK_.call(null,(c["reagentRender"]));
});
reagent.impl.component.cached_react_class = (function reagent$impl$component$cached_react_class(c){
return (c["cljsReactClass"]);
});
reagent.impl.component.cache_react_class = (function reagent$impl$component$cache_react_class(c,constructor$){
return (c["cljsReactClass"] = constructor$);
});
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.call(null,null));
}
});
if(typeof reagent.impl.component.as_element !== 'undefined'){
} else {
reagent.impl.component.as_element = null;
}
reagent.impl.component.wrap_render = (function reagent$impl$component$wrap_render(c){
while(true){
var f = (c["reagentRender"]);
var _ = ((cljs.core.ifn_QMARK_.call(null,f))?null:(function(){throw (new Error("Assert failed: (ifn? f)"))})());
var res = (((c["cljsLegacyRender"]) === true)?f.call(c,c):(function (){var v = reagent.impl.component.get_argv.call(null,c);
var n = cljs.core.count.call(null,v);
var G__26785 = n;
switch (G__26785) {
case (1):
return f.call(c);
break;
case (2):
return f.call(c,cljs.core.nth.call(null,v,(1)));
break;
case (3):
return f.call(c,cljs.core.nth.call(null,v,(1)),cljs.core.nth.call(null,v,(2)));
break;
case (4):
return f.call(c,cljs.core.nth.call(null,v,(1)),cljs.core.nth.call(null,v,(2)),cljs.core.nth.call(null,v,(3)));
break;
case (5):
return f.call(c,cljs.core.nth.call(null,v,(1)),cljs.core.nth.call(null,v,(2)),cljs.core.nth.call(null,v,(3)),cljs.core.nth.call(null,v,(4)));
break;
default:
return f.apply(c,cljs.core.into_array.call(null,v).slice((1)));
}
})());
if(cljs.core.vector_QMARK_.call(null,res)){
return reagent.impl.component.as_element.call(null,res);
} else {
if(cljs.core.ifn_QMARK_.call(null,res)){
var f__$1 = ((reagent.impl.component.reagent_class_QMARK_.call(null,res))?((function (c,f,_,res){
return (function() {
var G__26787__delegate = function (args){
return reagent.impl.component.as_element.call(null,cljs.core.apply.call(null,cljs.core.vector,res,args));
};
var G__26787 = function (var_args){
var args = null;
if (arguments.length > 0) {
var G__26788__i = 0, G__26788__a = new Array(arguments.length - 0);
while (G__26788__i < G__26788__a.length) {G__26788__a[G__26788__i] = arguments[G__26788__i + 0]; ++G__26788__i;}
args = new cljs.core.IndexedSeq(G__26788__a,0);
}
return G__26787__delegate.call(this,args);};
G__26787.cljs$lang$maxFixedArity = 0;
G__26787.cljs$lang$applyTo = (function (arglist__26789){
var args = cljs.core.seq(arglist__26789);
return G__26787__delegate(args);
});
G__26787.cljs$core$IFn$_invoke$arity$variadic = G__26787__delegate;
return G__26787;
})()
;})(c,f,_,res))
:res);
(c["reagentRender"] = f__$1);
var G__26790 = c;
c = G__26790;
continue;
} else {
return res;
}
}
break;
}
});
reagent.impl.component.do_render = (function reagent$impl$component$do_render(c){
var _STAR_current_component_STAR_26792 = reagent.impl.component._STAR_current_component_STAR_;
reagent.impl.component._STAR_current_component_STAR_ = c;
try{var ok = [false];
try{var res = reagent.impl.component.wrap_render.call(null,c);
(ok[(0)] = true);
return res;
}finally {if(cljs.core.truth_((ok[(0)]))){
} else {
if(cljs.core.truth_(reagent.debug.has_console)){
(cljs.core.truth_(reagent.debug.tracking)?reagent.debug.track_console:console).error([cljs.core.str([cljs.core.str("Error rendering component"),cljs.core.str(reagent.impl.component.comp_name.call(null))].join(''))].join(''));
} else {
}
}
}
}finally {reagent.impl.component._STAR_current_component_STAR_ = _STAR_current_component_STAR_26792;
}});
reagent.impl.component.rat_opts = new cljs.core.PersistentArrayMap(null, 1, [new cljs.core.Keyword(null,"no-cache","no-cache",1588056370),true], null);
reagent.impl.component.static_fns = new cljs.core.PersistentArrayMap(null, 1, [new cljs.core.Keyword(null,"render","render",-1408033454),(function reagent$impl$component$render(){
var c = this;
if(reagent.impl.util._STAR_non_reactive_STAR_){
return reagent.impl.component.do_render.call(null,c);
} else {
var rat = (c["cljsRatom"]);
reagent.impl.batching.mark_rendered.call(null,c);
if((rat == null)){
return reagent.ratom.run_in_reaction.call(null,((function (rat,c){
return (function (){
return reagent.impl.component.do_render.call(null,c);
});})(rat,c))
,c,"cljsRatom",reagent.impl.batching.queue_render,reagent.impl.component.rat_opts);
} else {
return rat._run(false);
}
}
})], null);
reagent.impl.component.custom_wrapper = (function reagent$impl$component$custom_wrapper(key,f){
var G__26796 = (((key instanceof cljs.core.Keyword))?key.fqn:null);
switch (G__26796) {
case "getDefaultProps":
throw (new Error([cljs.core.str("Assert failed: "),cljs.core.str("getDefaultProps not supported"),cljs.core.str("\n"),cljs.core.str("false")].join('')));
break;
case "getInitialState":
return ((function (G__26796){
return (function reagent$impl$component$custom_wrapper_$_getInitialState(){
var c = this;
return cljs.core.reset_BANG_.call(null,reagent.impl.component.state_atom.call(null,c),f.call(c,c));
});
;})(G__26796))
break;
case "componentWillReceiveProps":
return ((function (G__26796){
return (function reagent$impl$component$custom_wrapper_$_componentWillReceiveProps(nextprops){
var c = this;
return f.call(c,c,reagent.impl.component.props_argv.call(null,c,nextprops));
});
;})(G__26796))
break;
case "shouldComponentUpdate":
return ((function (G__26796){
return (function reagent$impl$component$custom_wrapper_$_shouldComponentUpdate(nextprops,nextstate){
var or__25130__auto__ = reagent.impl.util._STAR_always_update_STAR_;
if(cljs.core.truth_(or__25130__auto__)){
return or__25130__auto__;
} else {
var c = this;
var old_argv = (c["props"]["argv"]);
var new_argv = (nextprops["argv"]);
var noargv = ((old_argv == null)) || ((new_argv == null));
if((f == null)){
return (noargv) || (cljs.core.not_EQ_.call(null,old_argv,new_argv));
} else {
if(noargv){
return f.call(c,c,reagent.impl.component.get_argv.call(null,c),reagent.impl.component.props_argv.call(null,c,nextprops));
} else {
return f.call(c,c,old_argv,new_argv);
}
}
}
});
;})(G__26796))
break;
case "componentWillUpdate":
return ((function (G__26796){
return (function reagent$impl$component$custom_wrapper_$_componentWillUpdate(nextprops){
var c = this;
return f.call(c,c,reagent.impl.component.props_argv.call(null,c,nextprops));
});
;})(G__26796))
break;
case "componentDidUpdate":
return ((function (G__26796){
return (function reagent$impl$component$custom_wrapper_$_componentDidUpdate(oldprops){
var c = this;
return f.call(c,c,reagent.impl.component.props_argv.call(null,c,oldprops));
});
;})(G__26796))
break;
case "componentWillMount":
return ((function (G__26796){
return (function reagent$impl$component$custom_wrapper_$_componentWillMount(){
var c = this;
(c["cljsMountOrder"] = reagent.impl.batching.next_mount_count.call(null));
if((f == null)){
return null;
} else {
return f.call(c,c);
}
});
;})(G__26796))
break;
case "componentDidMount":
return ((function (G__26796){
return (function reagent$impl$component$custom_wrapper_$_componentDidMount(){
var c = this;
return f.call(c,c);
});
;})(G__26796))
break;
case "componentWillUnmount":
return ((function (G__26796){
return (function reagent$impl$component$custom_wrapper_$_componentWillUnmount(){
var c = this;
var G__26798_26800 = (c["cljsRatom"]);
if((G__26798_26800 == null)){
} else {
reagent.ratom.dispose_BANG_.call(null,G__26798_26800);
}
reagent.impl.batching.mark_rendered.call(null,c);
if((f == null)){
return null;
} else {
return f.call(c,c);
}
});
;})(G__26796))
break;
default:
return null;
}
});
reagent.impl.component.get_wrapper = (function reagent$impl$component$get_wrapper(key,f,name){
var wrap = reagent.impl.component.custom_wrapper.call(null,key,f);
if(cljs.core.truth_((function (){var and__25118__auto__ = wrap;
if(cljs.core.truth_(and__25118__auto__)){
return f;
} else {
return and__25118__auto__;
}
})())){
if(cljs.core.ifn_QMARK_.call(null,f)){
} else {
throw (new Error([cljs.core.str("Assert failed: "),cljs.core.str([cljs.core.str("Expected function in "),cljs.core.str(name),cljs.core.str(key),cljs.core.str(" but got "),cljs.core.str(f)].join('')),cljs.core.str("\n"),cljs.core.str("(ifn? f)")].join('')));
}
} else {
}
var or__25130__auto__ = wrap;
if(cljs.core.truth_(or__25130__auto__)){
return or__25130__auto__;
} else {
return f;
}
});
reagent.impl.component.obligatory = new cljs.core.PersistentArrayMap(null, 3, [new cljs.core.Keyword(null,"shouldComponentUpdate","shouldComponentUpdate",1795750960),null,new cljs.core.Keyword(null,"componentWillMount","componentWillMount",-285327619),null,new cljs.core.Keyword(null,"componentWillUnmount","componentWillUnmount",1573788814),null], null);
reagent.impl.component.dash_to_camel = reagent.impl.util.memoize_1.call(null,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.call(null,(function (m,k,v){
return cljs.core.assoc.call(null,m,cljs.core.keyword.call(null,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.call(null,reagent.impl.component.obligatory,fun_map);
});
reagent.impl.component.wrap_funs = (function reagent$impl$component$wrap_funs(fmap){
var renders_26803 = cljs.core.select_keys.call(null,fmap,new cljs.core.PersistentVector(null, 3, 5, cljs.core.PersistentVector.EMPTY_NODE, [new cljs.core.Keyword(null,"render","render",-1408033454),new cljs.core.Keyword(null,"reagentRender","reagentRender",-358306383),new cljs.core.Keyword(null,"componentFunction","componentFunction",825866104)], null));
var render_fun_26804 = cljs.core.first.call(null,cljs.core.vals.call(null,renders_26803));
if((cljs.core.count.call(null,renders_26803) > (0))){
} else {
throw (new Error([cljs.core.str("Assert failed: "),cljs.core.str("Missing reagent-render"),cljs.core.str("\n"),cljs.core.str("(pos? (count renders))")].join('')));
}
if(((1) === cljs.core.count.call(null,renders_26803))){
} else {
throw (new Error([cljs.core.str("Assert failed: "),cljs.core.str("Too many render functions supplied"),cljs.core.str("\n"),cljs.core.str("(== 1 (count renders))")].join('')));
}
if(cljs.core.ifn_QMARK_.call(null,render_fun_26804)){
} else {
throw (new Error([cljs.core.str("Assert failed: "),cljs.core.str([cljs.core.str("Render must be a function, not "),cljs.core.str(cljs.core.pr_str.call(null,render_fun_26804))].join('')),cljs.core.str("\n"),cljs.core.str("(ifn? render-fun)")].join('')));
}
var render_fun = (function (){var or__25130__auto__ = new cljs.core.Keyword(null,"reagentRender","reagentRender",-358306383).cljs$core$IFn$_invoke$arity$1(fmap);
if(cljs.core.truth_(or__25130__auto__)){
return or__25130__auto__;
} else {
return new cljs.core.Keyword(null,"componentFunction","componentFunction",825866104).cljs$core$IFn$_invoke$arity$1(fmap);
}
})();
var legacy_render = (render_fun == null);
var render_fun__$1 = (function (){var or__25130__auto__ = render_fun;
if(cljs.core.truth_(or__25130__auto__)){
return or__25130__auto__;
} else {
return new cljs.core.Keyword(null,"render","render",-1408033454).cljs$core$IFn$_invoke$arity$1(fmap);
}
})();
var name = [cljs.core.str((function (){var or__25130__auto__ = new cljs.core.Keyword(null,"displayName","displayName",-809144601).cljs$core$IFn$_invoke$arity$1(fmap);
if(cljs.core.truth_(or__25130__auto__)){
return or__25130__auto__;
} else {
return reagent.impl.util.fun_name.call(null,render_fun__$1);
}
})())].join('');
var name__$1 = (function (){var G__26802 = name;
switch (G__26802) {
case "":
return [cljs.core.str(cljs.core.gensym.call(null,"reagent"))].join('');
break;
default:
return name;
}
})();
var fmap__$1 = cljs.core.reduce_kv.call(null,((function (render_fun,legacy_render,render_fun__$1,name,name__$1){
return (function (m,k,v){
return cljs.core.assoc.call(null,m,k,reagent.impl.component.get_wrapper.call(null,k,v,name__$1));
});})(render_fun,legacy_render,render_fun__$1,name,name__$1))
,cljs.core.PersistentArrayMap.EMPTY,fmap);
return cljs.core.assoc.call(null,fmap__$1,new cljs.core.Keyword(null,"displayName","displayName",-809144601),name__$1,new cljs.core.Keyword(null,"autobind","autobind",-570650245),false,new cljs.core.Keyword(null,"cljsLegacyRender","cljsLegacyRender",-1527295613),legacy_render,new cljs.core.Keyword(null,"reagentRender","reagentRender",-358306383),render_fun__$1,new cljs.core.Keyword(null,"render","render",-1408033454),new cljs.core.Keyword(null,"render","render",-1408033454).cljs$core$IFn$_invoke$arity$1(reagent.impl.component.static_fns));
});
reagent.impl.component.map_to_js = (function reagent$impl$component$map_to_js(m){
return cljs.core.reduce_kv.call(null,(function (o,k,v){
var G__26807 = o;
(G__26807[cljs.core.name.call(null,k)] = v);
return G__26807;
}),({}),m);
});
reagent.impl.component.cljsify = (function reagent$impl$component$cljsify(body){
return reagent.impl.component.map_to_js.call(null,reagent.impl.component.wrap_funs.call(null,reagent.impl.component.add_obligatory.call(null,reagent.impl.component.camelify_map_keys.call(null,body))));
});
reagent.impl.component.create_class = (function reagent$impl$component$create_class(body){
if(cljs.core.map_QMARK_.call(null,body)){
} else {
throw (new Error("Assert failed: (map? body)"));
}
return (reagent.impl.util.react["createClass"])(reagent.impl.component.cljsify.call(null,body));
});
reagent.impl.component.component_path = (function reagent$impl$component$component_path(c){
var elem = (function (){var G__26813 = (function (){var or__25130__auto__ = (function (){var G__26815 = c;
if((G__26815 == null)){
return null;
} else {
return (G__26815["_reactInternalInstance"]);
}
})();
if(cljs.core.truth_(or__25130__auto__)){
return or__25130__auto__;
} else {
return c;
}
})();
if((G__26813 == null)){
return null;
} else {
return (G__26813["_currentElement"]);
}
})();
var name = (function (){var G__26816 = elem;
var G__26816__$1 = (((G__26816 == null))?null:(G__26816["type"]));
if((G__26816__$1 == null)){
return null;
} else {
return (G__26816__$1["displayName"]);
}
})();
var path = (function (){var G__26817 = elem;
var G__26817__$1 = (((G__26817 == null))?null:(G__26817["_owner"]));
var G__26817__$2 = (((G__26817__$1 == null))?null:reagent$impl$component$component_path.call(null,G__26817__$1));
if((G__26817__$2 == null)){
return null;
} else {
return [cljs.core.str(G__26817__$2),cljs.core.str(" > ")].join('');
}
})();
var res = [cljs.core.str(path),cljs.core.str(name)].join('');
if(cljs.core.empty_QMARK_.call(null,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__25130__auto__ = reagent.impl.component.component_path.call(null,c);
if(cljs.core.truth_(or__25130__auto__)){
return or__25130__auto__;
} else {
var G__26819 = c;
var G__26819__$1 = (((G__26819 == null))?null:G__26819.constructor);
if((G__26819__$1 == null)){
return null;
} else {
return reagent.impl.util.fun_name.call(null,G__26819__$1);
}
}
})();
if(!(cljs.core.empty_QMARK_.call(null,n))){
return [cljs.core.str(" (in "),cljs.core.str(n),cljs.core.str(")")].join('');
} else {
return "";
}
});
reagent.impl.component.fn_to_class = (function reagent$impl$component$fn_to_class(f){
if(cljs.core.ifn_QMARK_.call(null,f)){
} else {
throw (new Error([cljs.core.str("Assert failed: "),cljs.core.str([cljs.core.str("Expected a function, not "),cljs.core.str(cljs.core.pr_str.call(null,f))].join('')),cljs.core.str("\n"),cljs.core.str("(ifn? f)")].join('')));
}
if(!(!((reagent.impl.component.react_class_QMARK_.call(null,f)) && (!(reagent.impl.component.reagent_class_QMARK_.call(null,f)))))){
if(cljs.core.truth_(reagent.debug.has_console)){
(cljs.core.truth_(reagent.debug.tracking)?reagent.debug.track_console:console).warn([cljs.core.str("Warning: "),cljs.core.str("Using native React classes directly in Hiccup forms "),cljs.core.str("is not supported. Use create-element or "),cljs.core.str("adapt-react-class instead: "),cljs.core.str((function (){var n = reagent.impl.util.fun_name.call(null,f);
if(cljs.core.empty_QMARK_.call(null,n)){
return f;
} else {
return n;
}
})()),cljs.core.str(reagent.impl.component.comp_name.call(null))].join(''));
} else {
}
} else {
}
if(reagent.impl.component.reagent_class_QMARK_.call(null,f)){
return reagent.impl.component.cache_react_class.call(null,f,f);
} else {
var spec = cljs.core.meta.call(null,f);
var withrender = cljs.core.assoc.call(null,spec,new cljs.core.Keyword(null,"reagent-render","reagent-render",-985383853),f);
var res = reagent.impl.component.create_class.call(null,withrender);
return reagent.impl.component.cache_react_class.call(null,f,res);
}
});
reagent.impl.component.as_class = (function reagent$impl$component$as_class(tag){
var temp__4659__auto__ = reagent.impl.component.cached_react_class.call(null,tag);
if((temp__4659__auto__ == null)){
return reagent.impl.component.fn_to_class.call(null,tag);
} else {
var cached_class = temp__4659__auto__;
return cached_class;
}
});
reagent.impl.component.reactify_component = (function reagent$impl$component$reactify_component(comp){
if(reagent.impl.component.react_class_QMARK_.call(null,comp)){
return comp;
} else {
return reagent.impl.component.as_class.call(null,comp);
}
});
//# sourceMappingURL=component.js.map?rel=1603199188456

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,395 @@
(ns reagent.impl.template
(:require [clojure.string :as string]
[clojure.walk :refer [prewalk]]
[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 [])
;;; Common utilities
(defn ^boolean named? [x]
(or (keyword? x)
(symbol? x)))
(defn ^boolean hiccup-tag? [x]
(or (named? x)
(string? x)))
(defn ^boolean 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 cache-get [o k]
(when ^boolean (.hasOwnProperty o k)
(aget o k)))
(defn cached-prop-name [k]
(if (named? k)
(if-some [k' (cache-get prop-name-cache (name k))]
k'
(aset prop-name-cache (name k)
(util/dash-to-camel k)))
k))
(defn ^boolean js-val? [x]
(not (identical? "object" (goog/typeOf x))))
(declare convert-prop-value)
(defn kv-conv [o k v]
(doto o
(aset (cached-prop-name k)
(convert-prop-value v))))
(defn convert-prop-value [x]
(cond (js-val? x) x
(named? x) (name x)
(map? x) (reduce-kv kv-conv #js{} x)
(coll? x) (clj->js x)
(ifn? x) (fn [& args]
(apply x args))
:else (clj->js x)))
(defn oset [o k v]
(doto (if (nil? o) #js{} o)
(aset k v)))
(defn oget [o k]
(if (nil? o) nil (aget o k)))
(defn set-id-class [p id-class]
(let [id ($ id-class :id)
p (if (and (some? id)
(nil? (oget p "id")))
(oset p "id" id)
p)]
(if-some [class ($ id-class :className)]
(let [old (oget p "className")]
(oset p "className" (if (nil? old)
class
(str class " " old))))
p)))
(defn convert-props [props id-class]
(-> props
convert-prop-value
(set-id-class id-class)))
;;; Specialization for input components
;; <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 ^boolean has-selection-api?
[input-type]
(contains? these-inputs-have-selection-api input-type))
(defn input-set-value [this]
(when-some [node ($ this :cljsInputElement)]
($! this :cljsInputDirty false)
(let [rendered-value ($ this :cljsRenderedValue)
dom-value ($ this :cljsDOMValue)]
(when (not= rendered-value dom-value)
(if-not (and (identical? node ($ js/document :activeElement))
(has-selection-api? ($ node :type))
(string? rendered-value)
(string? dom-value))
;; just set the value, no need to worry about a cursor
(do
($! this :cljsDOMValue rendered-value)
($! node :value rendered-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 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 [node-value ($ node :value)]
(if (not= node-value dom-value)
;; IE has not notified us of the change yet, so check again later
(batch/do-after-render #(input-set-value this))
(let [existing-offset-from-end (- (count node-value)
($ node :selectionStart))
new-cursor-offset (- (count rendered-value)
existing-offset-from-end)]
($! this :cljsDOMValue rendered-value)
($! node :value rendered-value)
($! node :selectionStart new-cursor-offset)
($! node :selectionEnd new-cursor-offset)))))))))
(defn input-handle-change [this on-change e]
($! this :cljsDOMValue (-> e .-target .-value))
;; 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-after-render #(input-set-value this)))
(on-change e))
(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).
(when (and (some? jsprops)
(.hasOwnProperty jsprops "onChange")
(.hasOwnProperty jsprops "value"))
(let [v ($ jsprops :value)
value (if (nil? v) "" v)
on-change ($ jsprops :onChange)]
(when (nil? ($ this :cljsInputElement))
;; set initial value
($! this :cljsDOMValue value))
($! this :cljsRenderedValue value)
(js-delete jsprops "value")
(doto jsprops
($! :defaultValue value)
($! :onChange #(input-handle-change this on-change %))
($! :ref #($! this :cljsInputElement %1))))))
(defn ^boolean input-component? [x]
(case x
("input" "textarea") true
false))
(def reagent-input-class nil)
(declare make-element)
(def input-spec
{:display-name "ReagentInput"
:component-did-update input-set-value
: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-not (nil? class)
(string/replace class #"\." " "))]
(assert tag (str "Invalid tag: '" hiccup-tag "'"
(comp/comp-name)))
#js{:name tag
:id id
:className class}))
(defn try-get-key [x]
;; try catch to avoid clojurescript peculiarity with
;; sorted-maps with keys that are numbers
(try (get x :key)
(catch :default e)))
(defn get-key [x]
(when (map? x)
(try-get-key x)))
(defn key-from-vec [v]
(if-some [k (-> (meta v) get-key)]
k
(-> v (nth 1 nil) get-key)))
(defn reag-element [tag v]
(let [c (comp/as-class tag)
jsprops #js{:argv v}]
(when-some [key (key-from-vec v)]
($! jsprops :key key))
($ util/react createElement c jsprops)))
(defn adapt-react-class [c]
(doto (NativeWrapper.)
($! :name c)
($! :id nil)
($! :class nil)))
(def tag-name-cache #js{})
(defn cached-parse [x]
(if-some [s (cache-get tag-name-cache x)]
s
(aset tag-name-cache x (parse-tag x))))
(declare as-element)
(defn native-element [parsed argv first]
(let [comp ($ parsed :name)]
(let [props (nth argv first nil)
hasprops (or (nil? props) (map? props))
jsprops (convert-props (if hasprops props) parsed)
first-child (+ first (if hasprops 1 0))]
(if (input-component? comp)
(-> [(reagent-input) argv comp jsprops first-child]
(with-meta (meta argv))
as-element)
(let [key (-> (meta argv) get-key)
p (if (nil? key)
jsprops
(oset jsprops "key" key))]
(make-element argv comp p first-child))))))
(defn str-coll [coll]
(if (dev?)
(str (prewalk (fn [x]
(if (fn? x)
(let [n (util/fun-name x)]
(case n "" x (symbol n)))
x)) coll))
(str coll)))
(defn hiccup-err [v & msg]
(str (apply str msg) ": " (str-coll v) "\n" (comp/comp-name)))
(defn vec-to-elem [v]
(assert (pos? (count v)) (hiccup-err v "Hiccup form should not be empty"))
(let [tag (nth v 0 nil)]
(assert (valid-tag? tag) (hiccup-err v "Invalid Hiccup form"))
(cond
(hiccup-tag? tag)
(let [n (name tag)
pos (.indexOf n ">")]
(case pos
-1 (native-element (cached-parse n) v 1)
0 (let [comp (nth v 1 nil)]
;; Support [:> comp ...]
(assert (= ">" n) (hiccup-err v "Invalid Hiccup tag"))
(assert (or (string? comp) (fn? comp))
(hiccup-err v "Expected React component in"))
(native-element #js{:name comp} v 2))
;; 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 tag v 1)
:else (reag-element tag v))))
(declare expand-seq)
(declare expand-seq-check)
(defn as-element [x]
(cond (js-val? x) x
(vector? x) (vec-to-elem x)
(seq? x) (if (dev?)
(expand-seq-check x)
(expand-seq x))
(named? x) (name x)
(satisfies? IPrintWithWriter x) (pr-str x)
:else x))
(set! comp/as-element as-element)
(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 derefed] (ratom/check-derefs #(expand-seq-dev x ctx))]
(when derefed
(warn (hiccup-err x "Reactive deref not supported in lazy seq, "
"it should be wrapped in doall")))
(when ($ ctx :no-key)
(warn (hiccup-err x "Every element in a seq should have a unique :key")))
res))
;; From https://github.com/babel/babel/commit/1d0e68f5a19d721fe8799b1ea331041d8bf9120e
;; (def react-element-type (or (and (exists? js/Symbol)
;; ($ js/Symbol :for)
;; ($ js/Symbol for "react.element"))
;; 60103))
;; (defn make-element-fast [argv comp jsprops first-child]
;; (let [key (some-> jsprops ($ :key))
;; ref (some-> jsprops ($ :ref))
;; props (if (nil? jsprops) (js-obj) jsprops)]
;; ($! props :children
;; (case (- (count argv) first-child)
;; 0 nil
;; 1 (as-element (nth argv first-child))
;; (reduce-kv (fn [a k v]
;; (when (>= k first-child)
;; (.push a (as-element v)))
;; a)
;; #js[] argv)))
;; (js-obj "key" key
;; "ref" ref
;; "props" props
;; "$$typeof" react-element-type
;; "type" comp
;; ;; "_store" (js-obj)
;; )))
(defn make-element [argv comp jsprops first-child]
(case (- (count argv) first-child)
;; Optimize cases of zero or one child
0 ($ util/react createElement comp jsprops)
1 ($ util/react createElement comp jsprops
(as-element (nth argv first-child nil)))
(.apply ($ util/react :createElement) nil
(reduce-kv (fn [a k v]
(when (>= k first-child)
(.push a (as-element v)))
a)
#js[comp jsprops] argv))))

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,589 @@
// Compiled by ClojureScript 1.9.229 {}
goog.provide('reagent.impl.template');
goog.require('cljs.core');
goog.require('reagent.impl.util');
goog.require('reagent.impl.component');
goog.require('reagent.interop');
goog.require('reagent.ratom');
goog.require('reagent.impl.batching');
goog.require('clojure.string');
goog.require('reagent.debug');
goog.require('clojure.walk');
/**
* 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 (){
})
reagent.impl.template.NativeWrapper.getBasis = (function (){
return cljs.core.PersistentVector.EMPTY;
});
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__25736__auto__,writer__25737__auto__,opt__25738__auto__){
return cljs.core._write.call(null,writer__25737__auto__,"reagent.impl.template/NativeWrapper");
});
reagent.impl.template.__GT_NativeWrapper = (function reagent$impl$template$__GT_NativeWrapper(){
return (new reagent.impl.template.NativeWrapper());
});
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_.call(null,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_.call(null,x)) || (cljs.core.ifn_QMARK_.call(null,x)) || ((x instanceof reagent.impl.template.NativeWrapper));
});
reagent.impl.template.prop_name_cache = ({"class": "className", "for": "htmlFor", "charset": "charSet"});
reagent.impl.template.cache_get = (function reagent$impl$template$cache_get(o,k){
if(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_.call(null,k)){
var temp__4659__auto__ = reagent.impl.template.cache_get.call(null,reagent.impl.template.prop_name_cache,cljs.core.name.call(null,k));
if((temp__4659__auto__ == null)){
return (reagent.impl.template.prop_name_cache[cljs.core.name.call(null,k)] = reagent.impl.util.dash_to_camel.call(null,k));
} else {
var k_SINGLEQUOTE_ = temp__4659__auto__;
return k_SINGLEQUOTE_;
}
} else {
return k;
}
});
reagent.impl.template.js_val_QMARK_ = (function reagent$impl$template$js_val_QMARK_(x){
return !(("object" === goog.typeOf(x)));
});
reagent.impl.template.kv_conv = (function reagent$impl$template$kv_conv(o,k,v){
var G__26841 = o;
(G__26841[reagent.impl.template.cached_prop_name.call(null,k)] = reagent.impl.template.convert_prop_value.call(null,v));
return G__26841;
});
reagent.impl.template.convert_prop_value = (function reagent$impl$template$convert_prop_value(x){
if(reagent.impl.template.js_val_QMARK_.call(null,x)){
return x;
} else {
if(reagent.impl.template.named_QMARK_.call(null,x)){
return cljs.core.name.call(null,x);
} else {
if(cljs.core.map_QMARK_.call(null,x)){
return cljs.core.reduce_kv.call(null,reagent.impl.template.kv_conv,({}),x);
} else {
if(cljs.core.coll_QMARK_.call(null,x)){
return cljs.core.clj__GT_js.call(null,x);
} else {
if(cljs.core.ifn_QMARK_.call(null,x)){
return (function() {
var G__26842__delegate = function (args){
return cljs.core.apply.call(null,x,args);
};
var G__26842 = function (var_args){
var args = null;
if (arguments.length > 0) {
var G__26843__i = 0, G__26843__a = new Array(arguments.length - 0);
while (G__26843__i < G__26843__a.length) {G__26843__a[G__26843__i] = arguments[G__26843__i + 0]; ++G__26843__i;}
args = new cljs.core.IndexedSeq(G__26843__a,0);
}
return G__26842__delegate.call(this,args);};
G__26842.cljs$lang$maxFixedArity = 0;
G__26842.cljs$lang$applyTo = (function (arglist__26844){
var args = cljs.core.seq(arglist__26844);
return G__26842__delegate(args);
});
G__26842.cljs$core$IFn$_invoke$arity$variadic = G__26842__delegate;
return G__26842;
})()
;
} else {
return cljs.core.clj__GT_js.call(null,x);
}
}
}
}
}
});
reagent.impl.template.oset = (function reagent$impl$template$oset(o,k,v){
var G__26846 = (((o == null))?({}):o);
(G__26846[k] = v);
return G__26846;
});
reagent.impl.template.oget = (function reagent$impl$template$oget(o,k){
if((o == null)){
return null;
} else {
return (o[k]);
}
});
reagent.impl.template.set_id_class = (function reagent$impl$template$set_id_class(p,id_class){
var id = (id_class["id"]);
var p__$1 = (((cljs.core.some_QMARK_.call(null,id)) && ((reagent.impl.template.oget.call(null,p,"id") == null)))?reagent.impl.template.oset.call(null,p,"id",id):p);
var temp__4659__auto__ = (id_class["className"]);
if((temp__4659__auto__ == null)){
return p__$1;
} else {
var class$ = temp__4659__auto__;
var old = reagent.impl.template.oget.call(null,p__$1,"className");
return reagent.impl.template.oset.call(null,p__$1,"className",(((old == null))?class$:[cljs.core.str(class$),cljs.core.str(" "),cljs.core.str(old)].join('')));
}
});
reagent.impl.template.convert_props = (function reagent$impl$template$convert_props(props,id_class){
return reagent.impl.template.set_id_class.call(null,reagent.impl.template.convert_prop_value.call(null,props),id_class);
});
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_.call(null,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$["cljsInputElement"]);
if((temp__4661__auto__ == null)){
return null;
} else {
var node = temp__4661__auto__;
(this$["cljsInputDirty"] = false);
var rendered_value = (this$["cljsRenderedValue"]);
var dom_value = (this$["cljsDOMValue"]);
if(cljs.core.not_EQ_.call(null,rendered_value,dom_value)){
if(!(((node === (document["activeElement"]))) && (reagent.impl.template.has_selection_api_QMARK_.call(null,(node["type"]))) && (typeof rendered_value === 'string') && (typeof dom_value === 'string'))){
(this$["cljsDOMValue"] = rendered_value);
return (node["value"] = rendered_value);
} else {
var node_value = (node["value"]);
if(cljs.core.not_EQ_.call(null,node_value,dom_value)){
return reagent.impl.batching.do_after_render.call(null,((function (node_value,rendered_value,dom_value,node,temp__4661__auto__){
return (function (){
return reagent$impl$template$input_set_value.call(null,this$);
});})(node_value,rendered_value,dom_value,node,temp__4661__auto__))
);
} else {
var existing_offset_from_end = (cljs.core.count.call(null,node_value) - (node["selectionStart"]));
var new_cursor_offset = (cljs.core.count.call(null,rendered_value) - existing_offset_from_end);
(this$["cljsDOMValue"] = rendered_value);
(node["value"] = rendered_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){
(this$["cljsDOMValue"] = e.target.value);
if(cljs.core.truth_((this$["cljsInputDirty"]))){
} else {
(this$["cljsInputDirty"] = true);
reagent.impl.batching.do_after_render.call(null,(function (){
return reagent.impl.template.input_set_value.call(null,this$);
}));
}
return on_change.call(null,e);
});
reagent.impl.template.input_render_setup = (function reagent$impl$template$input_render_setup(this$,jsprops){
if(cljs.core.truth_((function (){var and__25118__auto__ = cljs.core.some_QMARK_.call(null,jsprops);
if(and__25118__auto__){
var and__25118__auto____$1 = jsprops.hasOwnProperty("onChange");
if(cljs.core.truth_(and__25118__auto____$1)){
return jsprops.hasOwnProperty("value");
} else {
return and__25118__auto____$1;
}
} else {
return and__25118__auto__;
}
})())){
var v = (jsprops["value"]);
var value = (((v == null))?"":v);
var on_change = (jsprops["onChange"]);
if(((this$["cljsInputElement"]) == null)){
(this$["cljsDOMValue"] = value);
} else {
}
(this$["cljsRenderedValue"] = value);
delete jsprops["value"];
var G__26850 = jsprops;
(G__26850["defaultValue"] = value);
(G__26850["onChange"] = ((function (G__26850,v,value,on_change){
return (function (p1__26847_SHARP_){
return reagent.impl.template.input_handle_change.call(null,this$,on_change,p1__26847_SHARP_);
});})(G__26850,v,value,on_change))
);
(G__26850["ref"] = ((function (G__26850,v,value,on_change){
return (function (p1__26848_SHARP_){
return (this$["cljsInputElement"] = p1__26848_SHARP_);
});})(G__26850,v,value,on_change))
);
return G__26850;
} else {
return null;
}
});
reagent.impl.template.input_component_QMARK_ = (function reagent$impl$template$input_component_QMARK_(x){
var G__26852 = x;
switch (G__26852) {
case "input":
case "textarea":
return true;
break;
default:
return false;
}
});
reagent.impl.template.reagent_input_class = null;
reagent.impl.template.input_spec = new cljs.core.PersistentArrayMap(null, 3, [new cljs.core.Keyword(null,"display-name","display-name",694513143),"ReagentInput",new cljs.core.Keyword(null,"component-did-update","component-did-update",-1468549173),reagent.impl.template.input_set_value,new cljs.core.Keyword(null,"reagent-render","reagent-render",-985383853),(function (argv,comp,jsprops,first_child){
var this$ = reagent.impl.component._STAR_current_component_STAR_;
reagent.impl.template.input_render_setup.call(null,this$,jsprops);
return 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.call(null,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__26857 = cljs.core.next.call(null,cljs.core.re_matches.call(null,reagent.impl.template.re_tag,cljs.core.name.call(null,hiccup_tag)));
var tag = cljs.core.nth.call(null,vec__26857,(0),null);
var id = cljs.core.nth.call(null,vec__26857,(1),null);
var class$ = cljs.core.nth.call(null,vec__26857,(2),null);
var class$__$1 = (((class$ == null))?null:clojure.string.replace.call(null,class$,/\./," "));
if(cljs.core.truth_(tag)){
} else {
throw (new Error([cljs.core.str("Assert failed: "),cljs.core.str([cljs.core.str("Invalid tag: '"),cljs.core.str(hiccup_tag),cljs.core.str("'"),cljs.core.str(reagent.impl.component.comp_name.call(null))].join('')),cljs.core.str("\n"),cljs.core.str("tag")].join('')));
}
return ({"name": tag, "id": id, "className": class$__$1});
});
reagent.impl.template.try_get_key = (function reagent$impl$template$try_get_key(x){
try{return cljs.core.get.call(null,x,new cljs.core.Keyword(null,"key","key",-1516042587));
}catch (e26861){var e = e26861;
return null;
}});
reagent.impl.template.get_key = (function reagent$impl$template$get_key(x){
if(cljs.core.map_QMARK_.call(null,x)){
return reagent.impl.template.try_get_key.call(null,x);
} else {
return null;
}
});
reagent.impl.template.key_from_vec = (function reagent$impl$template$key_from_vec(v){
var temp__4659__auto__ = reagent.impl.template.get_key.call(null,cljs.core.meta.call(null,v));
if((temp__4659__auto__ == null)){
return reagent.impl.template.get_key.call(null,cljs.core.nth.call(null,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.component.as_class.call(null,tag);
var jsprops = ({"argv": v});
var temp__4661__auto___26862 = reagent.impl.template.key_from_vec.call(null,v);
if((temp__4661__auto___26862 == null)){
} else {
var key_26863 = temp__4661__auto___26862;
(jsprops["key"] = key_26863);
}
return (reagent.impl.util.react["createElement"])(c,jsprops);
});
reagent.impl.template.adapt_react_class = (function reagent$impl$template$adapt_react_class(c){
var G__26865 = (new reagent.impl.template.NativeWrapper());
(G__26865["name"] = c);
(G__26865["id"] = null);
(G__26865["class"] = null);
return G__26865;
});
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.cache_get.call(null,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.call(null,x));
} else {
var s = temp__4659__auto__;
return s;
}
});
reagent.impl.template.native_element = (function reagent$impl$template$native_element(parsed,argv,first){
var comp = (parsed["name"]);
var props = cljs.core.nth.call(null,argv,first,null);
var hasprops = ((props == null)) || (cljs.core.map_QMARK_.call(null,props));
var jsprops = reagent.impl.template.convert_props.call(null,((hasprops)?props:null),parsed);
var first_child = (first + ((hasprops)?(1):(0)));
if(reagent.impl.template.input_component_QMARK_.call(null,comp)){
return reagent.impl.template.as_element.call(null,cljs.core.with_meta.call(null,new cljs.core.PersistentVector(null, 5, 5, cljs.core.PersistentVector.EMPTY_NODE, [reagent.impl.template.reagent_input.call(null),argv,comp,jsprops,first_child], null),cljs.core.meta.call(null,argv)));
} else {
var key = reagent.impl.template.get_key.call(null,cljs.core.meta.call(null,argv));
var p = (((key == null))?jsprops:reagent.impl.template.oset.call(null,jsprops,"key",key));
return reagent.impl.template.make_element.call(null,argv,comp,p,first_child);
}
});
reagent.impl.template.str_coll = (function reagent$impl$template$str_coll(coll){
return [cljs.core.str(clojure.walk.prewalk.call(null,(function (x){
if(cljs.core.fn_QMARK_.call(null,x)){
var n = reagent.impl.util.fun_name.call(null,x);
var G__26867 = n;
switch (G__26867) {
case "":
return x;
break;
default:
return cljs.core.symbol.call(null,n);
}
} else {
return x;
}
}),coll))].join('');
});
reagent.impl.template.hiccup_err = (function reagent$impl$template$hiccup_err(var_args){
var args__26212__auto__ = [];
var len__26205__auto___26871 = arguments.length;
var i__26206__auto___26872 = (0);
while(true){
if((i__26206__auto___26872 < len__26205__auto___26871)){
args__26212__auto__.push((arguments[i__26206__auto___26872]));
var G__26873 = (i__26206__auto___26872 + (1));
i__26206__auto___26872 = G__26873;
continue;
} else {
}
break;
}
var argseq__26213__auto__ = ((((1) < args__26212__auto__.length))?(new cljs.core.IndexedSeq(args__26212__auto__.slice((1)),(0),null)):null);
return reagent.impl.template.hiccup_err.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),argseq__26213__auto__);
});
reagent.impl.template.hiccup_err.cljs$core$IFn$_invoke$arity$variadic = (function (v,msg){
return [cljs.core.str(cljs.core.apply.call(null,cljs.core.str,msg)),cljs.core.str(": "),cljs.core.str(reagent.impl.template.str_coll.call(null,v)),cljs.core.str("\n"),cljs.core.str(reagent.impl.component.comp_name.call(null))].join('');
});
reagent.impl.template.hiccup_err.cljs$lang$maxFixedArity = (1);
reagent.impl.template.hiccup_err.cljs$lang$applyTo = (function (seq26869){
var G__26870 = cljs.core.first.call(null,seq26869);
var seq26869__$1 = cljs.core.next.call(null,seq26869);
return reagent.impl.template.hiccup_err.cljs$core$IFn$_invoke$arity$variadic(G__26870,seq26869__$1);
});
reagent.impl.template.vec_to_elem = (function reagent$impl$template$vec_to_elem(v){
while(true){
if((cljs.core.count.call(null,v) > (0))){
} else {
throw (new Error([cljs.core.str("Assert failed: "),cljs.core.str(reagent.impl.template.hiccup_err.call(null,v,"Hiccup form should not be empty")),cljs.core.str("\n"),cljs.core.str("(pos? (count v))")].join('')));
}
var tag = cljs.core.nth.call(null,v,(0),null);
if(reagent.impl.template.valid_tag_QMARK_.call(null,tag)){
} else {
throw (new Error([cljs.core.str("Assert failed: "),cljs.core.str(reagent.impl.template.hiccup_err.call(null,v,"Invalid Hiccup form")),cljs.core.str("\n"),cljs.core.str("(valid-tag? tag)")].join('')));
}
if(reagent.impl.template.hiccup_tag_QMARK_.call(null,tag)){
var n = cljs.core.name.call(null,tag);
var pos = n.indexOf(">");
var G__26875 = pos;
switch (G__26875) {
case (-1):
return reagent.impl.template.native_element.call(null,reagent.impl.template.cached_parse.call(null,n),v,(1));
break;
case (0):
var comp = cljs.core.nth.call(null,v,(1),null);
if(cljs.core._EQ_.call(null,">",n)){
} else {
throw (new Error([cljs.core.str("Assert failed: "),cljs.core.str(reagent.impl.template.hiccup_err.call(null,v,"Invalid Hiccup tag")),cljs.core.str("\n"),cljs.core.str("(= \">\" n)")].join('')));
}
if((typeof comp === 'string') || (cljs.core.fn_QMARK_.call(null,comp))){
} else {
throw (new Error([cljs.core.str("Assert failed: "),cljs.core.str(reagent.impl.template.hiccup_err.call(null,v,"Expected React component in")),cljs.core.str("\n"),cljs.core.str("(or (string? comp) (fn? comp))")].join('')));
}
return reagent.impl.template.native_element.call(null,({"name": comp}),v,(2));
break;
default:
var G__26877 = new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.subs.call(null,n,(0),pos),cljs.core.assoc.call(null,v,(0),cljs.core.subs.call(null,n,(pos + (1))))], null);
v = G__26877;
continue;
}
} else {
if((tag instanceof reagent.impl.template.NativeWrapper)){
return reagent.impl.template.native_element.call(null,tag,v,(1));
} else {
return reagent.impl.template.reag_element.call(null,tag,v);
}
}
break;
}
});
reagent.impl.template.as_element = (function reagent$impl$template$as_element(x){
if(reagent.impl.template.js_val_QMARK_.call(null,x)){
return x;
} else {
if(cljs.core.vector_QMARK_.call(null,x)){
return reagent.impl.template.vec_to_elem.call(null,x);
} else {
if(cljs.core.seq_QMARK_.call(null,x)){
return reagent.impl.template.expand_seq_check.call(null,x);
} else {
if(reagent.impl.template.named_QMARK_.call(null,x)){
return cljs.core.name.call(null,x);
} else {
if(((!((x == null)))?((((x.cljs$lang$protocol_mask$partition0$ & (2147483648))) || (x.cljs$core$IPrintWithWriter$))?true:(((!x.cljs$lang$protocol_mask$partition0$))?cljs.core.native_satisfies_QMARK_.call(null,cljs.core.IPrintWithWriter,x):false)):cljs.core.native_satisfies_QMARK_.call(null,cljs.core.IPrintWithWriter,x))){
return cljs.core.pr_str.call(null,x);
} else {
return x;
}
}
}
}
}
});
reagent.impl.component.as_element = reagent.impl.template.as_element;
reagent.impl.template.expand_seq = (function reagent$impl$template$expand_seq(s){
var a = cljs.core.into_array.call(null,s);
var n__26045__auto___26880 = a.length;
var i_26881 = (0);
while(true){
if((i_26881 < n__26045__auto___26880)){
(a[i_26881] = reagent.impl.template.as_element.call(null,(a[i_26881])));
var G__26882 = (i_26881 + (1));
i_26881 = G__26882;
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.call(null,s);
var n__26045__auto___26883 = a.length;
var i_26884 = (0);
while(true){
if((i_26884 < n__26045__auto___26883)){
var val_26885 = (a[i_26884]);
if((cljs.core.vector_QMARK_.call(null,val_26885)) && ((reagent.impl.template.key_from_vec.call(null,val_26885) == null))){
(o["no-key"] = true);
} else {
}
(a[i_26884] = reagent.impl.template.as_element.call(null,val_26885));
var G__26886 = (i_26884 + (1));
i_26884 = G__26886;
continue;
} else {
}
break;
}
return a;
});
reagent.impl.template.expand_seq_check = (function reagent$impl$template$expand_seq_check(x){
var ctx = ({});
var vec__26890 = reagent.ratom.check_derefs.call(null,((function (ctx){
return (function (){
return reagent.impl.template.expand_seq_dev.call(null,x,ctx);
});})(ctx))
);
var res = cljs.core.nth.call(null,vec__26890,(0),null);
var derefed = cljs.core.nth.call(null,vec__26890,(1),null);
if(cljs.core.truth_(derefed)){
if(cljs.core.truth_(reagent.debug.has_console)){
(cljs.core.truth_(reagent.debug.tracking)?reagent.debug.track_console:console).warn([cljs.core.str("Warning: "),cljs.core.str(reagent.impl.template.hiccup_err.call(null,x,"Reactive deref not supported in lazy seq, ","it should be wrapped in doall"))].join(''));
} else {
}
} else {
}
if(cljs.core.truth_((ctx["no-key"]))){
if(cljs.core.truth_(reagent.debug.has_console)){
(cljs.core.truth_(reagent.debug.tracking)?reagent.debug.track_console:console).warn([cljs.core.str("Warning: "),cljs.core.str(reagent.impl.template.hiccup_err.call(null,x,"Every element in a seq should have a unique :key"))].join(''));
} else {
}
} else {
}
return res;
});
reagent.impl.template.make_element = (function reagent$impl$template$make_element(argv,comp,jsprops,first_child){
var G__26894 = (cljs.core.count.call(null,argv) - first_child);
switch (G__26894) {
case (0):
return (reagent.impl.util.react["createElement"])(comp,jsprops);
break;
case (1):
return (reagent.impl.util.react["createElement"])(comp,jsprops,reagent.impl.template.as_element.call(null,cljs.core.nth.call(null,argv,first_child,null)));
break;
default:
return (reagent.impl.util.react["createElement"]).apply(null,cljs.core.reduce_kv.call(null,((function (G__26894){
return (function (a,k,v){
if((k >= first_child)){
a.push(reagent.impl.template.as_element.call(null,v));
} else {
}
return a;
});})(G__26894))
,[comp,jsprops],argv));
}
});
//# sourceMappingURL=template.js.map?rel=1603199188788

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,102 @@
(ns reagent.impl.util
(:require [cljsjs.react]
[reagent.debug :refer-macros [dbg log warn]]
[reagent.interop :refer-macros [$ $!]]
[clojure.string :as string]))
(defonce react
(cond (exists? js/React) js/React
(exists? js/require) (or (js/require "react")
(throw (js/Error. "require('react') failed")))
:else (throw (js/Error. "js/React is missing"))))
(def is-client (and (exists? js/window)
(-> js/window ($ :document) nil? not)))
(def ^:dynamic ^boolean *non-reactive* false)
;;; Props accessors
;; 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))))))
(defn fun-name [f]
(let [n (or (and (fn? f)
(or ($ f :displayName)
($ f :name)))
(and (implements? INamed f)
(name f))
(let [m (meta f)]
(if (map? m)
(:name m))))]
(-> n
str
(clojure.string/replace "$" "."))))
(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)
(defn force-update [comp deep]
(if deep
(binding [*always-update* true]
($ comp forceUpdate))
($ comp forceUpdate)))

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,277 @@
// Compiled by ClojureScript 1.9.229 {}
goog.provide('reagent.impl.util');
goog.require('cljs.core');
goog.require('cljsjs.react');
goog.require('reagent.debug');
goog.require('reagent.interop');
goog.require('clojure.string');
if(typeof reagent.impl.util.react !== 'undefined'){
} else {
reagent.impl.util.react = ((typeof React !== 'undefined')?React:((typeof require !== 'undefined')?(function (){var or__25130__auto__ = require("react");
if(cljs.core.truth_(or__25130__auto__)){
return or__25130__auto__;
} else {
throw (new Error("require('react') failed"));
}
})():(function(){throw (new Error("js/React is missing"))})()
));
}
reagent.impl.util.is_client = (typeof window !== 'undefined') && (!(((window["document"]) == null)));
reagent.impl.util._STAR_non_reactive_STAR_ = false;
reagent.impl.util.memoize_1 = (function reagent$impl$util$memoize_1(f){
var mem = cljs.core.atom.call(null,cljs.core.PersistentArrayMap.EMPTY);
return ((function (mem){
return (function (arg){
var v = cljs.core.get.call(null,cljs.core.deref.call(null,mem),arg);
if(!((v == null))){
return v;
} else {
var ret = f.call(null,arg);
cljs.core.swap_BANG_.call(null,mem,cljs.core.assoc,arg,ret);
return ret;
}
});
;})(mem))
});
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.call(null,s) < (2))){
return clojure.string.upper_case.call(null,s);
} else {
return [cljs.core.str(clojure.string.upper_case.call(null,cljs.core.subs.call(null,s,(0),(1)))),cljs.core.str(cljs.core.subs.call(null,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.call(null,dashed);
var vec__26420 = clojure.string.split.call(null,name_str,/-/);
var seq__26421 = cljs.core.seq.call(null,vec__26420);
var first__26422 = cljs.core.first.call(null,seq__26421);
var seq__26421__$1 = cljs.core.next.call(null,seq__26421);
var start = first__26422;
var parts = seq__26421__$1;
if(cljs.core.truth_(reagent.impl.util.dont_camel_case.call(null,start))){
return name_str;
} else {
return cljs.core.apply.call(null,cljs.core.str,start,cljs.core.map.call(null,reagent.impl.util.capitalize,parts));
}
}
});
reagent.impl.util.fun_name = (function reagent$impl$util$fun_name(f){
var n = (function (){var or__25130__auto__ = (function (){var and__25118__auto__ = cljs.core.fn_QMARK_.call(null,f);
if(and__25118__auto__){
var or__25130__auto__ = (f["displayName"]);
if(cljs.core.truth_(or__25130__auto__)){
return or__25130__auto__;
} else {
return (f["name"]);
}
} else {
return and__25118__auto__;
}
})();
if(cljs.core.truth_(or__25130__auto__)){
return or__25130__auto__;
} else {
var or__25130__auto____$1 = (function (){var and__25118__auto__ = ((!((f == null)))?((((f.cljs$lang$protocol_mask$partition1$ & (4096))) || (f.cljs$core$INamed$))?true:false):false);
if(and__25118__auto__){
return cljs.core.name.call(null,f);
} else {
return and__25118__auto__;
}
})();
if(cljs.core.truth_(or__25130__auto____$1)){
return or__25130__auto____$1;
} else {
var m = cljs.core.meta.call(null,f);
if(cljs.core.map_QMARK_.call(null,m)){
return new cljs.core.Keyword(null,"name","name",1843675177).cljs$core$IFn$_invoke$arity$1(m);
} else {
return null;
}
}
}
})();
return clojure.string.replace.call(null,[cljs.core.str(n)].join(''),"$",".");
});
/**
* @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__26432__delegate = function (self__,a){
var self____$1 = this;
var _ = self____$1;
var or__25130__auto___26433 = self__.p;
if(cljs.core.truth_(or__25130__auto___26433)){
} else {
self__.p = cljs.core.apply.call(null,cljs.core.partial,self__.f,self__.args);
}
return cljs.core.apply.call(null,self__.p,a);
};
var G__26432 = function (self__,var_args){
var self__ = this;
var a = null;
if (arguments.length > 1) {
var G__26434__i = 0, G__26434__a = new Array(arguments.length - 1);
while (G__26434__i < G__26434__a.length) {G__26434__a[G__26434__i] = arguments[G__26434__i + 1]; ++G__26434__i;}
a = new cljs.core.IndexedSeq(G__26434__a,0);
}
return G__26432__delegate.call(this,self__,a);};
G__26432.cljs$lang$maxFixedArity = 1;
G__26432.cljs$lang$applyTo = (function (arglist__26435){
var self__ = cljs.core.first(arglist__26435);
var a = cljs.core.rest(arglist__26435);
return G__26432__delegate(self__,a);
});
G__26432.cljs$core$IFn$_invoke$arity$variadic = G__26432__delegate;
return G__26432;
})()
;
reagent.impl.util.partial_ifn.prototype.apply = (function (self__,args26431){
var self__ = this;
var self____$1 = this;
return self____$1.call.apply(self____$1,[self____$1].concat(cljs.core.aclone.call(null,args26431)));
});
reagent.impl.util.partial_ifn.prototype.cljs$core$IFn$_invoke$arity$2 = (function() {
var G__26436__delegate = function (a){
var _ = this;
var or__25130__auto___26437 = self__.p;
if(cljs.core.truth_(or__25130__auto___26437)){
} else {
self__.p = cljs.core.apply.call(null,cljs.core.partial,self__.f,self__.args);
}
return cljs.core.apply.call(null,self__.p,a);
};
var G__26436 = function (var_args){
var self__ = this;
var a = null;
if (arguments.length > 0) {
var G__26438__i = 0, G__26438__a = new Array(arguments.length - 0);
while (G__26438__i < G__26438__a.length) {G__26438__a[G__26438__i] = arguments[G__26438__i + 0]; ++G__26438__i;}
a = new cljs.core.IndexedSeq(G__26438__a,0);
}
return G__26436__delegate.call(this,a);};
G__26436.cljs$lang$maxFixedArity = 0;
G__26436.cljs$lang$applyTo = (function (arglist__26439){
var a = cljs.core.seq(arglist__26439);
return G__26436__delegate(a);
});
G__26436.cljs$core$IFn$_invoke$arity$variadic = G__26436__delegate;
return G__26436;
})()
;
reagent.impl.util.partial_ifn.prototype.cljs$core$IEquiv$_equiv$arity$2 = (function (_,other){
var self__ = this;
var ___$1 = this;
return (cljs.core._EQ_.call(null,self__.f,other.f)) && (cljs.core._EQ_.call(null,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.call(null,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, [new cljs.core.Symbol(null,"f","f",43394975,null),new cljs.core.Symbol(null,"args","args",-1338879193,null),cljs.core.with_meta(new cljs.core.Symbol(null,"p","p",1791580836,null),new cljs.core.PersistentArrayMap(null, 1, [new cljs.core.Keyword(null,"mutable","mutable",875778266),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__25736__auto__,writer__25737__auto__,opt__25738__auto__){
return cljs.core._write.call(null,writer__25737__auto__,"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__ = new cljs.core.Keyword(null,"class","class",-2030961996).cljs$core$IFn$_invoke$arity$1(p1);
if(cljs.core.truth_(temp__4657__auto__)){
var c1 = temp__4657__auto__;
var temp__4657__auto____$1 = new cljs.core.Keyword(null,"class","class",-2030961996).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(c1),cljs.core.str(" "),cljs.core.str(c2)].join('');
} else {
return null;
}
} else {
return null;
}
})();
if((class$ == null)){
return p2;
} else {
return cljs.core.assoc.call(null,p2,new cljs.core.Keyword(null,"class","class",-2030961996),class$);
}
});
reagent.impl.util.merge_style = (function reagent$impl$util$merge_style(p1,p2){
var style = (function (){var temp__4657__auto__ = new cljs.core.Keyword(null,"style","style",-496642736).cljs$core$IFn$_invoke$arity$1(p1);
if(cljs.core.truth_(temp__4657__auto__)){
var s1 = temp__4657__auto__;
var temp__4657__auto____$1 = new cljs.core.Keyword(null,"style","style",-496642736).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.call(null,s1,s2);
} else {
return null;
}
} else {
return null;
}
})();
if((style == null)){
return p2;
} else {
return cljs.core.assoc.call(null,p2,new cljs.core.Keyword(null,"style","style",-496642736),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_.call(null,p1)){
} else {
throw (new Error("Assert failed: (map? p1)"));
}
return reagent.impl.util.merge_style.call(null,p1,reagent.impl.util.merge_class.call(null,p1,cljs.core.merge.call(null,p1,p2)));
}
});
reagent.impl.util._STAR_always_update_STAR_ = false;
reagent.impl.util.force_update = (function reagent$impl$util$force_update(comp,deep){
if(cljs.core.truth_(deep)){
var _STAR_always_update_STAR_26441 = reagent.impl.util._STAR_always_update_STAR_;
reagent.impl.util._STAR_always_update_STAR_ = true;
try{return (comp["forceUpdate"])();
}finally {reagent.impl.util._STAR_always_update_STAR_ = _STAR_always_update_STAR_26441;
}} else {
return (comp["forceUpdate"])();
}
});
//# sourceMappingURL=util.js.map?rel=1603199187075

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,2 @@
(ns reagent.interop
(:require-macros [reagent.interop]))

View file

@ -0,0 +1 @@
{:rename-macros {}, :renames {}, :use-macros {}, :excludes #{}, :name reagent.interop, :imports nil, :requires nil, :uses nil, :require-macros {reagent.interop reagent.interop}, :doc nil}

View file

@ -0,0 +1,5 @@
// Compiled by ClojureScript 1.9.229 {}
goog.provide('reagent.interop');
goog.require('cljs.core');
//# sourceMappingURL=interop.js.map?rel=1603199186592

View file

@ -0,0 +1 @@
{"version":3,"file":"\/Users\/simon\/workspace\/swinging-needle-meter\/docs\/js\/compiled\/out\/reagent\/interop.js","sources":["interop.cljs?rel=1603199186598"],"lineCount":5,"mappings":";AAAA","names":[]}

View file

@ -0,0 +1,592 @@
(ns reagent.ratom
(:refer-clojure :exclude [atom])
(:require-macros [reagent.ratom :refer [with-let]])
(:require [reagent.impl.util :as util]
[reagent.debug :refer-macros [dbg log warn error dev? time]]
[reagent.impl.batching :as batch]
[clojure.set :as s]))
(declare ^:dynamic *ratom-context*)
(defonce ^boolean debug false)
(defonce ^:private generation 0)
(defonce ^:private -running (clojure.core/atom 0))
(defn ^boolean reactive? []
(some? *ratom-context*))
;;; Utilities
(defn running []
(+ @-running))
(defn- ^number arr-len [x]
(if (nil? x) 0 (alength x)))
(defn- ^boolean arr-eq [x y]
(let [len (arr-len x)]
(and (== len (arr-len y))
(loop [i 0]
(or (== i len)
(if (identical? (aget x i) (aget y i))
(recur (inc i))
false))))))
(defn- in-context [obj f]
(binding [*ratom-context* obj]
(f)))
(defn- deref-capture [f r]
(set! (.-captured r) nil)
(when (dev?)
(set! (.-ratomGeneration r) (set! generation (inc generation))))
(let [res (in-context r f)
c (.-captured r)]
(set! (.-dirty? r) false)
;; Optimize common case where derefs occur in same order
(when-not (arr-eq c (.-watching r))
(._update-watching r c))
res))
(defn- notify-deref-watcher! [derefed]
(when-some [r *ratom-context*]
(let [c (.-captured r)]
(if (nil? c)
(set! (.-captured r) (array derefed))
(.push c derefed)))))
(defn- check-watches [old new]
(when debug
(swap! -running + (- (count new) (count old))))
new)
(defn- add-w [this key f]
(let [w (.-watches this)]
(set! (.-watches this) (check-watches w (assoc w key f)))
(set! (.-watchesArr this) nil)))
(defn- remove-w [this key]
(let [w (.-watches this)]
(set! (.-watches this) (check-watches w (dissoc w key)))
(set! (.-watchesArr this) nil)))
(defn- notify-w [this old new]
(let [w (.-watchesArr this)
a (if (nil? w)
;; Copy watches to array for speed
(->> (.-watches this)
(reduce-kv #(doto %1 (.push %2) (.push %3)) #js[])
(set! (.-watchesArr this)))
w)]
(let [len (alength a)]
(loop [i 0]
(when (< i len)
(let [k (aget a i)
f (aget a (inc i))]
(f k this old new))
(recur (+ 2 i)))))))
(defn- pr-atom [a writer opts s]
(-write writer (str "#<" s " "))
(pr-writer (binding [*ratom-context* nil] (-deref a)) writer opts)
(-write writer ">"))
;;; Queueing
(defonce ^:private rea-queue nil)
(defn- rea-enqueue [r]
(when (nil? rea-queue)
(set! rea-queue (array))
(batch/schedule))
(.push rea-queue r))
(defn flush! []
(loop []
(let [q rea-queue]
(when-not (nil? q)
(set! rea-queue nil)
(dotimes [i (alength q)]
(._queued-run (aget q i)))
(recur)))))
(set! batch/ratom-flush flush!)
;;; Atom
(defprotocol IReactiveAtom)
(deftype RAtom [^:mutable state meta validator ^:mutable watches]
IAtom
IReactiveAtom
IEquiv
(-equiv [o other] (identical? o other))
IDeref
(-deref [this]
(notify-deref-watcher! this)
state)
IReset
(-reset! [a new-value]
(when-not (nil? validator)
(assert (validator new-value) "Validator rejected reference state"))
(let [old-value state]
(set! state new-value)
(when-not (nil? watches)
(notify-w a old-value new-value))
new-value))
ISwap
(-swap! [a f] (-reset! a (f state)))
(-swap! [a f x] (-reset! a (f state x)))
(-swap! [a f x y] (-reset! a (f state x y)))
(-swap! [a f x y more] (-reset! a (apply f state x y more)))
IMeta
(-meta [_] meta)
IPrintWithWriter
(-pr-writer [a w opts] (pr-atom a w opts "Atom:"))
IWatchable
(-notify-watches [this old new] (notify-w this old new))
(-add-watch [this key f] (add-w this key f))
(-remove-watch [this key] (remove-w this key))
IHash
(-hash [this] (goog/getUid this)))
(defn atom
"Like clojure.core/atom, except that it keeps track of derefs."
([x] (RAtom. x nil nil nil))
([x & {:keys [meta validator]}] (RAtom. x meta validator nil)))
;;; track
(declare make-reaction)
(def ^{:private true :const true} cache-key "reagReactionCache")
(defn- cached-reaction [f o k obj destroy]
(let [m (aget o cache-key)
m (if (nil? m) {} m)
r (m k nil)]
(cond
(some? r) (-deref r)
(nil? *ratom-context*) (f)
:else (let [r (make-reaction
f :on-dispose (fn [x]
(when debug (swap! -running dec))
(as-> (aget o cache-key) _
(dissoc _ k)
(aset o cache-key _))
(when (some? obj)
(set! (.-reaction obj) nil))
(when (some? destroy)
(destroy x))))
v (-deref r)]
(aset o cache-key (assoc m k r))
(when debug (swap! -running inc))
(when (some? obj)
(set! (.-reaction obj) r))
v))))
(deftype Track [f args ^:mutable reaction]
IReactiveAtom
IDeref
(-deref [this]
(if-some [r reaction]
(-deref r)
(cached-reaction #(apply f args) f args this nil)))
IEquiv
(-equiv [_ other]
(and (instance? Track other)
(= f (.-f other))
(= args (.-args other))))
IHash
(-hash [_] (hash [f args]))
IPrintWithWriter
(-pr-writer [a w opts] (pr-atom a w opts "Track:")))
(defn make-track [f args]
(Track. f args nil))
(defn make-track! [f args]
(let [t (make-track f args)
r (make-reaction #(-deref t)
:auto-run true)]
@r
r))
(defn track [f & args]
{:pre [(ifn? f)]}
(make-track f args))
(defn track! [f & args]
{:pre [(ifn? f)]}
(make-track! f args))
;;; cursor
(deftype RCursor [ratom path ^:mutable reaction
^:mutable state ^:mutable watches]
IAtom
IReactiveAtom
IEquiv
(-equiv [_ other]
(and (instance? RCursor other)
(= path (.-path other))
(= ratom (.-ratom other))))
Object
(_peek [this]
(binding [*ratom-context* nil]
(-deref this)))
(_set-state [this oldstate newstate]
(when-not (identical? oldstate newstate)
(set! state newstate)
(when (some? watches)
(notify-w this oldstate newstate))))
IDeref
(-deref [this]
(let [oldstate state
newstate (if-some [r reaction]
(-deref r)
(let [f (if (satisfies? IDeref ratom)
#(get-in @ratom path)
#(ratom path))]
(cached-reaction f ratom path this nil)))]
(._set-state this oldstate newstate)
newstate))
IReset
(-reset! [this new-value]
(let [oldstate state]
(._set-state this oldstate new-value)
(if (satisfies? IDeref ratom)
(if (= path [])
(reset! ratom new-value)
(swap! ratom assoc-in path new-value))
(ratom path new-value))
new-value))
ISwap
(-swap! [a f] (-reset! a (f (._peek a))))
(-swap! [a f x] (-reset! a (f (._peek a) x)))
(-swap! [a f x y] (-reset! a (f (._peek a) x y)))
(-swap! [a f x y more] (-reset! a (apply f (._peek a) x y more)))
IPrintWithWriter
(-pr-writer [a w opts] (pr-atom a w opts (str "Cursor: " path)))
IWatchable
(-notify-watches [this old new] (notify-w this old new))
(-add-watch [this key f] (add-w this key f))
(-remove-watch [this key] (remove-w this key))
IHash
(-hash [_] (hash [ratom path])))
(defn cursor
[src path]
(assert (or (satisfies? IReactiveAtom src)
(and (ifn? src)
(not (vector? src))))
(str "src must be a reactive atom or a function, not "
(pr-str src)))
(RCursor. src path nil nil nil))
;;; with-let support
(defn with-let-destroy [v]
(when-some [f (.-destroy v)]
(f)))
(defn with-let-values [key]
(if-some [c *ratom-context*]
(cached-reaction array c key
nil with-let-destroy)
(array)))
;;;; reaction
(defprotocol IDisposable
(dispose! [this])
(add-on-dispose! [this f]))
(defprotocol IRunnable
(run [this]))
(defn- handle-reaction-change [this sender old new]
(._handle-change this sender old new))
(deftype Reaction [f ^:mutable state ^:mutable ^boolean dirty? ^boolean nocache?
^:mutable watching ^:mutable watches ^:mutable auto-run
^:mutable caught]
IAtom
IReactiveAtom
IWatchable
(-notify-watches [this old new] (notify-w this old new))
(-add-watch [this key f] (add-w this key f))
(-remove-watch [this key]
(let [was-empty (empty? watches)]
(remove-w this key)
(when (and (not was-empty)
(empty? watches)
(nil? auto-run))
(dispose! this))))
IReset
(-reset! [a newval]
(assert (fn? (.-on-set a)) "Reaction is read only.")
(let [oldval state]
(set! state newval)
(.on-set a oldval newval)
(notify-w a oldval newval)
newval))
ISwap
(-swap! [a f] (-reset! a (f (._peek-at a))))
(-swap! [a f x] (-reset! a (f (._peek-at a) x)))
(-swap! [a f x y] (-reset! a (f (._peek-at a) x y)))
(-swap! [a f x y more] (-reset! a (apply f (._peek-at a) x y more)))
Object
(_peek-at [this]
(binding [*ratom-context* nil]
(-deref this)))
(_handle-change [this sender oldval newval]
(when-not (or (identical? oldval newval)
dirty?)
(if (nil? auto-run)
(do
(set! dirty? true)
(rea-enqueue this))
(if (true? auto-run)
(._run this false)
(auto-run this)))))
(_update-watching [this derefed]
(let [new (set derefed)
old (set watching)]
(set! watching derefed)
(doseq [w (s/difference new old)]
(-add-watch w this handle-reaction-change))
(doseq [w (s/difference old new)]
(-remove-watch w this))))
(_queued-run [this]
(when (and dirty? (some? watching))
(._run this true)))
(_try-capture [this f]
(try
(set! caught nil)
(deref-capture f this)
(catch :default e
(set! state e)
(set! caught e)
(set! dirty? false))))
(_run [this check]
(let [oldstate state
res (if check
(._try-capture this f)
(deref-capture f this))]
(when-not nocache?
(set! state res)
;; Use = to determine equality from reactions, since
;; they are likely to produce new data structures.
(when-not (or (nil? watches)
(= oldstate res))
(notify-w this oldstate res)))
res))
(_set-opts [this {:keys [auto-run on-set on-dispose no-cache]}]
(when (some? auto-run)
(set! (.-auto-run this) auto-run))
(when (some? on-set)
(set! (.-on-set this) on-set))
(when (some? on-dispose)
(set! (.-on-dispose this) on-dispose))
(when (some? no-cache)
(set! (.-nocache? this) no-cache)))
IRunnable
(run [this]
(flush!)
(._run this false))
IDeref
(-deref [this]
(when-some [e caught]
(throw e))
(let [non-reactive (nil? *ratom-context*)]
(when non-reactive
(flush!))
(if (and non-reactive (nil? auto-run))
(when dirty?
(let [oldstate state]
(set! state (f))
(when-not (or (nil? watches) (= oldstate state))
(notify-w this oldstate state))))
(do
(notify-deref-watcher! this)
(when dirty?
(._run this false)))))
state)
IDisposable
(dispose! [this]
(let [s state
wg watching]
(set! watching nil)
(set! state nil)
(set! auto-run nil)
(set! dirty? true)
(doseq [w (set wg)]
(-remove-watch w this))
(when (some? (.-on-dispose this))
(.on-dispose this s))
(when-some [a (.-on-dispose-arr this)]
(dotimes [i (alength a)]
((aget a i) this)))))
(add-on-dispose! [this f]
;; f is called with the reaction as argument when it is no longer active
(if-some [a (.-on-dispose-arr this)]
(.push a f)
(set! (.-on-dispose-arr this) (array f))))
IEquiv
(-equiv [o other] (identical? o other))
IPrintWithWriter
(-pr-writer [a w opts] (pr-atom a w opts (str "Reaction " (hash a) ":")))
IHash
(-hash [this] (goog/getUid this)))
(defn make-reaction [f & {:keys [auto-run on-set on-dispose]}]
(let [reaction (Reaction. f nil true false nil nil nil nil)]
(._set-opts reaction {:auto-run auto-run
:on-set on-set
:on-dispose on-dispose})
reaction))
(def ^:private temp-reaction (make-reaction nil))
(defn run-in-reaction [f obj key run opts]
(let [r temp-reaction
res (deref-capture f r)]
(when-not (nil? (.-watching r))
(set! temp-reaction (make-reaction nil))
(._set-opts r opts)
(set! (.-f r) f)
(set! (.-auto-run r) #(run obj))
(aset obj key r))
res))
(defn check-derefs [f]
(let [ctx (js-obj)
res (in-context ctx f)]
[res (some? (.-captured ctx))]))
;;; wrap
(deftype Wrapper [^:mutable state callback ^:mutable ^boolean changed
^:mutable watches]
IAtom
IDeref
(-deref [this]
(when (dev?)
(when (and changed (some? *ratom-context*))
(warn "derefing stale wrap: "
(pr-str this))))
state)
IReset
(-reset! [this newval]
(let [oldval state]
(set! changed true)
(set! state newval)
(when (some? watches)
(notify-w this oldval newval))
(callback newval)
newval))
ISwap
(-swap! [a f] (-reset! a (f state)))
(-swap! [a f x] (-reset! a (f state x)))
(-swap! [a f x y] (-reset! a (f state x y)))
(-swap! [a f x y more] (-reset! a (apply f state x y more)))
IEquiv
(-equiv [_ other]
(and (instance? Wrapper other)
;; If either of the wrappers have changed, equality
;; cannot be relied on.
(not changed)
(not (.-changed other))
(= state (.-state other))
(= callback (.-callback other))))
IWatchable
(-notify-watches [this old new] (notify-w this old new))
(-add-watch [this key f] (add-w this key f))
(-remove-watch [this key] (remove-w this key))
IPrintWithWriter
(-pr-writer [a w opts] (pr-atom a w opts "Wrap:")))
(defn make-wrapper [value callback-fn args]
(Wrapper. value
(util/partial-ifn. callback-fn args nil)
false nil))
#_(do
(defn ratom-perf []
(set! debug false)
(dotimes [_ 10]
(let [nite 100000
a (atom 0)
f (fn []
(quot @a 10))
mid (make-reaction f)
res (track! (fn []
;; (with-let [x 1])
;; @(track f)
(inc @mid)
))]
@res
(time (dotimes [x nite]
(swap! a inc)
(flush!)))
(dispose! res))))
(ratom-perf))

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load diff

File diff suppressed because one or more lines are too long