This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-02-20
Channels
- # admin-announcements (1)
- # beginners (17)
- # boot (22)
- # cider (43)
- # cljs-dev (6)
- # cljsjs (2)
- # clojure (29)
- # clojure-austin (7)
- # clojure-estonia (1)
- # clojure-russia (62)
- # clojure-sg (1)
- # clojurebridge (2)
- # clojured (1)
- # clojurescript (89)
- # datomic (8)
- # hoplon (333)
- # jobs (3)
- # ldnclj (2)
- # leiningen (10)
- # luminus (1)
- # off-topic (9)
- # om (46)
- # proton (4)
- # re-frame (13)
- # reagent (29)
- # yada (11)
if i’m doing a loop-tpl
, is there a way to get at the next/previous items?
@thedavidmeister: one way is by assigning the elements in the template an id
attribute based on some known string and the loop # (you can get this by using map-indexed)
that's kind of gross though because it involves dipping into global dom scope, what are you trying to do?
@alandipert: just wanting to select the “next” element on keyup
usually when i think i need to fish around in the dom it's because there is an aspect of the overall model that i've missed
yeah, i’m looking at trying something...
i got [[a b] [c d] ...]
looking at dropping the first and mapping into
to get [[a b c] [c d e]]
dunno how good an idea that is
oh well, (loop-tpl :bindings [[id data]
becomes (loop-tpl :bindings [[id data next-id]
so i can stick “next-id” on the DOM element
probably
actually… all that’s really happening
is the browser by default moves the cursor to a new input
i want it to select the text in the input
i only just articulated it like that for the first time just now 😛
yeah i’ll try that now
annoyingly, it doesn’t seem to be triggering focus
but when the browser does something automatically that changes the ui state it usually fires an event
yeah it should
i’m surprised that it doesn't
maybe i don’t understand something about hoplon
so i’m building inputs based on a collection cell in loop-tpl
then i delete something from the cell
the browser sticks the cursor in one of the remaining inputs
but doesn’t seem to make focus happen
mmm it’s not triggering focus
i just did a console log to check
i’m wondering if the input is actually getting removed from the middle
that does appear to be what’s happening
but all the values/attributes shift?
sooooo
that’s kinda messing with me
actually now that i know that’s happening, i’m suspicious that’s messed with me before too
any idea how I could react to what hoplon is doing?
yeah hang on
so, you do need datascript
oh well i suppose you don't
i can cut this back a bit more
hangong
just pulling things out 😛
except..
:input #(d/transact! conn
(if-not (= "" @%)
(if-not @id
; create
[{:data @%}]
; update
[{:db/id @id :data @%}]
)
(if @id
; delete
[[:db.fn/retractEntity @id]])))
that’s my input handler, lol
(loop-tpl :bindings [[id data] state] [
(input
:type "text"
:value data
; input occurs on keydown but after the input's value has been updated
; c.f. keydown that occurs before the value has changed.
:input #(d/transact! conn
(if-not (= "" @%)
(if-not @id
; create
[{:data @%}]
; update
[{:db/id @id :data @%}]
)
(if @id
; delete
[[:db.fn/retractEntity @id]])))
the state is updating fine
i did (cell= (println state))
by the time it gets to the loop-tpl
it’s just something like this ([43 "asdf"] [65 "sdlkfj"] [71 "asdf"] [75 "asdf"] [76 "asdf"] [nil nil])
so, imagine i have that sequence, making some inputs
then i delete “asdf” one letter at a time from input 71
on the last :input
it will be an empty value for the input, so it will delete 71 from the db
the cursor will now be at the end of 75
does that make sense?
it’s keydown but after the value has updated
i could do something similar by putting a small timeout on keydown
like it's just moving the cursor to the end of the element that fired the input event in the first place
so in your input event callback you can do the transaction and then use with-timeout 0 to select the text
just trying to figure out how to do that now 😉
i think i might have to call it a night and try again tomorrow
(input
:input #(do (d/transact ...)
(with-timeout 0 (-> % .-target js/jQuery .select)))
...
now that i know that hoplon is actually rejigging the attributes
that works
i didn’t know about with-timeout
yeah but better than setTimeout
because you can more easily get to the variables in the current scope
_.delay = function(func, wait) {
var args = Array.prototype.slice.call(arguments, 2);
return setTimeout(function(){ return func.apply(null, args); }, wait);
};
that’s what you’d normally be doing >.<
http://stackoverflow.com/questions/1190642/how-can-i-pass-a-parameter-to-a-settimeout-callback
seriously +1 for clojure
they've spent like half of their professional careers working on the syntax for fat arrows
yeah, i need to figure out how to get clojure into existing projects
so i can use it in my day job 😉
javelin looks like the most obvious place to start
i’ve been lecturing my devs on one way data flow for years
although, i didn’t know that’s what it was called until recently 😛
and javelin looks like a good way to help everyone out with that
well, i’ve found another bug
but it’s 3am
thanks for helping, again
some of the subtleties of hoplon can be tricky
like when you see things that want to talk to each other and it's not straightforward to do it
that usually indicates the need for some higher level abstraction that can encompass those relationships
well in this case, it was the way the DOM manipulation was happening that threw me
i thought it was a new input but it was the same input
like with react type things you have to get down into lifecycle protocols from the beginning
the only reason i was even thinking of getting “next input” into the DOM was to try and workaround the issue i was having
but actually i just needed a better understanding of what was happening
could be worth triggering the events as part of hoplon
food for thought
if the input really was deleted and the cursor was moved to a new input (which is what looks like is happening)
i would expect a few events to trigger
well, i guess you’d have to observe what the browser does
it was confusing because what i did in hoplon was delete something in a collection
that was mapped to input
so i was thinking “i deleted this thing, so the input was deleted"
lol, this blog post for splint
because things can't really contain their own state, the state needs to come from outside
is a bit too close to home
i’m definitely going to show the guys at work this 😉
yeah, it sounds too much like one of my rants...
except that the JS example is about as far as i manage to get people to not where they’re coming from
yeah look, i still see people interleaving “reading DOM”, “doing calculations”, “updating DOM”, “binding event handlers” within functions that have meaningless names
c# generating js via spark which contains jquery tempaltes which are run by code in partials rendered by c# ...
yeah how can you make a meaningful name when you do't even really know what the meaning is of the thing you're doing?
the whole concept that there might be invisible dependencies getting created en-masse, and that might be really bad, is totally new to a lot of people
well the blog post pretty much points out why
JS, the language, totally encourages that
I've been doing Clojure for ~2 years, but your (and Alan's) work made me break from the previous experience only about half a year ago
the last company i was at, we did a lot of whitelabel work for other agencies
me too, i remember my first year of doing clojure i learned more abot computing than i had in the previous 10 years combined
so i’ve seen how a bunch of different companies do stuff
the crap JS is pretty ubiquitous
i’m still a cljs noob, but it’s scratching some itches that have been bothering me for a while
anyway, gotta cruise
so late >.<
yeah, um 3:40
i gotta stop the late night hoplon binges 😛
melbourne
definitely come to melbourne if you do
we have the worst weather but the best culture
hah, it’s just really random
we get all the seasons every day
and your toilets swirl counter clockwise instead of the correct northern hemisphere clockwise fashion
ah yes, i think the first settlers miscalibrated those, we never quite fixed that
ah yes, but it only works within the embassy 😉
well, if you like coffee, head to melbourne
if you like beaches, head to sydney
oooh, well go north
or anywhere in the middle
or adelaide, or tasmania...
actually, go anywhere in australia other than melbourne or sydney >.<
yeah me too, it looks amazing
thinking of heading there in a couple of years
hah, there’s that too
it’s a crazy beautiful place though
pssssh
compared to what?
not australia, obviously
like when they had the flooding a few years ago, the whole place was awash in poisonous snakes, crocodiles, and bull sharks
there’s not much down here that doesn’t want to kill you tbh
it’s not so bad in the cities, but my mum has a shotgun in the kitchen for snakes, lol
yeah, nah
we take the KISS approach, all snakes are poisonous
don’t think so?
anyway, i really gotta go
4am now
great convo btw
i enjoyed the bit about toilets and standing on heads
i wish i could make it smaller
i feel like i didn't get to the essential code explosion problem with callbacks
circled it but didn't nail it
yeah it's fun
also splint is in the blog if you ever wanna use it in a post
do a little bret victor action or whatever
Is there any support for the mutual recursion of defelem
s?
Also, last time I checked, hoplon didn’t support if
s for rendering. Has this changed? If it hasn’t, is loop-tpl
the only way to handle the termination of the recursion? So many questions!
‘cause right now, the workaround i’m using instead of if
is
(defelem node [{:keys [subtree]} _ ]
(let [child-node (cell= (if-let [cn (:child-node subtree)]
[cn]))]
(div
(loop-tpl :bindings [cn child-node]
(node :subtree cn))))