This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
@thedavidmeister: because loop-tpl
only sees the first form in the body
each item in the bindings data must correspond to a single element that will be inserted and removed from the dom
but i can’t use something like comp
i have to wrap it?
vector works
awesome
not ideal to have the DOM need to fit the framework
(loop-tpl :bindings [n test-values]
[(input :value n) (br) (text "foo")]))
totally works
which is cool
i’m definitely learning in baby steps here >.<
(def test-values
(cell ["foo" "" "bar"]))
(defn remove-empty-values
[values]
(filter seq values))
(defn append-empty-value
[values]
(conj values ""))
(defn prepare-values
[values]
(append-empty-value
(remove-empty-values values)))
(swap! test-values prepare-values)
(print test-values)
(e/outer-dom
(loop-tpl :bindings [n test-values]
[(input :value n) (br)]))
that produces a DOM with an empty input first, then foo
and bar
in subsequent inputs
if i change “prepare values"
to just this
(defn prepare-values
[values]
(append-empty-value values))
which just doesn’t run filter
then i get the empty input last
which is what I want
so I’m a bit confused as to how filter
and conj
interact with a cell
wait...
filterv
@thedavidmeister: yeah, conj
insert values last when the collection is a vector and first when it's a list.
@mynomoto: thanks
@mynomoto: i do have another q though
i have this
(def state
(cell [
{:data "foo"}
{:data "bar"}]))
(loop-tpl :bindings [i state]
[(input
:value i
:type "text")])
the value for my input ends up being a string representation of those sets
how would I get the :data
from the state into the input as a value?
(loop-tpl :bindings [{data :data} state]
[(input
:value data
:type "text")])
that works
@thedavidmeister: Yeah, this last one is the way to do what you want. Are you new to clojure too or only to Hoplon?
it’s a little tricky to know what’s hoplon and what’s me just being a beginner
they really are
albeit, often not in my timezone 😉
ok, sooo
i’ve got a list of inputs and i can make a state vector
and all the sets in that state vector end up in the inputs
wondering how to go back the other way
so if i update an input in the DOM, have that value go back into the data in the state cell
assoc-in
looks like it might do the trick
@thedavidmeister: there is two ways I would use.
but i’d need to get the key lined up against the input somehow
Another would be something more like https://github.com/hoplon/demos/blob/master/counters/src/index.cljs.hl#L10 where you have local cells and can change them.
yeah, i was thinking about that
but later i’m going to want to export the state of all the inputs
or nest it or something
so the global state like what’s in the todo app example looked OK for that
it used update-in
but i don’t quite grok how to do the indexing yet
like, as a small example, i want to add a new, empty input to the list of inputs if all the current inputs have data in them
yeah i do, but “current state of my code” is basically what i posted
it’s all foos and bars and messing around atm
@mynomoto: eeeey that indexed thing did an index
thanks
i’m just reading over the todo app now
now that you pointed out the map-indexed i see it in the todo app as well
cooool
that probably would have taken me all of tomorrow lol
i was just printing % and @% in :change
to see what that does
So %
is the argument of the function when we use the #(...)
syntax for anonymous functions.
yeah i knew that much
yeah but the event has been changed somehow?
to be like, clojurified or somethign?
or is that just the way the event looks when you print
it?
oh, i just moved it from :change
to :keyup
that’s nice
It shouldn't change probably printing it cause the changes, try using (.log js/console ...)
to check if it is what you expect..
yeah that makes more sense
so deref
on a jquery event = a value of an input?
rightio
so that would work differently for different DOM elements i presume?
like, inner text for a div or somethign?
Not sure about div, but it works for text areas, selects, radio buttons if I'm not mistaken. The inputs
demo has some examples.
Also since you are learning clojure, not sure if you found this yet: http://jafingerhut.github.io/cheatsheet/grimoire/cheatsheet-tiptip-cdocs-summary.html
ok, so tomorrow i’m going to try to deconstruct all the things you did in my head
and figure out how to make the delete key shift the focus to the preceeding input if the input is empty
@mynomoto: are idx
and itm
idiomatic for “index” and “item”?
@thedavidmeister: not really, there is no real convention for those, I just copied from the example. I usually like full names more.
yeah me too
uses less brainpower when reading over it later
oh, except “index” is a function apparently
You can use it anyway, on clojurescript there is problems if you use window
as a variable name 😕
not surprising
yeah, i had something similar with trying to use loop-tpl
without a wrapper div
just spinning my wheels
so, why do we have to deref i in :keyup #(swap! state assoc-in [@i :data] @%)
As a rule of thumb you always deref when using a cell on a callback function. The reason is that on Hoplon the ui knows when cell changed to update themselves, but callback functions are just ordinary functions with no knowledge about cells. If they need the value that the cell contains you need to deref it.
oh, that sounds important
is that documented somewhere?
Not sure, we have been updating the wiki with docs but I don't know the current state.
the chat has been the most helpful source of info so far
but the references do help too
We had more docs on the old http://hoplon.io probably worth to dig it out and add to the wiki if it was not done yet.
so, i tried this to get the keyCode from the jQuery object
(prn (:keyCode %))
didn’t work
i just get nil
not to be confused with null, lol
so what does that do?
This is for interop with javascript. If you want to access a property you do (.-property_name obj)
so .-
is something hoplon specific?
why the -
?
To differentiate between properties and functions. You can have both with the same name on the same object on javascript.
makes sense
and is there a hoplon way to trigger events, like a focus
or would i have to run that through JS too?
sounds like something for tomorroe
*tomorrow
learned a heap today
thanks for that
I'm changing jobs at the moment, going to another startup try to spread clojure/hoplon to more places I also have been busy over the last weeks.
the latest changes will make it much easier to implement future improvements and add features without breaking anything
the defelem+ thing will require devising some solution to the javelin garbage collection problem
Yeah, documentation is important. I will try to help with that. Ask things doesn't scale well enough
I will try to move what we had on http://hoplon.io to the hoplon wiki. It was not much, but way more than we have now.
The advantage that those had was that I wrote part of it when I was learning. So I did all the drills. Needs some updating but not excessive I think.
yeah i think like people will come in and write a bunch of pages in the wiki while they're learning and find things that confused them
I was having castra troubles last week trying to update a project to 3.0.0. I will try to debug them, but the crazy thing is that it worked for some usernames and failed for others. Is there a easy way to debug session problems there?
Not sure, I stopped when I could reliable replicate the problem for one user but others would just work. Session would be nil on some cases
also are you sure that the server is sending the session to the client? you should see it in the response headers