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