{"action":"created","issue":{"url":"https://api.github.com/repos/reagent-project/reagent/issues/92","labels_url":"https://api.github.com/repos/reagent-project/reagent/issues/92/labels{/name}","comments_url":"https://api.github.com/repos/reagent-project/reagent/issues/92/comments","events_url":"https://api.github.com/repos/reagent-project/reagent/issues/92/events","html_url":"https://github.com/reagent-project/reagent/issues/92","id":56170089,"number":92,"title":"Allow any atom to be reagent-ized","user":{"login":"Frozenlock","id":1152041,"avatar_url":"https://avatars.githubusercontent.com/u/1152041?v=3","gravatar_id":"","url":"https://api.github.com/users/Frozenlock","html_url":"https://github.com/Frozenlock","followers_url":"https://api.github.com/users/Frozenlock/followers","following_url":"https://api.github.com/users/Frozenlock/following{/other_user}","gists_url":"https://api.github.com/users/Frozenlock/gists{/gist_id}","starred_url":"https://api.github.com/users/Frozenlock/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Frozenlock/subscriptions","organizations_url":"https://api.github.com/users/Frozenlock/orgs","repos_url":"https://api.github.com/users/Frozenlock/repos","events_url":"https://api.github.com/users/Frozenlock/events{/privacy}","received_events_url":"https://api.github.com/users/Frozenlock/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/reagent-project/reagent/labels/enhancement","name":"enhancement","color":"84b6eb"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-02-01T17:16:23Z","updated_at":"2015-02-16T15:34:46Z","closed_at":null,"body":"I recently built [Entanglement](https://github.com/Frozenlock/entanglement) specifically to manipulate atoms. It was becoming clear, with all the cursors/lenses/wraps appearing everywhere, that there was an underlying problem trying to be solved there.\r\n\r\nAnyhow...\r\n\r\nWith a few modifications in `ratom.cljs` , Reagent could be used with *any* atom construct, while making (IMO) the code simpler.\r\n\r\nIn the `ratom.cljs` namespace:\r\n```clj\r\n\r\n(declare ^:dynamic *in-ratom*)\r\n\r\n(defn reagent-ize\r\n  \"Add the special Reagent sauce to an atom. Return the new and\r\n  improved atom.\"\r\n  [source-atom]\r\n  (let [derefer (fn [this source-atom getter]\r\n                  (if-not *in-ratom*\r\n                    ;; if we are not already derefing from another ratom\r\n                    (do (notify-deref-watcher! this)\r\n                        (binding [*in-ratom* true]\r\n                          (getter (-deref source-atom))))\r\n                    ;; already in ratom: just get the value\r\n                    (getter (-deref source-atom))))]\r\n    (ent/entangle source-atom\r\n                  (fn [value] value) ;; identity\r\n                  (fn [_ new-val] new-val)\r\n                  :derefer derefer)))\r\n\r\n\r\n(defn atom\r\n  \"Like clojure.core/atom, except that it keeps track of derefs.\"\r\n  [x & rest]\r\n  (-> (apply cljs.core/atom x rest)\r\n      (reagent-ize))) ;; <--- Special Reagent sauce\r\n```\r\n\r\nFollowing that, `cursors` could simply be this:\r\n\r\n```clj\r\n(defn cursor\r\n  \"Like a normal cursor, but make sure Reagent capture it, rather than\r\n  any higher up atoms in the chain.\"\r\n  [a path]\r\n  (-> (ent/cursor a path)\r\n      (reagent-ize)))  ;; <--- special Reagent sauce\r\n```\r\n\r\nI tested it in my own Reagent applications and it seems to work. The only thing bugging me is that it fails the tests (if I ran them correctly...).\r\n\r\nI wanted to ask for opinions before spending any more time with this.\r\n"},"comment":{"url":"https://api.github.com/repos/reagent-project/reagent/issues/comments/74525840","html_url":"https://github.com/reagent-project/reagent/issues/92#issuecomment-74525840","issue_url":"https://api.github.com/repos/reagent-project/reagent/issues/92","id":74525840,"user":{"login":"holmsand","id":224523,"avatar_url":"https://avatars.githubusercontent.com/u/224523?v=3","gravatar_id":"","url":"https://api.github.com/users/holmsand","html_url":"https://github.com/holmsand","followers_url":"https://api.github.com/users/holmsand/followers","following_url":"https://api.github.com/users/holmsand/following{/other_user}","gists_url":"https://api.github.com/users/holmsand/gists{/gist_id}","starred_url":"https://api.github.com/users/holmsand/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/holmsand/subscriptions","organizations_url":"https://api.github.com/users/holmsand/orgs","repos_url":"https://api.github.com/users/holmsand/repos","events_url":"https://api.github.com/users/holmsand/events{/privacy}","received_events_url":"https://api.github.com/users/holmsand/received_events","type":"User","site_admin":false},"created_at":"2015-02-16T15:34:45Z","updated_at":"2015-02-16T15:34:45Z","body":"@Frozenlock Looks interesting, but I'm not entirely sure what it is you want to achieve here… \r\n\r\nIf you want to create an alias for a \"non-Reagent atom\", you can do this today just by setting up mutual add-watches between a Reagent atom and a clojure.core one, that keeps them in sync at all times. \r\n\r\nIf you want to customize getters and setters, you can do that as well, using the new cursors in 0.5.0-alpha3. \r\n\r\nOr do you have another use-case altogether in mind?"}}