sdfsdfs
This commit is contained in:
@@ -3,7 +3,9 @@
|
||||
The 'R' in 'CRUD' is implemented by [[emptyhead.idea.protocol/value]]."
|
||||
(:require [emptyhead.idea.state :refer [state]]
|
||||
[emptyhead.idea.property :as prop]
|
||||
[emptyhead.idea.protocol :as prtc]))
|
||||
[emptyhead.idea.protocol :as prtc]
|
||||
[emptyhead.idea.memtag :as memtag]
|
||||
[clojure.set :as set]))
|
||||
|
||||
(defn- register-idea!
|
||||
"Helper function to scaffold an 'empty' idea."
|
||||
@@ -48,11 +50,14 @@
|
||||
"Instantiate up to `count` new ideas, optionally prefixing reference symbol with `prefix`.
|
||||
Additionally allows you to immediately attach `properties` and `data`.
|
||||
Returns a single idea or a list of ideas depending on whether `count` was given."
|
||||
[& {:keys [prefix count properties data]
|
||||
:or {count 1 prefix "idea" properties []}}]
|
||||
[& {:keys [prefix count properties data shadowing]
|
||||
:or {count 1 prefix "idea" properties [] shadowing []}}]
|
||||
(let [fun #(register-idea! (gensym (str prefix "$")))
|
||||
ideas (take count (repeatedly fun))]
|
||||
ideas (take count (repeatedly fun))
|
||||
shadowing (apply set/union (map prop/with-property shadowing))]
|
||||
(run! forget-idea! shadowing)
|
||||
(run! #(apply prop/register-property! % properties) ideas)
|
||||
(run! #(prop/register-property! % (memtag/uid-of %)) ideas)
|
||||
(when data (run! #(extend-idea! % data) ideas))
|
||||
(if (= count 1)
|
||||
(first ideas)
|
||||
|
||||
12
src/cljs/emptyhead/idea/memtag.cljs
Normal file
12
src/cljs/emptyhead/idea/memtag.cljs
Normal file
@@ -0,0 +1,12 @@
|
||||
(ns emptyhead.idea.memtag
|
||||
(:require [emptyhead.idea.property :as prop]
|
||||
[emptyhead.idea.protocol :as prtc]))
|
||||
|
||||
(defn add-group! [idea & group]
|
||||
(let [group (or group
|
||||
[:emptyhead :memtag :group (keyword (gensym "memtag#group$"))])]
|
||||
(prop/register-property! idea group)
|
||||
group))
|
||||
|
||||
(defn uid-of [idea]
|
||||
[:emptyhead :memtag :uid (prtc/ref-fn keyword idea)])
|
||||
@@ -9,8 +9,10 @@
|
||||
(let [ref (get-in val [:_meta :_reference])]
|
||||
(cond
|
||||
(get-in val [:_meta :_stale-reference])
|
||||
(log/error (str "Attempt to find stale reference `" ref "` -- this is a copy.")
|
||||
{:value val :type :stale-reference})
|
||||
(do
|
||||
(println "fucky wucky " val)
|
||||
(log/error (str "Attempt to find stale reference `" ref "` -- this is a copy.")
|
||||
{:value val :type :stale-reference}))
|
||||
|
||||
(not (symbol? ref))
|
||||
(log/error (str "Attempt to find invalid reference `" ref "` -- invalid idea?")
|
||||
@@ -42,14 +44,15 @@
|
||||
[idea]
|
||||
(assoc-in (value idea) [:_meta :_stale-reference] true))
|
||||
|
||||
(defn- non-copy [idea] (assoc-in (value idea) [:_meta :_stale-reference] false))
|
||||
(defn non-copy [idea] (assoc-in (value idea) [:_meta :_stale-reference] false))
|
||||
|
||||
(defn uncopy!
|
||||
"Takes a copied idea and 'uncopies' it, making its reference active again
|
||||
and updating what is in the game state."
|
||||
[copy-obj]
|
||||
(let [idea (non-copy copy-obj)]
|
||||
(swap! state assoc (to-reference idea) idea)))
|
||||
(swap! state assoc (reference idea) idea)
|
||||
(reference idea)))
|
||||
|
||||
(defn force-reference
|
||||
"Get the (now stale!) reference of a copied idea."
|
||||
|
||||
Reference in New Issue
Block a user