Liking cljdoc? Tell your friends :D

leva.schema

Functions for converting a leva.cljs schema into a Leva schema set up for state synchronization via a ClojureScript atom.

Functions for converting a leva.cljs schema into a Leva schema set up for state
synchronization via a ClojureScript atom.
raw docstring

->cljcljs

(->clj v)

Slightly more efficient js->clj that skips primitive types.

Slightly more efficient `js->clj` that skips primitive types.
sourceraw docstring

build-schemacljs

(build-schema schema state k->on-change)

Given

  • a ClojureScript schema
  • an initial state (a dereferenced atom)
  • a function k->on-change from a k to a state-updating on-change handler,

Returns a Leva schema (to pass to useControls) modified to synchronize state back to some external store like a Reagent atom.

Given

- a ClojureScript `schema`
- an initial `state` (a dereferenced atom)
- a function `k->on-change` from a `k` to a state-updating `on-change` handler,

Returns a Leva schema (to pass to `useControls`) modified to synchronize state
back to some external store like a Reagent atom.
sourceraw docstring

controlled->jscljs

(controlled->js k v schema on-change)

Given

  • a key k and value v from some stateful store like an atom,
  • a schema for the value,
  • a state-updating function on-change of type (value, path, context) => void

Returns a JS Leva schema entry that will configure the k's value v to push state updates via on-change.

NOTE that if v is a map, entries in v will take precedence over any duplicates in schema.

Given

- a key `k` and value `v` from some stateful store like an atom,
- a `schema` for the value,
- a state-updating function `on-change` of type (value, path, context) => void

Returns a JS Leva schema entry that will configure the `k`'s value `v` to push
state updates via on-change.

NOTE that if `v` is a map, entries in `v` will take precedence over any
duplicates in `schema`.
sourceraw docstring

merge-controlled-entries!cljs

(merge-controlled-entries! acc m k->on-change)

Given

  • a mutable JS object acc representing the Leva schema
  • a map m of new entries to merge into acc,
  • a function k->on-change from a k to a state-updating on-change handler,

Sets onChange on all values in m.

Returns acc with the transformed m merged in.

Given

- a mutable JS object `acc` representing the Leva schema
- a map `m` of new entries to merge into `acc`,
- a function `k->on-change` from a `k` to a state-updating `on-change` handler,

Sets `onChange` on all values in `m`.

Returns `acc` with the transformed `m` merged in.
sourceraw docstring

normalize-entrycljs

(normalize-entry entry)

Accepts an entry in a leva schema and normalizes nil?, vector? or leva.types/primitive? values into a map for easier processing below.

Given a map-shaped entry, acts as identity.

Accepts an `entry` in a leva schema and normalizes `nil?`, `vector?`
or [[leva.types/primitive?]] values into a map for easier processing below.

Given a map-shaped `entry`, acts as identity.
sourceraw docstring

on-change-fncljs

(on-change-fn !state)

Given some atom !state, returns a function that accepts some key and returns a Leva OnChangeHandler that sets the entry in !state for key to the new incoming value.

Given some atom `!state`, returns a function that accepts some `key` and
returns a Leva OnChangeHandler that sets the entry in `!state` for `key` to
the new incoming value.
sourceraw docstring

opts->argvcljs

(opts->argv {:keys [folder schema atom store]})

Accepts the options map for a leva.core/Controls component and returns the rather confusing vector of arguments required by leva's useControls hook.

The parsing logic lives here in leva.

Accepts the options map for a [[leva.core/Controls]] component and returns the
rather confusing vector of arguments required by leva's `useControls` hook.

The parsing logic [lives
here](https://github.com/pmndrs/leva/blob/33b2d9948818c5828409e3cf65baed4c7492276a/packages/leva/src/useControls.ts#L30-L75)
in leva.
sourceraw docstring

uncontrolled->jscljs

(uncontrolled->js k schema)

Given some key k and a corresponding schema, returns (clj->js schema) after ensuring that schema has an onChange handler registered.

If it doesn't, emits a warning and inserts a no-op handler before conversion.

returns a JS Leva schema entry that will configure the k's value v to push state updates via on-change.

NOTE that we do this because without an :onChange handler, leva's useControls hook forces the component to re-render any time the value for k changes. The re-render is a waste because the user can't get at the changed value.

Given some key `k` and a corresponding `schema`, returns `(clj->js schema)`
after ensuring that `schema` has an onChange handler registered.

If it doesn't, emits a warning and inserts a no-op handler before conversion.

returns a JS Leva schema entry that will configure the `k`'s value `v` to push
state updates via on-change.

NOTE that we do this because without an `:onChange` handler, leva's
`useControls` hook forces the component to re-render any time the value for
`k` changes. The re-render is a waste because the user can't get at the
changed value.
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close