 (defprotocol IReadOnly
   (-read-only? [_]))
 
+(declare writeable!)
+
 (deftype Native [^:mutable __ro]
   IReadOnly
   (-read-only? [_] __ro)


  IAssociative
  (-assoc [native k v]
    (let [new (goog.object.clone native)]
      (aset new (if (keyword? k) (name k) k) v)
      new))
  
  IMap
  (-dissoc [native k]
    (let [new (goog.object.clone native)]
      (cljs.core/js-delete new (if (keyword? k) (name k) k))
      new))
    
  ICollection
  (-conj [native [k v]]
    (let [new (goog.object.clone native)]
      (aset new (if (keyword? k) (name k) k) v)
      new)))


    (set! (.-constructor jsobj) Native)
    ;; TODO: Copy impls?
    ))

(defn native? [native]
  (= (.-constructor native) Native))

(defn read-only! [native]
  {:pre [(native? native)]}
  (set! (.-__ro native) true))

(defn writeable! [native]
  {:pre [(native? native)]}
  (set! (.-__ro native) false))

;;
;; Native object store
