Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No protocol method IWithMeta.-with-meta defined #28

Closed
tony-landis opened this issue Dec 10, 2014 · 3 comments
Closed

No protocol method IWithMeta.-with-meta defined #28

tony-landis opened this issue Dec 10, 2014 · 3 comments

Comments

@tony-landis
Copy link

I have created a cursor using with-meta:

  (with-meta 
    (cursor a path)
    {:path path
     :atom a}) 

Attempting to use the cursor throws this exception:

No protocol method IWithMeta.-with-meta defined for type freactive.core/ReactiveCursor

It would be great to be able to have metadata on cursors.

Thanks!

@aaronc
Copy link
Owner

aaronc commented Dec 10, 2014

Cursors, like other "ref"s should support alter-meta!

@tony-landis
Copy link
Author

Thanks Aaron. For an app I am building, it is very useful to track a cursor's parent iref and the key sequence. I was able to implement a helper fn to accomplish this using alter-meta!

(clojure
(defn cursor!
[iref key-s]
"builds a cursor with metadata to track its parent "
(let [c (cursor iref key-s) ]
(alter-meta! c assoc :iref iref :key-s key-s)
c))

@aaronc
Copy link
Owner

aaronc commented Dec 11, 2014

Do you think this is important enough to put into core?

I'm thinking something like this:

(defn cursor* [ref korks-or-getter setter lazy]
  (let [ks (cond
            (keyword? korks-or-getter)
            [korks-or-getter]

            (sequential? korks-or-getter)
            korks-or-getter)
...
        cursor (ReactiveCursor. ref getter setter true nil nil nil nil lazy nil nil)]
...
     (when ks
       (let [{:keys [root path]} (meta ref)
              path-info (if (and root path)
                               {:root root :path (concat path ks)}
                               {:root ref :path ks})]
           (alter-meta! cursor merge path-info)))
     cursor))

That would capture the path back to the root if available. What do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants