(-legal-keys query)
PRIVATE. Find the legal keys in a query. NOTE: This is at compile time, so the get-query calls are still embedded (thus cannot use the AST)
PRIVATE. Find the legal keys in a query. NOTE: This is at compile time, so the get-query calls are still embedded (thus cannot use the AST)
(any->app x)
Attempt to coerce x
to a reconciler. Legal inputs are a fulcro application, reconciler, a mounted component, a
map with a :reconciler key, or an atom holding any of the above.
Attempt to coerce `x` to a reconciler. Legal inputs are a fulcro application, reconciler, a mounted component, a map with a :reconciler key, or an atom holding any of the above.
(children component)
Get the sequence of react children of the given component.
Get the sequence of react children of the given component.
(class->all x class)
Get all components from the indexes that are instances of the component class.
x
can be anything any->app
is ok with.
Get all components from the indexes that are instances of the component class. `x` can be anything `any->app` is ok with.
(class->any x cls)
Get any component from the indexes that are instances of the component class.
x
can be anything any->app
is ok with.
Get any component from the indexes that are instances of the component class. `x` can be anything `any->app` is ok with.
(class->registry-key class)
Returns the registry key for the given component class.
Returns the registry key for the given component class.
(component->state-map this)
Returns the current value of the state map via a component instance. Note that it is not safe to render arbitrary data from the state map since Fulcro will have no idea that it should refresh a component that does so; however, it is sometimes useful to look at the state map for information that doesn't change over time.
Returns the current value of the state map via a component instance. Note that it is not safe to render arbitrary data from the state map since Fulcro will have no idea that it should refresh a component that does so; however, it is sometimes useful to look at the state map for information that doesn't change over time.
(component-class? x)
Returns true if the argument is a component class.
Returns true if the argument is a component class.
(component-instance? x)
Returns true if the argument is a component. A component is defined as a mounted component. This function returns false for component classes, and also returns false for the output of a Fulcro component factory.
Returns true if the argument is a component. A component is defined as a *mounted component*. This function returns false for component classes, and also returns false for the output of a Fulcro component factory.
(component-name class)
Returns a string version of the given react component's name. Works on component instances and classes.
Returns a string version of the given react component's name. Works on component instances and classes.
Returns true if the argument is a component instance.
DEPRECATED for terminology clarity. Use component-instance?
instead.
Returns true if the argument is a component instance. DEPRECATED for terminology clarity. Use `component-instance?` instead.
(compressible-transact! comp-or-reconciler tx)
(compressible-transact! comp-or-reconciler ref tx)
Identical to transact!
, but marks the history edge as compressible. This means that if more than one
adjacent history transition edge is compressible, only the more recent of the sequence of them is kept. This
is useful for things like form input fields, where storing every keystoke in history is undesirable. This
also compress the transactions in Fulcro Inspect.
NOTE: history events that trigger remote interactions are not compressible, since they may be needed for automatic network error recovery handling.
Identical to `transact!`, but marks the history edge as compressible. This means that if more than one adjacent history transition edge is compressible, only the more recent of the sequence of them is kept. This is useful for things like form input fields, where storing every keystoke in history is undesirable. This also compress the transactions in Fulcro Inspect. NOTE: history events that trigger remote interactions are not compressible, since they may be needed for automatic network error recovery handling.
(computed props computed-map)
Add computed properties to props. Note will replace any pre-existing computed properties.
Add computed properties to props. Note will replace any pre-existing computed properties.
(computed-factory class)
(computed-factory class options)
Similar to factory, but returns a function with the signature [props computed & children] instead of default [props & children]. This makes easier to send computed.
Similar to factory, but returns a function with the signature [props computed & children] instead of default [props & children]. This makes easier to send computed.
(computed-initial-state? s)
Returns true if the given initial state was computed from a call to get-initial-state.
Returns true if the given initial state was computed from a call to get-initial-state.
(configure-component! cls fqkw options)
Configure the given cls
to act as a react component.
Configure the given `cls` to act as a react component.
(create-element class props children)
Create a react element. In CLJ this returns the same thing as a mounted instance, whereas in CLJS it is an element (which has yet to instantiate an instance).
Create a react element. In CLJ this returns the same thing as a mounted instance, whereas in CLJS it is an element (which has yet to instantiate an instance).
(defsc & args)
Define a stateful component. This macro emits a React UI class with a query, optional ident (if :ident is specified in options), optional initial state, optional css, lifecycle methods, and a render method. It can also cause the class to implement additional protocols that you specify. Destructuring is supported in the argument list.
The template (data-only) versions do not have any arguments in scope The lambda versions have arguments in scope that make sense for those lambdas, as listed below:
(defsc Component [this {:keys [db/id x] :as props} {:keys [onSelect] :as computed} extended-args]
{
;; stateful component options
;; query template is literal. Use the lambda if you have ident-joins or unions.
:query [:db/id :x] ; OR (fn [] [:db/id :x]) ; this in scope
;; ident template is table name and ID property name
:ident [:table/by-id :id] ; OR (fn [] [:table/by-id id]) ; this and props in scope
;; initial-state template is magic..see dev guide. Lambda version is normal.
:initial-state {:x :param/x} ; OR (fn [params] {:x (:x params)}) ; nothing is in scope
;; pre-merge, use a lamba to modify new merged data with component needs
:pre-merge (fn [{:keys [...]}] (merge {:ui/default-value :start} tree))
; React Lifecycle Methods (this in scope)
:initLocalState (fn [this props] ...) ; CAN BE used to call things as you might in a constructor. Return value is initial state.
:shouldComponentUpdate (fn [this next-props next-state] ...)
:componentDidUpdate (fn [this prev-props prev-state snapshot] ...) ; snapshot is optional, and is 16+. Is context for 15
:componentDidMount (fn [this] ...)
:componentWillUnmount (fn [this] ...)
;; DEPRECATED IN REACT 16 (to be removed in 17):
:componentWillReceiveProps (fn [this next-props] ...)
:componentWillUpdate (fn [this next-props next-state] ...)
:componentWillMount (fn [this] ...)
;; Replacements for deprecated methods in React 16.3+
:UNSAFE_componentWillReceiveProps (fn [this next-props] ...)
:UNSAFE_componentWillUpdate (fn [this next-props next-state] ...)
:UNSAFE_componentWillMount (fn [this] ...)
;; ADDED for React 16:
:componentDidCatch (fn [this error info] ...)
:getSnapshotBeforeUpdate (fn [this prevProps prevState] ...)
;; static
:getDerivedStateFromProps (fn [props state] ...)
;; ADDED for React 16.6:
:getDerivedStateFromError (fn [error] ...) **NOTE**: OVERWRITES entire state. This differs slightly from React.
NOTE: shouldComponentUpdate should generally not be overridden other than to force it false so
that other libraries can control the sub-dom. If you do want to implement it, then old props can
be obtained from (prim/props this), and old state via (gobj/get (. this -state) "fulcro$state").
; BODY forms. May be omitted IFF there is an options map, in order to generate a component that is used only for queries/normalization.
(dom/div #js {:onClick onSelect} x))
NOTE: The options map is "open". That is: you can add whatever extra stuff you want to in order
to co-locate data for component-related concerns. This is exactly what component-local css, the
dynamic router, and form-state do. The data that you add is available from comp/component-options
on the component class and instances (i.e. this
).
See the Developer's Guide at book.fulcrologic.com for more details.
Define a stateful component. This macro emits a React UI class with a query, optional ident (if :ident is specified in options), optional initial state, optional css, lifecycle methods, and a render method. It can also cause the class to implement additional protocols that you specify. Destructuring is supported in the argument list. The template (data-only) versions do not have any arguments in scope The lambda versions have arguments in scope that make sense for those lambdas, as listed below: ``` (defsc Component [this {:keys [db/id x] :as props} {:keys [onSelect] :as computed} extended-args] { ;; stateful component options ;; query template is literal. Use the lambda if you have ident-joins or unions. :query [:db/id :x] ; OR (fn [] [:db/id :x]) ; this in scope ;; ident template is table name and ID property name :ident [:table/by-id :id] ; OR (fn [] [:table/by-id id]) ; this and props in scope ;; initial-state template is magic..see dev guide. Lambda version is normal. :initial-state {:x :param/x} ; OR (fn [params] {:x (:x params)}) ; nothing is in scope ;; pre-merge, use a lamba to modify new merged data with component needs :pre-merge (fn [{:keys [...]}] (merge {:ui/default-value :start} tree)) ; React Lifecycle Methods (this in scope) :initLocalState (fn [this props] ...) ; CAN BE used to call things as you might in a constructor. Return value is initial state. :shouldComponentUpdate (fn [this next-props next-state] ...) :componentDidUpdate (fn [this prev-props prev-state snapshot] ...) ; snapshot is optional, and is 16+. Is context for 15 :componentDidMount (fn [this] ...) :componentWillUnmount (fn [this] ...) ;; DEPRECATED IN REACT 16 (to be removed in 17): :componentWillReceiveProps (fn [this next-props] ...) :componentWillUpdate (fn [this next-props next-state] ...) :componentWillMount (fn [this] ...) ;; Replacements for deprecated methods in React 16.3+ :UNSAFE_componentWillReceiveProps (fn [this next-props] ...) :UNSAFE_componentWillUpdate (fn [this next-props next-state] ...) :UNSAFE_componentWillMount (fn [this] ...) ;; ADDED for React 16: :componentDidCatch (fn [this error info] ...) :getSnapshotBeforeUpdate (fn [this prevProps prevState] ...) ;; static :getDerivedStateFromProps (fn [props state] ...) ;; ADDED for React 16.6: :getDerivedStateFromError (fn [error] ...) **NOTE**: OVERWRITES entire state. This differs slightly from React. NOTE: shouldComponentUpdate should generally not be overridden other than to force it false so that other libraries can control the sub-dom. If you do want to implement it, then old props can be obtained from (prim/props this), and old state via (gobj/get (. this -state) "fulcro$state"). ; BODY forms. May be omitted IFF there is an options map, in order to generate a component that is used only for queries/normalization. (dom/div #js {:onClick onSelect} x)) ``` NOTE: The options map is "open". That is: you can add whatever extra stuff you want to in order to co-locate data for component-related concerns. This is exactly what component-local css, the dynamic router, and form-state do. The data that you add is available from `comp/component-options` on the component class and instances (i.e. `this`). See the Developer's Guide at book.fulcrologic.com for more details.
(denormalize-query state-map ID)
Takes a state map that may contain normalized queries and a query ID. Returns the stored query or nil.
Takes a state map that may contain normalized queries and a query ID. Returns the stored query or nil.
(factory class)
(factory class {:keys [keyfn qualifier] :as opts})
Create a factory constructor from a component class created with defui.
Create a factory constructor from a component class created with defui.
(fragment & args)
Wraps children in a React.Fragment. Props are optional, like normal DOM elements.
Wraps children in a React.Fragment. Props are optional, like normal DOM elements.
(get-computed x)
(get-computed x k-or-ks)
Return the computed properties on a component or its props.
Return the computed properties on a component or its props.
(get-extra-props this)
Get any data (as a map) that extensions have associated with the given Fulcro component.
Get any data (as a map) that extensions have associated with the given Fulcro component.
(get-ident x)
(get-ident class props)
Get the ident for a mounted component OR using a component class.
That arity-2 will return the ident using the supplied props map.
The single-arity version should only be used with a mounted component (e.g. this
from render
), and will derive the
props that were sent to it most recently.
Get the ident for a mounted component OR using a component class. That arity-2 will return the ident using the supplied props map. The single-arity version should only be used with a mounted component (e.g. `this` from `render`), and will derive the props that were sent to it most recently.
(get-indexes x)
Get the component indexes from a component instance or app. See also ident->any
, class->any
, etc.
Get the component indexes from a component instance or app. See also `ident->any`, `class->any`, etc.
(get-initial-state class)
(get-initial-state class params)
Get the initial state of a component. Needed because calling the protocol method from a defui component in clj will not work as expected.
Get the initial state of a component. Needed because calling the protocol method from a defui component in clj will not work as expected.
(get-query class-or-factory)
(get-query class-or-factory state-map)
Get the query for the given class or factory. If called without a state map, then you'll get the declared static query of the class. If a state map is supplied, then the dynamically set queries in that state will result in the current dynamically-set query according to that state.
Get the query for the given class or factory. If called without a state map, then you'll get the declared static query of the class. If a state map is supplied, then the dynamically set queries in that state will result in the current dynamically-set query according to that state.
(get-raw-react-prop c k)
GET a RAW react prop
GET a RAW react prop
(get-state component)
(get-state component k-or-ks)
Get a component's local state. May provide a single key or a sequential collection of keys for indexed access into the component's local state.
Get a component's local state. May provide a single key or a sequential collection of keys for indexed access into the component's local state.
(ident->any x ident)
Return a components that uses the given ident. x
is anything any->app accepts.
Return a components that uses the given ident. `x` is anything any->app accepts.
(ident->components x ident)
Return all components for a given ident. x
is anything any->app accepts.
Return all components for a given ident. `x` is anything any->app accepts.
(link-query query)
Find all of the elements (only at the top level) of the given query and replace them with their query ID
Find all of the elements (only at the top level) of the given query and replace them with their query ID
(make-state-map initial-state children-by-query-key params)
Build a component's initial state using the defsc initial-state-data from options, the children from options, and the params from the invocation of get-initial-state.
Build a component's initial state using the defsc initial-state-data from options, the children from options, and the params from the invocation of get-initial-state.
(newer-props props-a props-b)
Returns whichever of the given Fulcro props were most recently generated according to denormalization-time
.
Returns whichever of the given Fulcro props were most recently generated according to `denormalization-time`.
(normalize-query state-map query)
Given a state map and a query, returns a state map with the query normalized into the database. Query fragments that already appear in the state will not be added.
Given a state map and a query, returns a state map with the query normalized into the database. Query fragments that already appear in the state will not be added.
(normalize-query-elements state-map query)
Determines if there are query elements in the present query that need to be normalized as well. If so, it does so. Returns the new state map.
Determines if there are query elements in the present query that need to be normalized as well. If so, it does so. Returns the new state map.
(prop->classes x prop)
Get all component classes that query for the given prop.
x
can be anything any->app
is ok with.
Returns all classes that query for that prop (or ident)
Get all component classes that query for the given prop. `x` can be anything `any->app` is ok with. Returns all classes that query for that prop (or ident)
(props component)
Return a components props.
Return a components props.
(ptransact! component-or-app tx)
(ptransact! component-or-app ref tx)
DEPRECATED: Generally use result-action
in mutations to chain sequences instead.
Like transact!
, but ensures each call completes (in a full-stack, pessimistic manner) before the next call starts
in any way. Note that two calls of this function have no guaranteed relationship to each other. They could end up
intermingled at runtime. The only guarantee is that for a single call to ptransact!
, the calls in the given tx will run
pessimistically (one at a time) in the order given. Follow-on reads in the given transaction will be repeated after each remote
interaction.
component-or-app
a mounted component or the app
tx
the tx to run
ref
the ident (ref context) in which to run the transaction (including all deferrals)
DEPRECATED: Generally use `result-action` in mutations to chain sequences instead. Like `transact!`, but ensures each call completes (in a full-stack, pessimistic manner) before the next call starts in any way. Note that two calls of this function have no guaranteed relationship to each other. They could end up intermingled at runtime. The only guarantee is that for *a single call* to `ptransact!`, the calls in the given tx will run pessimistically (one at a time) in the order given. Follow-on reads in the given transaction will be repeated after each remote interaction. `component-or-app` a mounted component or the app `tx` the tx to run `ref` the ident (ref context) in which to run the transaction (including all deferrals)
(query-id class qualifier)
Returns a string ID for the query of the given class with qualifier
Returns a string ID for the query of the given class with qualifier
(raw->newest-props raw-props raw-state)
Using raw react props/state returns the newest Fulcro props.
Using raw react props/state returns the newest Fulcro props.
(react-type x)
Returns the component type, regardless of whether the component has been mounted
Returns the component type, regardless of whether the component has been mounted
(register-component! k component-class)
Add a component to Fulcro's component registry. This is used by defsc to ensure that all Fulcro classes that have been compiled (transitively required) will be accessible for lookup by fully-qualified symbol/keyword. Not meant for public use, unless you're creating your own component macro that doesn't directly leverage defsc.
Add a component to Fulcro's component registry. This is used by defsc to ensure that all Fulcro classes that have been compiled (transitively required) will be accessible for lookup by fully-qualified symbol/keyword. Not meant for public use, unless you're creating your own component macro that doesn't directly leverage defsc.
(registry-key->class classname)
Look up the given component in Fulcro's global component registry. Will only be able to find components that have been (transitively) required by your application.
classname
can be a fully-qualified keyword or symbol.
Look up the given component in Fulcro's global component registry. Will only be able to find components that have been (transitively) required by your application. `classname` can be a fully-qualified keyword or symbol.
(set-query! x class-or-factory {:keys [query params] :as opts})
Set a dynamic query. Alters the query, and then rebuilds internal indexes.
x
is anything that any->app accepts.
Set a dynamic query. Alters the query, and then rebuilds internal indexes. `x` is anything that any->app accepts.
(set-query* state-map class-or-factory {:keys [query] :as args})
Put a query in app state. NOTE: Indexes must be rebuilt after setting a query, so this function should primarily be used to build up an initial app state.
Put a query in app state. NOTE: Indexes must be rebuilt after setting a query, so this function should primarily be used to build up an initial app state.
(shared component)
(shared component k-or-ks)
Return the global shared properties of the root. See :shared and :shared-fn reconciler options.
Return the global shared properties of the root. See :shared and :shared-fn reconciler options.
(transact! app-or-comp tx)
(transact! app-or-component tx options)
Submit a transaction for processing.
The underlying transaction system is pluggable, but the default supported options are:
:optimistic?
- boolean. Should the transaction be processed optimistically?:ref
- ident. The ident of the component used to submit this transaction. This is set automatically if you use a component to call this function.:component
- React element. Set automatically if you call this function using a component.:refresh
- Vector containing idents (of components) and keywords (of props). Things that have changed and should be re-rendered
on screen. Only necessary when the underlying rendering algorithm won't auto-detect, such as when UI is derived from the
state of other components or outside of the directly queried props. Interpretation depends on the renderer selected:
The ident-optimized render treats these as "extras".:only-refresh
- Vector of idents/keywords. If the underlying rendering configured algorithm supports it: The
components using these are the only things that will be refreshed in the UI.
This can be used to avoid the overhead of looking for stale data when you know exactly what
you want to refresh on screen as an extra optimization. Idents are not checked against queries.:abort-id
- An ID (you make up) that makes it possible (if the plugins you're using support it) to cancel
the network portion of the transaction (assuming it has not already completed).:compressible?
- boolean. Check compressible-transact! docs.NOTE: This function calls the application's tx!
function (which is configurable). Fulcro 2 'follow-on reads' are
supported by the default version and are added to the :refresh
entries. Your choice of rendering algorithm will
influence their necessity.
Returns the transaction ID of the submitted transaction.
Submit a transaction for processing. The underlying transaction system is pluggable, but the default supported options are: - `:optimistic?` - boolean. Should the transaction be processed optimistically? - `:ref` - ident. The ident of the component used to submit this transaction. This is set automatically if you use a component to call this function. - `:component` - React element. Set automatically if you call this function using a component. - `:refresh` - Vector containing idents (of components) and keywords (of props). Things that have changed and should be re-rendered on screen. Only necessary when the underlying rendering algorithm won't auto-detect, such as when UI is derived from the state of other components or outside of the directly queried props. Interpretation depends on the renderer selected: The ident-optimized render treats these as "extras". - `:only-refresh` - Vector of idents/keywords. If the underlying rendering configured algorithm supports it: The components using these are the *only* things that will be refreshed in the UI. This can be used to avoid the overhead of looking for stale data when you know exactly what you want to refresh on screen as an extra optimization. Idents are *not* checked against queries. - `:abort-id` - An ID (you make up) that makes it possible (if the plugins you're using support it) to cancel the network portion of the transaction (assuming it has not already completed). - `:compressible?` - boolean. Check compressible-transact! docs. NOTE: This function calls the application's `tx!` function (which is configurable). Fulcro 2 'follow-on reads' are supported by the default version and are added to the `:refresh` entries. Your choice of rendering algorithm will influence their necessity. Returns the transaction ID of the submitted transaction.
(update-state! component f)
(update-state! component f & args)
Update a component's local state. Similar to Clojure(Script)'s swap!
This function affects a managed cljs map maintained in React state. If you want to affect the low-level
js state itself use React's own .setState
on the component.
Update a component's local state. Similar to Clojure(Script)'s swap! This function affects a managed cljs map maintained in React state. If you want to affect the low-level js state itself use React's own `.setState` on the component.
(with-parent-context outer-parent & body)
Wraps the given body with the correct internal bindings of the parent so that Fulcro internals will work when that body is embedded in unusual ways (e.g. as the body in a child-as-a-function React pattern).
Wraps the given body with the correct internal bindings of the parent so that Fulcro internals will work when that body is embedded in unusual ways (e.g. as the body in a child-as-a-function React pattern).
(wrap-update-extra-props f)
(wrap-update-extra-props handler f)
Wrap the props middleware such that f
is called to get extra props that should be placed
in the extra-props arg of the component.
handler
- (optional) The next item in the props middleware chain.
f
- A (fn [cls extra-props] new-extra-props)
f
will be passed the class being rendered and the current map of extra props. It should augment
those and return a new version.
Wrap the props middleware such that `f` is called to get extra props that should be placed in the extra-props arg of the component. `handler` - (optional) The next item in the props middleware chain. `f` - A (fn [cls extra-props] new-extra-props) `f` will be passed the class being rendered and the current map of extra props. It should augment those and return a new version.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close