(ns buddho.core.dhamma.state
  "Facilities for managing dhamma registration in state memory."
  (:require [buddho.core.state :as s :refer [value reference]]
            [buddho.core.dhamma.data :refer [make-dhamma]]))

(defn register-dhamma!
  "Register a dhamma."
  [name & {:keys [data meta is-aspect-of? asp-props transient]
           :as args}]
  (let [idea (s/have-idea! "dhamma_")
        dhamma (make-dhamma name args)]
    (s/update-idea! idea dhamma)
    (s/register-property! idea [:dhamma])))

(defn remove-dhamma! [dhamma]
  (s/forget-idea! dhamma))

(defn update-dhamma! [dhamma fun]
  (s/update-idea! (reference dhamma) (fun (value dhamma))))
