Fork me on GitHub
#hoplon
<
2017-07-19
>
cycle33711:07:08

how does one work with cells that have sequable elements ? like [{:name 1} {:name 2}]

cycle33711:07:45

i can't seem to be able to loop-tpl to show them in separate div

thedavidmeister12:07:10

(for-tpl [{:keys [name]} (j/cell= [{:name 1} {:name 2}])] (div name)) @avabinary

thedavidmeister12:07:13

does that work for you?

thedavidmeister12:07:15

(for-tpl [n (j/cell= [{:name 1} {:name 2}])] (div (j/cell= (:name n)))) or this?

cycle33712:07:09

let me check

cycle33712:07:15

no it's not working\

cycle33712:07:19

I mean your code works

cycle33712:07:31

but my cell comes from an upper element

cycle33712:07:07

I basically have a for-tpl nested in a case-tpl

cycle33712:07:13

code looks like this

cycle33712:07:54

(defc app-state {:modules {}
                           :choices {:top nil :bottom nil}}
                           :users-to-edit {})

(defn path-cell [c path]
  (cell= (get-in c path)
         (partial swap! c assoc-in path)))

(def all-users-cell (path-cell app-state [:users-to-edit]))

(case-tpl route
                 :users (div "users")
                 :edit-users (user-edit-view all-users-cell ))

cycle33712:07:40

somewhere along the code I do a request when a route is changed

cycle33712:07:37

(defn get-all-users []
  (ajax-request {:uri "/api/users/"
                 :method :get
                 :handler (fn [[ok response]]
                            (if ok (dosync
                                     (reset! all-users-cell response))
                              (.error js/console (str response))))
                 :format (json-request-format)
                 :response-format (json-response-format {:keywords? true})}))

cycle33712:07:55

and with secretary I defroute

