Extensibility of IInspect made difficult by cursors
Opened this issue · 2 comments
I tried using a custom renderer for Person records in the example included with ankha. I added the following code into the example (adapted from the readme):
(extend-protocol ankha/IInspect
Person
(-inspect [this]
(dom/span #js {:className "record user"}
(dom/span nil "First name: " (:first-name this))
" "
(dom/span nil "Last name: " (:last-name this)))))
However, this custom inspector doesn't get used. Instead, the one associated with the MapCursor
is used.
To trigger the Person renderer, I had to modify the example to unwrap the cursor with om/vaule
and then pass that to the inspector. But then the data is no longer editable.
Am I approaching this the wrong way or is there an ankha bug here?
I'm beginning to wonder if a protocol was the wrong choice for extensibility. A multimethod might have been a better choice. We could probably fix this issue by checking if (extends? IInspect (om/value x))
in the MapCursor
implementation and calling -inspect
if it's true otherwise fall back to default record behavior.
One thing you can do is override om's protocol if you are using a record:
(defrecord RecordTest [x y]
om/IToCursor
(-to-cursor [value state path]
value))
I think this will only work when you are dealing with a leaf item in a tree.