this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: add View.node JSON encoding to message protocol

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

+44
+44
idl/message.ml
··· 139 139 let get_string_array obj key = 140 140 Array.to_list (Array.map Js.to_string (get_array obj key)) 141 141 142 + (** {1 View node JSON encoding} *) 143 + 144 + let rec json_of_view_attr (a : Widget_view.attr) = 145 + match a with 146 + | Property (k, v) -> 147 + json_of_obj [("t", json_string "prop"); ("k", json_string k); ("v", json_string v)] 148 + | Style (k, v) -> 149 + json_of_obj [("t", json_string "style"); ("k", json_string k); ("v", json_string v)] 150 + | Class c -> 151 + json_of_obj [("t", json_string "cls"); ("v", json_string c)] 152 + | Handler (ev, id) -> 153 + json_of_obj [("t", json_string "handler"); ("ev", json_string ev); ("id", json_string id)] 154 + 155 + and json_of_view_node (n : Widget_view.node) = 156 + match n with 157 + | Text s -> 158 + json_of_obj [("t", json_string "txt"); ("v", json_string s)] 159 + | Element { tag; attrs; children } -> 160 + json_of_obj [ 161 + ("t", json_string "el"); 162 + ("tag", json_string tag); 163 + ("a", json_array (List.map (fun a -> Js.Unsafe.inject (json_of_view_attr a)) attrs)); 164 + ("c", json_array (List.map (fun c -> Js.Unsafe.inject (json_of_view_node c)) children)); 165 + ] 166 + 167 + let view_attr_of_json obj : Widget_view.attr = 168 + let t = get_string obj "t" in 169 + match t with 170 + | "prop" -> Property (get_string obj "k", get_string obj "v") 171 + | "style" -> Style (get_string obj "k", get_string obj "v") 172 + | "cls" -> Class (get_string obj "v") 173 + | "handler" -> Handler (get_string obj "ev", get_string obj "id") 174 + | _ -> failwith ("Unknown attr type: " ^ t) 175 + 176 + let rec view_node_of_json obj : Widget_view.node = 177 + let t = get_string obj "t" in 178 + match t with 179 + | "txt" -> Text (get_string obj "v") 180 + | "el" -> 181 + let attrs = Array.to_list (Array.map view_attr_of_json (get_array obj "a")) in 182 + let children = Array.to_list (Array.map view_node_of_json (get_array obj "c")) in 183 + Element { tag = get_string obj "tag"; attrs; children } 184 + | _ -> failwith ("Unknown node type: " ^ t) 185 + 142 186 (** {1 Worker message serialization} *) 143 187 144 188 let json_of_position p =