(defroute "/edit-users" []
  (dosync
    (reset! route :edit-users)
    (reset! all-users-cell (get-all-users)))

cycle33712:07:58

and user-edit-view that's called in the case-tpl is imported from a different ns

(ns admin.edit-users)

(defelem user-edit-view [_ users]
   (for-tpl [n (cell= users)]
      (div (cell= (:user_id n)))))

cycle33713:07:08

and that's about it

cycle33713:07:11

should work no ?

cycle33713:07:45

I did the same for another defroute and it worked perfectly

cycle33713:07:07

I think this is due to nesting of for-tpl in case-tpl ?!

cycle33713:07:15

:thinking_face:

cycle33713:07:58

I checked (cell? all-users-cell)

cycle33713:07:23

#<Cell: {}>

cycle33713:07:27

just before I send it off to user-edit-view

cycle33713:07:54

and afterwards in admin.edit-users ns when I check the same thing on users

cycle33713:07:06

so it's not a cell anymore ??

flyboarder17:07:37

@avabinary con confirm PR #36 fixes all my issues 😜

flyboarder17:07:22

@avabinary it’s your all-users-cell is passed as children to your defelem you need to specify some attribute :my-users-cell

flyboarder17:07:26

or something

cycle33717:07:30

@flyboarder I previously passed it as an attribute and destructured in the receiving defelem

cycle33717:07:14

when I (cell= (pr x)) it would show up as [Object object] and when trying to loop-tpl or for-tpl it would Error on not implementing ISequable

flyboarder17:07:47

@avabinary that would be the correct process, the non iseq error is probably because something was expecting a list

flyboarder18:07:52

You probably want to wrap your destructured data within another cell

cycle33718:07:10

well ... I'm having this as a response

[{:name "Anna" :id 1}{:name "Costanza" :id 2}....]

cycle33718:07:52

so that's what my all-users-cell would look like if I log it to console

cycle33718:07:14

still, that should be for all intents and purposes a sequable cell right ?

cycle33718:07:21

also, I'm not sure I understand what you're proposing, you mean I should do a (defc received-users [])

cycle33718:07:48

globally in my admin.edit-users ns ?

cycle33718:07:18

and reset! it again with the destructured cell from user-edit-view element ?

cycle33718:07:02

I now have a cell received-users in the same ns as my user-edit-view

cycle33718:07:17

and i (reset! received-users all-users-cell) when I (cell= (pr received-users)) this is what I get #<Cell: #object[Pd [object Object]]>

cycle33718:07:22

when I (for-tpl [x received-users] (div (str x))) i get Error: [object Object] is not ISeqable

cycle33718:07:59

and just before sending it to user-edit-view I do a (cell= (pr edit-all-users))

dm318:07:45

all-users-cell is a Cell

dm318:07:00

so you need to (reset! received-users @all-users-cell)

dm318:07:42

it also shows that the contents of your all-users-cell is something called Pd

dm318:07:55

can you inspect in the browser’s debugging view?

cycle33718:07:19

@dm3 but when should I deref and when not ? because I have working code that does (reset! old-cell new-cell)

dm318:07:21

it seems to be some sort of a javascript object

dm318:07:35

well, you can make nested cells work

dm318:07:44

but you shouldn’t have the need to do that

cycle33718:07:44

yes I can inspect it it is unreadable though

cycle33718:07:03

@dm3 sorry to ask, to what are you referring to when you say I shouldn't do that ?

dm318:07:18

to having cells inside cells

cycle33718:07:55

Pd
function Pd() 

cycle33718:07:03

this is what console says

cycle33718:07:42

but I've run out of options and I thought that was what @flyboarder suggested

dm318:07:47

how do you get this Pd?

cycle33718:07:53

ajax-request

dm318:07:01

what is ajax-request?

cycle33718:07:03

please see code above

dm318:07:20

yeah, but what does ajax-request return?

cycle33718:07:55

(:require [ajax.core
             :refer [GET
                     POST
                     json-request-format
                     json-response-format
                     ajax-request]]
they're from https://github.com/JulianBirch/cljs-ajax/

dm318:07:56

I guess some sort of a deferred Javascript object

dm318:07:07

or a core.async channel if it’s a cljs lib

cycle33718:07:30

it has middleware to wrap response json into edn

dm318:07:44

so you need to convert a core.async channel into a cell first

dm318:07:49

not just put it inside a cell

cycle33718:07:57

but this works on a simple call

cycle33718:07:05

I can't explain it

dm318:07:12

what is a simple call?

cycle33718:07:37

say I get a response like this

{:name "Paula" :id 1}

dm318:07:07

the problem is that you never see the actual values inside the cell

dm318:07:12

you get the chan object

cycle33718:07:13

i just reset! a lens like in the above code (see the :handler part)

dm318:07:56

(defroute "/edit-users" []
  (async/go (dosync
    (reset! route :edit-users)
    (reset! all-users-cell (async/<! (get-all-users))))

cycle33718:07:08

then I can

(cell= (:name some-cell-reset!-like-that))
and it works

cycle33718:07:32

should I change the :handler for the get-users-cell as well or is it enough to change the defroute area ?

cycle33718:07:54

I have a reset! cell response there as well

flyboarder18:07:31

@avabinary you deref a cell when you want its value, otherwise you always use cells/formula cells

cycle33718:07:06

but when I have a lens

cycle33718:07:29

I can reset! it without deref-ing right ?

flyboarder18:07:14

Correct, however that doesn't guarantee anything is mutated, it's just attempts to do what the lense callback does, which "should" update something

flyboarder18:07:20

Usually an underlying cell to the lense

flyboarder18:07:34

Which would cause the lense to also update

flyboarder18:07:40

Also you can use anonymous cells within a defelem to see what happens as they update

cycle33718:07:22

ok, sounds about right

cycle33718:07:41

I'm slowly getting the hang of this, is what I mean

flyboarder18:07:02

Once you do, there will be no turning back!

cycle33718:07:35

true that ! after seeing how om does things ...

cycle33718:07:41

I wrapped everything in an async/go as @dm3 suggested (thank you)

cycle33718:07:44

and now it complains \

cycle33718:07:57

Error: <! used not in (go ...) block

cycle33718:07:43

I put [org.clojure/core.async "0.3.443"] in my build.boot :dependencies and then in my ns I required [cljs.core.async :as async]

cycle33718:07:08

something is off in the matrix tonight :))

cycle33718:07:36

I forgot to (:require-macros [cljs.core.async.macros :refer [go]])

flyboarder18:07:48

That error is very accurate, you are usin <! Outside of go

flyboarder18:07:58

There ya go!

cycle33719:07:43

still ... same thing 😞

flyboarder19:07:05

Is there a repo?

cycle33719:07:37

no, I am working offline but I could set it up on github

flyboarder20:07:47

@avabinary or post the problematic file