(add-basis-time props time)
(add-basis-time q props time)
Recursively add the given basis time to all of the maps in the props. This is part of the UI refresh optimization algorithm. Children that refresh in isolation could be mis-drawn if a parent subsequently does a re-render without a query (e.g. local state change). The basis times allow us to detect and avoid that.
Recursively add the given basis time to all of the maps in the props. This is part of the UI refresh optimization algorithm. Children that refresh in isolation could be mis-drawn if a parent subsequently does a re-render without a query (e.g. local state change). The basis times allow us to detect and avoid that.
(add-root! reconciler root-class target)
(add-root! reconciler root-class target options)
Given a root component class and a target root DOM node, instantiate and render the root class using the reconciler's :state property. The reconciler will continue to observe changes to :state and keep the target node in sync. Note a reconciler may have only one root. If invoked on a reconciler with an existing root, the new root will replace the old one.
Given a root component class and a target root DOM node, instantiate and render the root class using the reconciler's :state property. The reconciler will continue to observe changes to :state and keep the target node in sync. Note a reconciler may have only one root. If invoked on a reconciler with an existing root, the new root will replace the old one.
(annotate-mutations tx ident)
Given a query expression annotate all mutations by adding a :mutator -> ident entry to the metadata of each mutation expression in the query.
Given a query expression annotate all mutations by adding a :mutator -> ident entry to the metadata of each mutation expression in the query.
(app-root reconciler)
Return the application's root component.
Return the application's root component.
(app-state reconciler)
Return the reconciler's application state atom. Useful when the reconciler was initialized via denormalized data.
Return the reconciler's application state atom. Useful when the reconciler was initialized via denormalized data.
(as-leaf data)
Returns data with meta-data marking it as a leaf in the result.
Returns data with meta-data marking it as a leaf in the result.
(build-css env
thissym
{css-method :method css-template :template}
{include-method :method include-template :template})
(build-prop->class-index! prop->classes query)
Build an index from property to class using the (annotated) query.
Build an index from property to class using the (annotated) query.
(children component)
Returns the component's children.
Returns the component's children.
(class->all x class)
Get any component from the indexer that matches the component class.
Get any component from the indexer that matches the component class.
(class->any x class)
Get any component from the indexer that matches the component class.
Get any component from the indexer that matches the component class.
(collect-statics dt)
Collect the static declarations from the defui.
Collect the static declarations from the defui.
(component->state-map component)
Get the normalized database state as a map. Requires a mounted component instance.
Get the normalized database state as a map. Requires a mounted component instance.
(component-class? x)
Returns true if the given x
is a defsc
or defui
component class definition.
Returns true if the given `x` is a `defsc` or `defui` component class definition.
(component-merge-query component object-data)
Calculates the query that can be used to pull (or merge) a component with an ident to/from a normalized app database. Requires a tree of data that represents the instance of the component in question (e.g. ident will work on it)
Calculates the query that can be used to pull (or merge) a component with an ident to/from a normalized app database. Requires a tree of data that represents the instance of the component in question (e.g. ident will work on it)
(component-name class)
Returns a string version of the given react component's name.
Returns a string version of the given react component's name.
(component? x)
Returns true if the argument is a component. A component is defined as a mounted React-based javascript 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 React-based javascript component*. This function returns false for component classes, and also returns false for the output of a Fulcro component factory.
(compressible-transact! comp-or-reconciler 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.
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. 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] instead of default [props & children]. This makes easier to send computed but will not accept children params.
Similar to factory, but returns a function with the signature [props computed] instead of default [props & children]. This makes easier to send computed but will not accept children params.
(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.
(db->tree query data refs)
(db->tree query data refs map-ident)
Given a query, some data in the default database format, and the entire application state in the default database format, return the tree where all ident links have been replaced with their original node values.
Given a query, some data in the default database format, and the entire application state in the default database format, return the tree where all ident links have been replaced with their original node values.
(dedup-components-by-path components)
Remove components from the given list by removing those whose paths are encompassed by others. In other words, remove components from the list when there is a parent of that component also in the list.
Remove components from the given list by removing those whose paths are encompassed by others. In other words, remove components from the list when there is a parent of that component also in the list.
(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} css-classmap]
{
;; 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)}) ; this in scope
;; pre-merge, use a lamba to modify new merged data with component needs
:pre-merge (fn [tree] (merge {:ui/default-value :start} tree))
:css [] ; garden css rules
:css-include [] ; list of components that have CSS to compose towards root.
; React Lifecycle Methods (this in scope)
:initLocalState (fn [] ...) ; CAN BE used to call things as you might in a constructor. Return value is initial state.
:shouldComponentUpdate (fn [next-props next-state] ...)
:componentDidUpdate (fn [prev-props prev-state snapshot] ...) ; snapshot is optional, and is 16+. Is context for 15
:componentDidMount (fn [] ...)
:componentWillUnmount (fn [] ...)
;; DEPRECATED IN REACT 16 (to be removed in 17):
:componentWillReceiveProps (fn [next-props] ...)
:componentWillUpdate (fn [next-props next-state] ...)
:componentWillMount (fn [] ...)
;; Replacements for deprecated methods in React 16.3+
:UNSAFE_componentWillReceiveProps (fn [next-props] ...)
:UNSAFE_componentWillUpdate (fn [next-props next-state] ...)
:UNSAFE_componentWillMount (fn [] ...)
;; ADDED for React 16:
:componentDidCatch (fn [error info] ...)
:getSnapshotBeforeUpdate (fn [prevProps prevState] ...)
: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").
; Custom literal protocols (Object ok, too, to add arbitrary methods. Nothing automatically in scope.)
:protocols [YourProtocol
(method [this] ...)]} ; nothing is automatically in scope
; 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))
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} css-classmap] { ;; 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)}) ; this in scope ;; pre-merge, use a lamba to modify new merged data with component needs :pre-merge (fn [tree] (merge {:ui/default-value :start} tree)) :css [] ; garden css rules :css-include [] ; list of components that have CSS to compose towards root. ; React Lifecycle Methods (this in scope) :initLocalState (fn [] ...) ; CAN BE used to call things as you might in a constructor. Return value is initial state. :shouldComponentUpdate (fn [next-props next-state] ...) :componentDidUpdate (fn [prev-props prev-state snapshot] ...) ; snapshot is optional, and is 16+. Is context for 15 :componentDidMount (fn [] ...) :componentWillUnmount (fn [] ...) ;; DEPRECATED IN REACT 16 (to be removed in 17): :componentWillReceiveProps (fn [next-props] ...) :componentWillUpdate (fn [next-props next-state] ...) :componentWillMount (fn [] ...) ;; Replacements for deprecated methods in React 16.3+ :UNSAFE_componentWillReceiveProps (fn [next-props] ...) :UNSAFE_componentWillUpdate (fn [next-props next-state] ...) :UNSAFE_componentWillMount (fn [] ...) ;; ADDED for React 16: :componentDidCatch (fn [error info] ...) :getSnapshotBeforeUpdate (fn [prevProps prevState] ...) :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"). ; Custom literal protocols (Object ok, too, to add arbitrary methods. Nothing automatically in scope.) :protocols [YourProtocol (method [this] ...)]} ; nothing is automatically in scope ; 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)) ``` 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.
(depth component)
PRIVATE: Returns the render depth (a integer) of the component relative to the mount root.
PRIVATE: Returns the render depth (a integer) of the component relative to the mount root.
(dispatch _ key _)
Helper function for implementing :read and :mutate as multimethods. Use this as the dispatch-fn.
Helper function for implementing :read and :mutate as multimethods. Use this as the dispatch-fn.
(factory class)
(factory class
{:keys [validator keyfn instrument? qualifier]
:or {instrument? true}
:as opts})
Create a factory constructor from a component class created with fulcro.client.primitives/defui.
Create a factory constructor from a component class created with fulcro.client.primitives/defui.
Create a factory constructor from a component class created with defui.
Create a factory constructor from a component class created with defui.
(focus-query query path)
Given a query, focus it along the specified path.
Examples: (focus-query [:foo :bar :baz] [:foo]) => [:foo]
(fulcro.client.primitives/focus-query [{:foo [:bar :baz]} :woz] [:foo :bar]) => [{:foo [:bar]}]
Given a query, focus it along the specified path. Examples: (focus-query [:foo :bar :baz] [:foo]) => [:foo] (fulcro.client.primitives/focus-query [{:foo [:bar :baz]} :woz] [:foo :bar]) => [{:foo [:bar]}]
(focus-subquery query sub-query)
Given a query, focus it along the specified query expression.
Examples: (focus-query [:foo :bar :baz] [:foo]) => [:foo]
(fulcro.client.primitives/focus-query [{:foo [:bar :baz]} :woz] [{:foo [:bar]} :woz]) => [{:foo [:bar]} :woz]
Given a query, focus it along the specified query expression. Examples: (focus-query [:foo :bar :baz] [:foo]) => [:foo] (fulcro.client.primitives/focus-query [{:foo [:bar :baz]} :woz] [{:foo [:bar]} :woz]) => [{:foo [:bar]} :woz]
(force-root-render! reconciler)
Force a re-render of the root. Runs a root query, disables shouldComponentUpdate, and renders the root component. This effectively forces React to do a full VDOM diff. Useful for things like changing locales where there are no real data changes, but the UI still needs to refresh. recomputing :shared.
Force a re-render of the root. Runs a root query, disables shouldComponentUpdate, and renders the root component. This effectively forces React to do a full VDOM diff. Useful for things like changing locales where there are no real data changes, but the UI still needs to refresh. recomputing :shared.
(force-update c)
(force-update c cb)
An exception-protected React .forceUpdate
An exception-protected React .forceUpdate
(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.
(fulcro-ui->props {:keys [parser state] :as env} c)
Finds props for a given component. Returns ::no-ident if the component has no ident (which prevents localized update). This eliminates the need for path data.
Finds props for a given component. Returns ::no-ident if the component has no ident (which prevents localized update). This eliminates the need for path data.
(gather-keys query)
Gather the keys that would be considered part of the refresh set for the given query.
E.g. [:a {:j [:b]} {:u {:x [:l] :y [:k]}}] ==> #{:a :j :u}
Gather the keys that would be considered part of the refresh set for the given query. E.g. [:a {:j [:b]} {:u {:x [:l] :y [:k]}}] ==> #{:a :j :u}
(gather-sends {:keys [parser] :as env} q remotes tx-time)
Given an environment, a query and a set of remotes return a hash map of remotes mapped to the query specific to that remote.
Given an environment, a query and a set of remotes return a hash map of remotes mapped to the query specific to that remote.
(get-basis-time props)
Returns the basis time from the given props, or ::unset if not available.
Returns the basis time from the given props, or ::unset if not available.
(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-current-time reconciler)
get the current basis time from the reconciler. Used instead of calling the protocol method basis-t
to facilitate testing.
get the current basis time from the reconciler. Used instead of calling the protocol method `basis-t` to facilitate testing.
(get-history reconciler)
pass-through function for getting history, that enables testing (cannot mock protocols easily)
pass-through function for getting history, that enables testing (cannot mock protocols easily)
(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-indexer reconciler)
PRIVATE: Get the indexer associated with the reconciler.
PRIVATE: Get the indexer associated with the reconciler.
(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-rendered-state component)
(get-rendered-state component k-or-ks)
Get the rendered state of component. fulcro.client.primitives/get-state always returns the up-to-date state.
Get the rendered state of component. fulcro.client.primitives/get-state always returns the up-to-date state.
(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 this props)
Return the ident for this component
Return the ident for this component
(initial-state clz params)
Get the initial state to be used for this component in app state. You are responsible for composing these together.
Get the initial state to be used for this component in app state. You are responsible for composing these together.
(integrate-ident state ident & named-parameters)
DEPRECATED: Use fulcro.client.mutations/integrate-ident* in your mutations instead.
DEPRECATED: Use fulcro.client.mutations/integrate-ident* in your mutations instead.
(integrate-ident! state ident & named-parameters)
DEPRECATED: Use fulcro.client.mutations/integrate-ident* in your mutations instead.
DEPRECATED: Use fulcro.client.mutations/integrate-ident* in your mutations instead.
(pre-merge* this data)
Modify data before merging.
Modify data before merging.
(query this)
Return the component's unbound static query
Return the component's unbound static query
(leaf? data)
Returns true iff the given data is marked as a leaf in the result (according to the query). Requires pre-marking.
Returns true iff the given data is marked as a leaf in the result (according to the query). Requires pre-marking.
(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.
(mark-missing result query)
Recursively walk the query and response marking anything that was asked for in the query but is not in the response as missing. The merge process (which happens later in the plumbing) looks for these markers as indicators to remove any existing data in the database (which has provably disappeared).
The naive approach to data merging (even recursive) would fail to remove such data.
Returns the result with missing markers in place (which are then used/removed in a later stage).
Recursively walk the query and response marking anything that was *asked for* in the query but is *not* in the response as missing. The merge process (which happens later in the plumbing) looks for these markers as indicators to remove any existing data in the database (which has provably disappeared). The naive approach to data merging (even recursive) would fail to remove such data. Returns the result with missing markers in place (which are then used/removed in a later stage).
(merge! reconciler data-tree)
(merge! reconciler data-tree query)
(merge! reconciler data-tree query remote)
Merge an arbitrary data-tree that conforms to the shape of the given query.
query - A query, derived from defui components, that can be used to normalized a tree of data. data-tree - A tree of data that matches the nested shape of query remote - No longer used. May be passed, but is ignored.
Merge an arbitrary data-tree that conforms to the shape of the given query. query - A query, derived from defui components, that can be used to normalized a tree of data. data-tree - A tree of data that matches the nested shape of query remote - No longer used. May be passed, but is ignored.
(merge* reconciler state res query)
Internal implementation of merge. Given a reconciler, state (map), result, and query returns a map of the:
:keys
to refresh
:next
state
and ::tempids
that need to be migrated
Internal implementation of merge. Given a reconciler, state (map), result, and query returns a map of the: `:keys` to refresh `:next` state and `::tempids` that need to be migrated
(merge-alternate-union-elements state-map root-component)
Just like merge-alternate-union-elements!, but usable from within mutations and on server-side rendering. Ensures that when a component has initial state it will end up in the state map, even if it isn't currently in the initial state of the union component (which can only point to one at a time).
Just like merge-alternate-union-elements!, but usable from within mutations and on server-side rendering. Ensures that when a component has initial state it will end up in the state map, even if it isn't currently in the initial state of the union component (which can only point to one at a time).
(merge-alternate-union-elements! app root-component)
Walks the query and initial state of root-component and merges the alternate sides of unions with initial state into
the application state database. See also merge-alternate-union-elements
, which can be used on a state map and
is handy for server-side rendering. This function side-effects on your app, and returns nothing.
Walks the query and initial state of root-component and merges the alternate sides of unions with initial state into the application state database. See also `merge-alternate-union-elements`, which can be used on a state map and is handy for server-side rendering. This function side-effects on your app, and returns nothing.
(merge-alternate-unions merge-fn root-component)
Walks the given query and calls (merge-fn parent-union-component union-child-initial-state) for each non-default element of a union that has initial app state. You probably want to use merge-alternate-union-elements[!] on a state map or app.
Walks the given query and calls (merge-fn parent-union-component union-child-initial-state) for each non-default element of a union that has initial app state. You probably want to use merge-alternate-union-elements[!] on a state map or app.
(merge-component state-map component component-data & named-parameters)
Given a state map of the application database, a component, and a tree of component-data: normalizes
the tree of data and merges the component table entries into the state, returning a new state map.
Since there is not an implied root, the component itself won't be linked into your graph (though it will
remain correctly linked for its own consistency).
Therefore, this function is just for dropping normalized things into tables
when they themselves have a recursive nature. This function is useful when you want to create a new component instance
and put it in the database, but the component instance has recursive normalized state. This is a basically a
thin wrapper around prim/tree->db
.
See also integrate-ident, integrate-ident!, and merge-component!
Given a state map of the application database, a component, and a tree of component-data: normalizes the tree of data and merges the component table entries into the state, returning a new state map. Since there is not an implied root, the component itself won't be linked into your graph (though it will remain correctly linked for its own consistency). Therefore, this function is just for dropping normalized things into tables when they themselves have a recursive nature. This function is useful when you want to create a new component instance and put it in the database, but the component instance has recursive normalized state. This is a basically a thin wrapper around `prim/tree->db`. See also integrate-ident, integrate-ident!, and merge-component!
(merge-component! reconciler component object-data & named-parameters)
Normalize and merge a (sub)tree of application state into the application using a known UI component's query and ident.
This utility function obtains the ident of the incoming object-data using the UI component's ident function. Once obtained, it uses the component's query and ident to normalize the data and place the resulting objects in the correct tables. It is also quite common to want those new objects to be linked into lists in other spot in app state, so this function supports optional named parameters for doing this. These named parameters can be repeated as many times as you like in order to place the ident of the new object into other data structures of app state.
This function honors the data merge story for Fulcro: attributes that are queried for but do not appear in the data will be removed from the application. This function also uses the initial state for the component as a base for merge if there was no state for the object already in the database.
This function will also trigger re-renders of components that directly render object merged, as well as any components into which you integrate that data via the named-parameters.
This function is primarily meant to be used from things like server push and setTimeout/setInterval, where you're outside of the normal mutation story. Do not use this function within abstract mutations.
Any keywords that appear in ident integration steps will be added to the re-render queue.
See also fulcro.client.primitives/merge!
.
Normalize and merge a (sub)tree of application state into the application using a known UI component's query and ident. This utility function obtains the ident of the incoming object-data using the UI component's ident function. Once obtained, it uses the component's query and ident to normalize the data and place the resulting objects in the correct tables. It is also quite common to want those new objects to be linked into lists in other spot in app state, so this function supports optional named parameters for doing this. These named parameters can be repeated as many times as you like in order to place the ident of the new object into other data structures of app state. This function honors the data merge story for Fulcro: attributes that are queried for but do not appear in the data will be removed from the application. This function also uses the initial state for the component as a base for merge if there was no state for the object already in the database. This function will also trigger re-renders of components that directly render object merged, as well as any components into which you integrate that data via the named-parameters. This function is primarily meant to be used from things like server push and setTimeout/setInterval, where you're outside of the normal mutation story. Do not use this function within abstract mutations. - reconciler: A reconciler - component: The class of the component that corresponsds to the data. Must have an ident. - object-data: A map (tree) of data to merge. Will be normalized for you. - named-parameter: Post-processing ident integration steps. see integrate-ident! Any keywords that appear in ident integration steps will be added to the re-render queue. See also `fulcro.client.primitives/merge!`.
(merge-handler mutation-merge target source)
Handle merging incoming data, but be sure to sweep it of values that are marked missing. Also triggers the given mutation-merge if available.
Handle merging incoming data, but be sure to sweep it of values that are marked missing. Also triggers the given mutation-merge if available.
(merge-mutation-joins state query data-tree)
Merge all of the mutations that were joined with a query
Merge all of the mutations that were joined with a query
(mounted? x)
Returns true if the component is mounted.
Returns true if the component is mounted.
(nilify-not-found x)
Given x, return x value unless it's ::prim/not-found, in which case it returns nil.
This is useful when you wanna do a nil check but you are in a position where the value could be ::prim/not-found (and you want to consider it as nil). A common pattern looks like: `(or (prim/nilify-not-found x) 10)
Given x, return x value unless it's ::prim/not-found, in which case it returns nil. This is useful when you wanna do a nil check but you are in a position where the value could be ::prim/not-found (and you want to consider it as nil). A common pattern looks like: `(or (prim/nilify-not-found x) 10)
(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.
(parser {:keys [read mutate] :as opts})
Create a parser. The argument is a map of two keys, :read and :mutate. Both functions should have the signature (Env -> Key -> Params -> ParseResult).
The mutation functions return a map keyed by:
:action
- The lambda to run to do the local optimistic version of that mutation
any-keyword-matching-a-remote - A boolean true or AST expression of the thing to run on the named remote.
:refresh - A vector of namespaced keywords of data that was/will be changed by this mutation
When the parser runs on mutations it collects the :refresh
list into the metadata of the results
under the :fulcro.client.primitives/refresh key.
Create a parser. The argument is a map of two keys, :read and :mutate. Both functions should have the signature (Env -> Key -> Params -> ParseResult). The mutation functions return a map keyed by: `:action` - The lambda to run to do the local optimistic version of that mutation any-keyword-matching-a-remote - A boolean true or AST expression of the thing to run on the named remote. :refresh - A vector of namespaced keywords of data that was/will be changed by this mutation When the parser runs on mutations it collects the `:refresh` list into the metadata of the results under the :fulcro.client.primitives/refresh key.
(pessimistic-transaction->transaction tx)
(pessimistic-transaction->transaction
tx
{:keys [valid-remotes env state-map]
:or {valid-remotes #{:remote} env {} state-map {}}
:as options})
Converts a sequence of calls as if each call should run in sequence (deferring even the optimistic side until
the prior calls have completed in a full-stack manner), and returns a tx that can be submitted via the normal
transact!
.
The options map can contain:
valid-remotes
is a set of remote names in your application. Defaults to #{:remote}
env
is a map that is merged into the deferred transaction's env
WARNING: If a mutation tries to interact with more than one simultaneous remote, the current implementation will wait until the first one of them completes (selected in a non-deterministic fashion), not all.
Converts a sequence of calls as if each call should run in sequence (deferring even the optimistic side until the prior calls have completed in a full-stack manner), and returns a tx that can be submitted via the normal `transact!`. The options map can contain: `valid-remotes` is a set of remote names in your application. Defaults to `#{:remote}` `env` is a map that is merged into the deferred transaction's `env` WARNING: If a mutation tries to interact with more than one simultaneous remote, the current implementation will wait until the *first* one of them completes (selected in a non-deterministic fashion), not all.
(pre-merge-transform state)
Transform function that modifies data using component pre-merge hook.
Transform function that modifies data using component pre-merge hook.
(props component)
Return a components props.
Return a components props.
(ptransact! comp-or-reconciler tx)
(ptransact! comp-or-reconciler ref tx)
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.
comp-or-reconciler
a mounted component or reconciler
tx
the tx to run
ref
the ident (ref context) in which to run the transaction (including all deferrals)
NOTE: ptransact!
is safe to use from within mutations (e.g. for retry behavior).
WARNINGS: Mutations that interact with more than one remote at the same time will only wait for one of the remotes to finish.
Also, mutations that just issue loads should not be used. This function defers pessimistic writes, not reads.
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. `comp-or-reconciler` a mounted component or reconciler `tx` the tx to run `ref` the ident (ref context) in which to run the transaction (including all deferrals) NOTE: `ptransact!` *is* safe to use from within mutations (e.g. for retry behavior). WARNINGS: Mutations that interact with more than one remote *at the same time* will only wait for one of the remotes to finish. Also, mutations that just issue loads should *not* be used. This function defers pessimistic *writes*, not reads.
(query->ast query-expr)
Given a query expression convert it into an AST.
Given a query expression convert it into an AST.
(query->ast1 query-expr)
Call query->ast and return the first children.
Call query->ast and return the first children.
(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
(react-key component)
Returns the components React key.
Returns the components React key.
(react-ref component name)
Returns the component associated with a component's React ref.
Returns the component associated with a component's React ref.
(react-set-state! component new-state)
(react-set-state! component new-state cb)
DEPRECATED: Use set-state! which is a React-level primitive now.
DEPRECATED: Use set-state! which *is* a React-level primitive now.
(react-type component)
(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
(reader in)
(reader in opts)
(reader)
(reader opts)
Create a transit reader. This reader can handler the tempid type. Can pass transit reader customization opts map.
Create a transit reader. This reader can handler the tempid type. Can pass transit reader customization opts map.
(reconciler {:keys [id state shared shared-fn hydrate? parser normalize send
merge-sends remotes merge-tree merge-ident lifecycle
root-render root-unmount root-hydrate migrate render-mode
instrument tx-listen history]
:or {root-render (fn clj-root-render [c target] c)
root-hydrate (fn clj-root-hydrate [c target] c)
merge-sends (fn* [p1__12299# p2__12300#]
(merge-with into p1__12299# p2__12300#))
remotes [:remote]
render-mode :normal
history 200
lifecycle nil
root-unmount (fn clj-unmount [x])
hydrate? false}
:as config})
(reconciler
{:keys [id state shared shared-fn hydrate? parser normalize send merge-sends
remotes merge-tree merge-ident lifecycle root-render root-unmount
root-hydrate migrate render-mode instrument tx-listen history]
:or {root-render (fn* [p1__103208# p2__103209#]
(js/ReactDOM.render p1__103208# p2__103209#))
root-hydrate (fn* [p1__103210# p2__103211#]
(js/ReactDOM.hydrate p1__103210# p2__103211#))
merge-sends (fn* [p1__103206# p2__103207#]
(merge-with into p1__103206# p2__103207#))
remotes [:remote]
render-mode :normal
history 200
lifecycle nil
root-unmount (fn* [p1__103212#]
(js/ReactDOM.unmountComponentAtNode p1__103212#))
hydrate? false}
:as config})
Construct a reconciler from a configuration map.
Required parameters: :state - the application state. If IAtom value is not supplied the data will be normalized into the default database format using the root query. This can be disabled by explicitly setting the optional :normalize parameter to false. :parser - the parser to be used
Optional parameters:
:id - a unique ID that this reconciler will be known as. Used to resolve global variable usage when more than one app is on a page. If
left unspecified it will default to a random UUID.
:shared - a map of global shared properties for the component tree.
:shared-fn - a function to compute global shared properties from the root props.
the result is merged with :shared.
:send - required only if the parser will return a non-empty value when
run against the supplied :remotes. send is a function of two
arguments, the map of remote expressions keyed by remote target
and a callback which should be invoked with the result from each
remote target. Note this means the callback can be invoked
multiple times to support parallel fetching and incremental
loading if desired. The callback should take the response as the
first argument and the the query that was sent as the second
argument.
:history - A positive integer. The number of history steps to keep in memory.
:normalize - whether the state should be normalized. If true it is assumed
all novelty introduced into the system will also need
normalization.
:remotes - a vector of keywords representing remote services which can
evaluate query expressions. Defaults to [:remote]
:hydrate? - Bolean. When true, it indicates the the first render should assume the server pre-rendered a DOM,
which will cause a call to hydrate instead of render (React 16+).
:root-render - the root render function. Defaults to ReactDOM.render
:root-hydrate - the root hydrate function. Defaults to ReactDOM.hydrate. Only used on initial render, and only if :hydrate?
is true.
:root-unmount - the root unmount function. Defaults to
ReactDOM.unmountComponentAtNode
:render-mode - :normal - fastest, and the default. Components with idents can refresh in isolation.
shouldComponentUpdate returns false if state/data are unchanged. Follow-on reads are
required to refresh non-local concerns.
:keyframe - Every data change runs a root-level query and re-renders from root.
shouldComponentUpdate is the same as :default. Follow-on reads are not needed for
non-local UI refresh.
:brutal - Every data change runs a root-level query, and re-renders from root. shouldComponentUpdate
always returns true, forcing full React diff. Not really useful for anything but benchmarking.
:lifecycle - A function (fn [component event]) that is called when react components either :mount or :unmount. Useful for debugging tools.
:tx-listen - a function of 2 arguments that will listen to transactions.
The first argument is the parser's env map also containing
the old and new state. The second argument is a history-step (see history). It also contains
a couple of legacy fields for bw compatibility with 1.0.
Construct a reconciler from a configuration map. Required parameters: :state - the application state. If IAtom value is not supplied the data will be normalized into the default database format using the root query. This can be disabled by explicitly setting the optional :normalize parameter to false. :parser - the parser to be used Optional parameters: :id - a unique ID that this reconciler will be known as. Used to resolve global variable usage when more than one app is on a page. If left unspecified it will default to a random UUID. :shared - a map of global shared properties for the component tree. :shared-fn - a function to compute global shared properties from the root props. the result is merged with :shared. :send - required only if the parser will return a non-empty value when run against the supplied :remotes. send is a function of two arguments, the map of remote expressions keyed by remote target and a callback which should be invoked with the result from each remote target. Note this means the callback can be invoked multiple times to support parallel fetching and incremental loading if desired. The callback should take the response as the first argument and the the query that was sent as the second argument. :history - A positive integer. The number of history steps to keep in memory. :normalize - whether the state should be normalized. If true it is assumed all novelty introduced into the system will also need normalization. :remotes - a vector of keywords representing remote services which can evaluate query expressions. Defaults to [:remote] :hydrate? - Bolean. When true, it indicates the the first render should assume the server pre-rendered a DOM, which will cause a call to hydrate instead of render (React 16+). :root-render - the root render function. Defaults to ReactDOM.render :root-hydrate - the root hydrate function. Defaults to ReactDOM.hydrate. Only used on initial render, and only if `:hydrate?` is true. :root-unmount - the root unmount function. Defaults to ReactDOM.unmountComponentAtNode :render-mode - :normal - fastest, and the default. Components with idents can refresh in isolation. shouldComponentUpdate returns false if state/data are unchanged. Follow-on reads are required to refresh non-local concerns. :keyframe - Every data change runs a root-level query and re-renders from root. shouldComponentUpdate is the same as :default. Follow-on reads are *not* needed for non-local UI refresh. :brutal - Every data change runs a root-level query, and re-renders from root. shouldComponentUpdate always returns true, forcing full React diff. Not really useful for anything but benchmarking. :lifecycle - A function (fn [component event]) that is called when react components either :mount or :unmount. Useful for debugging tools. :tx-listen - a function of 2 arguments that will listen to transactions. The first argument is the parser's env map also containing the old and new state. The second argument is a history-step (see history). It also contains a couple of legacy fields for bw compatibility with 1.0.
(reconciler? x)
Returns true if x is a reconciler.
Returns true if x is a reconciler.
(reduce-query-depth q k)
Changes a join on key k with depth limit from [:a {:k n}] to [:a {:k (dec n)}]
Changes a join on key k with depth limit from [:a {:k n}] to [:a {:k (dec n)}]
(ref->any x ref)
Get any component from the indexer that matches the ref.
Get any component from the indexer that matches the ref.
(ref->components x ref)
Return all components for a given ref.
Return all components for a given ref.
(remove-loads-and-fallbacks query)
Removes all fulcro/load and tx/fallback mutations from the query
Removes all fulcro/load and tx/fallback mutations from the query
(remove-root! reconciler target)
Remove a root target (a DOM element) from a reconciler. The reconciler will no longer attempt to reconcile application state with the specified root.
Remove a root target (a DOM element) from a reconciler. The reconciler will no longer attempt to reconcile application state with the specified root.
(resolve-tempids state tid->rid)
Replaces all tempids in app-state with the ids returned by the server.
Replaces all tempids in app-state with the ids returned by the server.
(rewrite-tempids-in-request-queue queue tempid-map)
Rewrite any pending requests in the request queue to account for the fact that a response might have changed ids that are expressed in the mutations of that queue. tempid-map MUST be a map from om tempid to real ids, not idents.
Rewrite any pending requests in the request queue to account for the fact that a response might have changed ids that are expressed in the mutations of that queue. tempid-map MUST be a map from om tempid to real ids, not idents.
(sc & args)
Just like defsc, but returns the component instead. The arguments are the same, except do not supply a symbol:
(let [C (prim/sc [this props] ...)] ...)
Just like defsc, but returns the component instead. The arguments are the same, except do not supply a symbol: ``` (let [C (prim/sc [this props] ...)] ...) ```
(schedule-render! r)
(schedule-render! reconciler)
(set-query! component-or-reconciler
class-or-factory
{:keys [query params follow-on-reads] :as opts})
Set a dynamic query. ALters the query, and then rebuilds internal indexes.
Set a dynamic query. ALters the query, and then rebuilds internal indexes.
(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.
(set-state! component new-state)
(set-state! component new-state cb)
(set-state! component new-state)
(set-state! component new-state callback)
Shallow merge new-state into the state of this component. This is asynchronous and will NOT be reflected by
get-state
immediately, since the underlying React setState and will trigger an refresh
according to React rules (see React dos for the version you're using).
This function manages a cljs map within React props, and does the shallow merge by key, so setting state:
{:x 1}
against an existing state of {:y 2} will yield:
{:x 1 :y 2}
The callback is as described in the React docs (it is invoked after the state is updated).
If you want to control the update function itself, use update-state!
.
If you're wanting low-level js interop to affect low-level js props: use React's setState
.
Shallow merge new-state into the state of this component. This is asynchronous and will NOT be reflected by `get-state` immediately, since the underlying React setState and will trigger an refresh according to React rules (see React dos for the version you're using). This function manages a cljs map within React props, and does the shallow merge by key, so setting state: {:x 1} against an existing state of {:y 2} will yield: {:x 1 :y 2} The callback is as described in the React docs (it is invoked after the state is updated). If you want to control the update function itself, use `update-state!`. If you're wanting low-level js interop to affect low-level js props: use React's `setState`.
(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.
(some-hasquery? c)
Returns true if the given component or one of its parents has a query.
Returns true if the given component or one of its parents has a query.
(strip-ui query)
Returns a new query with fragments that are in the ui
namespace removed.
Returns a new query with fragments that are in the `ui` namespace removed.
(sweep m)
Remove all of the not-found keys (recursively) from v, stopping at marked leaves (if present)
Remove all of the not-found keys (recursively) from v, stopping at marked leaves (if present)
(sweep-merge target source)
Do a recursive merge of source into target, but remove any target data that is marked as missing in the response. The missing marker is generated in the source when something has been asked for in the query, but had no value in the response. This allows us to correctly remove 'empty' data from the database without accidentally removing something that may still exist on the server (in truth we don't know its status, since it wasn't asked for, but we leave it as our 'best guess')
Do a recursive merge of source into target, but remove any target data that is marked as missing in the response. The missing marker is generated in the source when something has been asked for in the query, but had no value in the response. This allows us to correctly remove 'empty' data from the database without accidentally removing something that may still exist on the server (in truth we don't know its status, since it wasn't asked for, but we leave it as our 'best guess')
(sweep-one m)
Remove not-found keys from m (non-recursive)
Remove not-found keys from m (non-recursive)
(tempid? x)
Return true if x is a tempid, false otherwise
Return true if x is a tempid, false otherwise
(transact! x tx)
(transact! r ref tx)
Given a reconciler or component run a transaction. tx is a parse expression that should include mutations followed by any necessary read. The reads will be used to trigger component re-rendering.
Example:
(transact! widget '[(do/this!) (do/that!) :read/this :read/that])
NOTE: transact! is not safe to call from within mutations unless you defer it inside of a setTimeout. This is because otherwise you could potentially nest calls of swap! that will cause unexpected results. In general it the model of Fulcro is such that a call transact! within a mutation is technically just bad design. If you need pessimistic UI control, see ptransact! instead.
Given a reconciler or component run a transaction. tx is a parse expression that should include mutations followed by any necessary read. The reads will be used to trigger component re-rendering. Example: (transact! widget '[(do/this!) (do/that!) :read/this :read/that]) NOTE: transact! is not safe to call from within mutations unless you defer it inside of a setTimeout. This is because otherwise you could potentially nest calls of swap! that will cause unexpected results. In general it the model of Fulcro is such that a call transact! within a mutation is technically just bad design. If you need pessimistic UI control, see ptransact! instead.
(transact* reconciler c ref tx)
Internal implementation detail of transact!. Call that function instead.
Internal implementation detail of transact!. Call that function instead.
(tree->db x data)
(tree->db x data merge-idents)
(tree->db x data merge-idents transform)
Given a component class or instance and a tree of data, use the component's query to transform the tree into the default database format. All nodes that can be mapped via Ident implementations wil be replaced with ident links. The original node data will be moved into tables indexed by ident. If merge-idents option is true, will return these tables in the result instead of as metadata.
Given a component class or instance and a tree of data, use the component's query to transform the tree into the default database format. All nodes that can be mapped via Ident implementations wil be replaced with ident links. The original node data will be moved into tables indexed by ident. If merge-idents option is true, will return these tables in the result instead of as metadata.
(ui & forms)
Declare an anonymous UI component. If the first argument is a keyword, then it is treated as the React version (defaults to :v15).
Declare an anonymous UI component. If the first argument is a keyword, then it is treated as the React version (defaults to :v15).
(union->query union-query)
Turn a union query into a query that attempts to encompass all possible things that might be queried
Turn a union query into a query that attempts to encompass all possible things that might be queried
(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).
(writer)
(writer opts)
Create a transit writer. This writer can handler the tempid type. Can pass transit writer customization opts map.
Create a transit writer. This writer can handler the tempid type. Can pass transit writer customization opts map.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close