This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-02-26
Channels
- # aws-lambda (2)
- # beginners (10)
- # boot (17)
- # cider (19)
- # clara (1)
- # cljs-dev (13)
- # cljsjs (22)
- # cljsrn (1)
- # clojure (132)
- # clojure-austin (2)
- # clojure-berlin (2)
- # clojure-dusseldorf (1)
- # clojure-germany (2)
- # clojure-italy (7)
- # clojure-spec (6)
- # clojure-uk (5)
- # clojurescript (45)
- # core-matrix (3)
- # cursive (4)
- # datomic (8)
- # emacs (3)
- # keechma (3)
- # lein-figwheel (1)
- # leiningen (2)
- # lumo (24)
- # nyc (1)
- # off-topic (29)
- # om (68)
- # onyx (5)
- # perun (50)
- # planck (5)
- # protorepl (5)
- # re-frame (128)
- # reagent (10)
- # remote-jobs (1)
- # ring (4)
- # rum (41)
- # untangled (28)
- # yada (4)
Hello. Let's say we a text editor - tabs for files on the top and file tree to the left. In app-db i have something like this
{:files {} ; stores some file meta
:sidebar {:file-ids {}}
:tabs {:file-ids {}}
Now when i delete a file (e.g. in handler :files/delete
) i must also delete this file from sidebar and tabs. What would be a good way to do it? Explicitly send events like :sidebar/file-deleted
and :tabs/file-deleted
(looks not good because :files/delete
must know about every place which is interested in file) or maybe i can set some kind of event which will be triggered when file is deleted?@nidu, I think sidebars and tabs ideally should be derived from files, i.e. there should be a single place for each piece of information
@pesterhazy Sidebar and tabs have specific order and display only open files so i'm not sure how to remove app-db
one way would be to add a :sidebar/position
attribute to files
not saying this is the best way to do it, but I'd think about ways to normalize your data model
remember it's all in memory so unlike a durable db, scanning through all elements is lightning fast
@pesterhazy interesting approach! However now i have to rebuild :sidebar/position
and :tabs/position
upon deletion quite the same way ๐
how so? you just sort by sidebar/position and don't care about gaps
of course adding a file is more complicated that way
I guess my point is you should avoid coordinated changes and instead use reactions/track/subscriptions
@pesterhazy yeah, the problem in this case moves to file addition
well not if you always add to the beginning or end
yeah, deriving as much as possible is good. However here i'd like to change state of one module when data changes and i'm not sure how to do it with reactions. Would be nice to change app-db in response to some reaction change
otherwise you can re-number the elements
@pesterhazy unfortunately that's not the case
I'm not a re-frame expert, but I'm not sure state changes should trigger other state changes
it'd be better to have a single event that updates both sidebar
and files
at the same time
like an even add-file
, delete-file
etc.
that way you can be sure that there are never orphan files in sidebar...
personally I wouldn't worry too much about coupling
it's better than a sort of a pinball event system
real newbie question here but im trying to handle an event and cause it to fire another event, heres my code
(re-frame/reg-event-fx
:login-success
(fn [cofx]
(console.log "login success called")
(assoc cofx :active-page :create-game)
))
(re-frame/reg-event-db
:login
(fn [cofx [_ data]]
(console.log " login event handled")
(assoc cofx :db (assoc (:db cofx) :name data) :dispatch [:login-success] )
))
login even it handled , however login success is never handled, can anyone suggest how i should go about diagnosing?
anyone knows why it would be better to use :g rather than :div?
Hi friends, trying to figure out the best way to structure this in re-frame: I have a page where I need to load some data, read it, and potentially redirect
Doing that in an (if) clause in the render method seems sketch, though in theory would work. What might be better, though?
@bpicolo I don't understand the use case
@pesterhazy Say a new user hits some page. I want to load their user details, and if they haven't filled them out yet, redirect them to the page where they fill out user details
redirect as in a server side HTTP redirect?
More-specifically https://github.com/venantius/accountant because it's a dope secretary wrapper ๐
yeah you shouldn't trigger events in the render methods
I guess I could add a data loading callback to the HTTP GET, but that's kinda of a sketchy workaround of re-frame data flow
so you have a page /private
which is only accessible if the user has filled in her details?
can't you show the details screen instead /private on /private if it's not accessible?
in which way?
the other option would be to make the decision upon navigation
It's a bit more to maintain to have a page that can show up potentially inside another
true but you can still have a check there
(if user-complete? [content] [:div "Please fill in your details first"])
Might be the best choice, but it seems kind of crazy that check-data-redirect wouldn't be a supported flow right?
what I've learned over the last year is that normally components shouldn't make those decisions
usually the place where you want this to happen in navigation
I mean I could register an extremely specific handler function, that's not generally applicable for any other page
but I've also run into flows that are similarly problematic
That's the one problem I've hit with newfangled SPA frameworks, there's some extreme trivialities that they make super hard : (
well SPAs are intrinsically harder than old school web appps
because you have to re-implement browser functionality
(error handling, navigation, ....)
That difficulty is purely a side-effect of the one-way-data-flow with a global state atom
don't know about that
it seems more of a limitation of React's components and re-frame's event model
there's probably a nice pattern there
ok so something I usually do is to add an event that gets triggered when a screen gets focus
i.e. when the user navigates somewhere
you could use that to trigger a nav event
you could lose the ability to play back the event history
not sure how often people actually do that though
but losing that ability seems like it could defeat the purpose of re-frame
@pesterhazy I think for now I'll drop it right in the same view
feels like there's a pattern there to be discovered
"landing-page + redirect"
one thing I'm not thrilled with is that some pages I have to wait for 3 things to load before displaying the page makes sense
so I wait for 3 ratoms, but that means any ratom changing has to rerender the whole page
@pesterhazy > it's better than a sort of a pinball event system Agree, moreover making it explicit probably makes the system more transparent
im getting http://localhost:3449/favicon.ico 404 (Not Found)`` which folder is favicon.ico supposed to live?
that's a server side issue (also you can safely ignore it)
@gregnwosu you'll need a route to /favicon.ico that serves the static asset for that
@gregnwosu Oh no clue, I'm not using clojure on the backend
in which case you'll want this in your <head> : <link rel="shortcut icon" href="/wherever/favicon.ico" />
@gregnwosu Python. I'm just much more productive in it
if I want to do some simple validation on some inputs
the easiest way is just to use a class
and then CSS to style differently
or better some other way?