Created
February 21, 2024 18:08
-
-
Save camsaul/2e919d539523d3a0dfc335b4ad66a80d to your computer and use it in GitHub Desktop.
Dataset Hating Map
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; it's a map that hates if you try to get the key `:dataset` from it. NOCOMMIT | |
(declare ->DatasetHatingMap) | |
(defn- check-for-dataset-key [k] | |
(when (= k :dataset) | |
(throw (ex-info ":dataset is deprecated, use :type instead!" {})))) | |
(p/def-map-type DatasetHatingMap [m] | |
(get [_this k default-value] | |
(check-for-dataset-key k) | |
(get m k default-value)) | |
(assoc [this k v] | |
(check-for-dataset-key k) | |
(let [m' (assoc m k v)] | |
(if (identical? m m') | |
this | |
(->DatasetHatingMap m')))) | |
(dissoc [this k] | |
(check-for-dataset-key k) | |
(let [m' (dissoc m k)] | |
(if (identical? m m') | |
this | |
(->DatasetHatingMap m')))) | |
(keys [_this] | |
(keys m)) | |
(meta [_this] | |
(meta m)) | |
(with-meta [this metta] | |
(let [m' (with-meta m metta)] | |
(if (identical? m m') | |
this | |
(->DatasetHatingMap m')))) | |
pretty/PrettyPrintable | |
(pretty [_this] | |
(list `->DatasetHatingMap m))) | |
(t2/define-after-select :model/Card | |
[card] | |
(let [card (public-settings/remove-public-uuid-if-public-sharing-is-disabled card) | |
m* (into (DatasetHatingMap. {}) card)] | |
(t2.instance/->Instance (t2/model card) m* m* (meta card)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
the last line is a workaround for camsaul/toucan2#164, you would think you could do
or whatever and it would preserve card's map type, but it doesn't