Skip to content

Commit cbf5813

Browse files
authored
用 StateKey union 收紧 Termina 的本地状态路径 (#65)
1 parent 98ac479 commit cbf5813

2 files changed

Lines changed: 20 additions & 12 deletions

File tree

‎calcit.cirru‎

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
(:states cursor s)
4747
reset! *states $ decode-map-as
4848
update-states @*states
49-
decode-map-as cursor $ List Dynamic
49+
decode-map-as cursor $ List app.schema/StateKey
5050
, s
5151
Map Tag Dynamic
5252
(:effect/connect) (connect!)
@@ -200,7 +200,7 @@
200200
let
201201
cursor $ decode-map-as
202202
.unwrap $ get states :cursor
203-
List Dynamic
203+
List app.schema/StateKey
204204
state $ decode-map-as
205205
or (app.schema/field-or states :data nil)
206206
if (.some? base-command)
@@ -271,7 +271,7 @@
271271
let
272272
cursor $ decode-map-as
273273
.unwrap $ get states :cursor
274-
List Dynamic
274+
List app.schema/StateKey
275275
state $ decode-map-as
276276
either (app.schema/field-or states :data nil)
277277
{} $ :pop? false
@@ -686,7 +686,7 @@
686686
let
687687
cursor $ decode-map-as
688688
.unwrap $ get states :cursor
689-
List Dynamic
689+
List app.schema/StateKey
690690
state $ let
691691
raw-state $ or (app.schema/field-or states :data nil)
692692
{} (:query |) (:pop? false)
@@ -929,7 +929,7 @@
929929
let
930930
cursor $ decode-map-as
931931
.unwrap $ get states :cursor
932-
List Dynamic
932+
List app.schema/StateKey
933933
state $ decode-map-as
934934
or (app.schema/field-or states :data nil) initial-state
935935
Map Tag String
@@ -1305,7 +1305,7 @@
13051305
let
13061306
cursor $ decode-map-as
13071307
.unwrap $ get states :cursor
1308-
List Dynamic
1308+
List app.schema/StateKey
13091309
state $ let
13101310
raw-state $ either (app.schema/field-or states :data nil)
13111311
{} (:filter |) (:filter? true) (:wrap? true) (:all-log? false) (:hide-thread-info? false)
@@ -1707,7 +1707,7 @@
17071707
let
17081708
cursor $ decode-map-as
17091709
.unwrap $ get states :cursor
1710-
List Dynamic
1710+
List app.schema/StateKey
17111711
state $ let
17121712
original-state $ or (app.schema/field-or states :data nil)
17131713
{} (:focused-id nil) (:base-workflow nil) (:pop? false)
@@ -1842,7 +1842,7 @@
18421842
let
18431843
cursor $ decode-map-as
18441844
.unwrap $ get states :cursor
1845-
List Dynamic
1845+
List app.schema/StateKey
18461846
state $ decode-map-as
18471847
either (app.schema/field-or states :data nil)
18481848
{} (:pop? false) (:edit? false)
@@ -1971,7 +1971,7 @@
19711971
let
19721972
cursor $ decode-map-as
19731973
.unwrap $ get states :cursor
1974-
List Dynamic
1974+
List app.schema/StateKey
19751975
state $ decode-map-as
19761976
or (app.schema/field-or states :data nil)
19771977
if (.some? base-workflow)
@@ -2334,7 +2334,7 @@
23342334
'Op $ %{} 'CodeEntry
23352335
:doc "|Operations dispatched by page components. Most are forwarded to the server."
23362336
:code $ quote $ defenum Op
2337-
:states (List Dynamic) Dynamic
2337+
:states (List app.schema/StateKey) Dynamic
23382338
:effect/connect
23392339
:session/connect
23402340
:session/disconnect
@@ -2366,6 +2366,10 @@
23662366
:command Dynamic
23672367
:examples $ []
23682368
:schema $ quote EnumDef
2369+
'StateKey $ %{} 'CodeEntry (:doc |)
2370+
:code $ quote $ defunion StateKey Tag String Number
2371+
:examples $ []
2372+
:schema $ quote UnionDef
23692373
'command $ %{} 'CodeEntry (:doc |)
23702374
:code $ quote $ def command
23712375
{} (:id nil) (:title |) (:path |.) (:code |)

‎tests/components.test.mjs‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,13 @@ test('workflow button preserves command paths and dispatches one Enum without ru
9898
});
9999

100100
test('command editor preserves legacy draft values, edits each field and submits two arguments', () => {
101-
const cursor = parse('[] :editor 7');
101+
const cursor = parse('[] :editor |command 7');
102102
const state = parse('{} (:title |合成🐈) (:code |never-run) (:path |./sandbox)');
103-
const states = c.parse_cirru_edn('{} (:cursor $ [] :editor 7) (:data $ {} (:title |合成🐈) (:code |never-run) (:path |./sandbox))');
103+
const states = c.parse_cirru_edn('{} (:cursor $ [] :editor |command 7) (:data $ {} (:title |合成🐈) (:code |never-run) (:path |./sandbox))');
104+
assert.throws(
105+
() => comp_command_editor(parse('{} (:cursor $ [] true)'), parse(':: :none'), () => {}),
106+
/decode-map-as/,
107+
);
104108
const calls = [], submissions = [];
105109
const dispatch = (...args) => calls.push(args);
106110
const nodes = elements(comp_command_editor(states, parse(':: :none'), (...args) => submissions.push(args)));

0 commit comments

Comments
 (0)