Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions calcit.cirru
Original file line number Diff line number Diff line change
Expand Up @@ -2374,6 +2374,11 @@
:code $ quote $ defunion StateKey Tag String Number
:examples $ []
:schema $ quote UnionDef
'TextInputEvent $ %{} 'CodeEntry (:doc |)
:code $ quote $ defunion TextInputEvent respo.schema/RespoEvent
Map Tag $ JsNullish String
:examples $ []
:schema $ quote UnionDef
'command $ %{} 'CodeEntry (:doc |)
:code $ quote $ def command
{} (:id nil) (:title |) (:path |.) (:code |)
Expand Down Expand Up @@ -2468,15 +2473,18 @@
'event-value $ %{} 'CodeEntry
:doc "|Text value of an input event. Respo passes a RespoEvent struct; tests and legacy callers pass a map."
:code $ quote $ defn event-value (event)
let
fields $ if (struct? event) (&struct:to-map event)
decode-map-as event $ Map Tag Dynamic
match (get fields :value)
(:some value)
match event
(respo.schema/RespoEvent input)
let
value $ :value input
if (nil? value) | $ decode-map-as value 'String
(:none) |
(Map fields)
match (get fields :value)
(:some value)
if (js-nullish? value) | $ decode-map-as value 'String
(:none) |
:examples $ []
:schema $ quote $ Fn Dynamic (-> String)
:schema $ quote $ Fn TextInputEvent (-> String) (:features :js-ffi)
'field-or $ %{} 'CodeEntry
:doc "|Read an optional wire field. A missing or nil field gives the fallback."
:code $ quote $ defn field-or (fields field fallback)
Expand Down
6 changes: 5 additions & 1 deletion tests/components.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { comp_container, decode_view } from '../out-page/app.comp.container.mjs'
import { Op, decode_changes, op_to_wire } from '../out-page/app.schema.mjs';
import { patch_twig } from '../out-page/recollect.patch.mjs';
import { websocket_url, clear_current_route_$x_ } from '../out-page/app.util.mjs';
import { event__GT_edn } from '../out-page/respo.util.format.mjs';

const tags = c.init_tags(['tree', 'children', 'node', 'key', 'name', 'attrs', 'event', 'input', 'click', 'value', 'inner-text', 'title', 'code', 'path', 'command', 'cwd', 'router', 'count', 'color']);
const read = (value, key) => c.option_$o_unwrap(c.get(value, tags[key]));
Expand Down Expand Up @@ -115,7 +116,10 @@ test('command editor preserves legacy draft values, edits each field and submits
const inputs = nodes.filter(node => read(node, 'name').value === 'input');
assert.deepEqual(values(inputs), ['合成🐈', 'never-run', './sandbox']);
for (const [index, field] of ['title', 'code', 'path'].entries()) {
read(read(inputs[index], 'event'), 'input')(parse('{} (:value |更新🌱)'), dispatch);
const event = index === 0
? event__GT_edn({ type: 'input', target: { value: '更新🌱', checked: false } })
: parse('{} (:value |更新🌱)');
read(read(inputs[index], 'event'), 'input')(event, dispatch);
const args = calls.at(-1);
assert.equal(args.length, 1);
assert.equal(part(args[0], 0).value, 'states');
Expand Down