This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-02-24
Channels
- # admin-announcements (1)
- # aleph (3)
- # announcements (4)
- # beginners (30)
- # boot (296)
- # cider (21)
- # cljsjs (2)
- # cljsrn (18)
- # clojure (124)
- # clojure-poland (23)
- # clojure-russia (4)
- # clojurescript (73)
- # core-async (58)
- # css (3)
- # datomic (31)
- # editors (4)
- # emacs (35)
- # euroclojure (3)
- # hoplon (104)
- # immutant (8)
- # jobs (3)
- # jobs-discuss (1)
- # keechma (1)
- # ldnclj (33)
- # leiningen (5)
- # liberator (1)
- # mount (20)
- # off-topic (2)
- # om (104)
- # onyx (54)
- # parinfer (80)
- # proton (1)
- # re-frame (59)
- # remote-jobs (1)
- # ring-swagger (9)
- # slack-help (15)
- # spacemacs (7)
- # yada (12)
is there a “hoplon way” to store data on elements, or should I just use data attributes?
or jquery data?
how do i get user input into vars?
sure, so if i use a datascript db to build a bunch of inputs
from a query
and i want to reference something in the db by entity id
i’d need to know, at the time the event is triggered, what input matches what id
so, your example gives me a value, but what about the key?
(loop-tpl [[input-key input-value] (cell= (as-key-value-map (d/q ...)))]
(input :type "text", :keyup #(input-changed! input-key %@), :value input-value))
would something like that work?hmm, maybe
that direct example would be buggy
based on my experience
because there seems to be some weird race conditions between changing cells on :keyup or :input or :keydown and the way the DOM reflows
it mostly works
but sometimes i’ll see some of the attributes on inputs change, but missing values, etc.
what i’m trying at the moment, is running a timeout on keyup
then a query to flush all the “invalid” entities from the db
which reflows the DOM consistently AFAICS
or at least, i haven’t been able to make it bug out
but i want to re-insert focus back into the DOM just before the removed input
so, get the highest entity id lower than the one i removed, and select that
I think your suggestion might work for that
i’ll try it out
i also have to learn how the queries work, lol
link to docs?
kind of like https://github.com/tonsky/datascript/wiki/Tips-&-tricks#getting-top-10-entities-by-some-attribute
i don’t totally understand it just from that
where do i put the db cell?
(take 10 (d/datoms :avet :post/timestamp))
that’s an example
that’s different to what you just said?
yeah, it’s like that all the way through
the datascript docs aren’t great tbh
they just link to datomic
which is what i’m reading through
@dm3: just tried your approach to sending through the id
@dm3: works well, i just have to remember to deref so i get the value before the db is purged and not when i happen to use it
kk, so i have something like this
(prn (d/q '[:find ?id :where [?id :data ?data] [(< ?id 250)]] @conn))
and that works
but (prn (d/q '[:find ?id :where [?id :data ?data] [(< ?id id)]] @conn))
does not
i think because the ’
makes id
not be the id as a number in that scope
i feel i’m missing something obvious 😛
pass as a parameter to d/q
ey?
that’s new
i’ll try that
ooooh i think that worked
@dm3: OK, sooo
now i have the highest ID that was less than the ID of the thing that was invalid
how do I select that in the DOM without a data attribute?
dunno? i’ll try 😛
sort of..
so :focus
moves the cursor to the input, to the end
select()
from jquery actually selects all the text in the input
i wonder if there’s something like :focus
for selecting
@dm3: so is the idea that if i pass :focus
something true
it will trigger focus, otherwise if i pass it a function it will trigger that function when it gets focus?
something is certainly happening
it does trigger focus/select
but then after it does that i want it to clear out the cell containing what needs to be focused/selected
but I can’t put a cell=
that might be a boolean and also an event handler on a single attribute
so close to being able to get rid of the data attribute
gotta keep going >.<
got it!
i think
(input
:select (cell= (= id select-id))
:focusin #(select-id! :none)
(defc select-id :none)
(defn select-id! [id] (reset! select-id id))
assuming this doesn’t turn out to be buggy
this is very cool
although, i got lucky this time, it does appear that in general it would be limiting to not be able to both bind and trigger a given event on an element...
@dm3 thanks heaps for your help