Fork me on GitHub
#re-frame
<
2016-02-25
>
kingoftheknoll00:02:46

Maybe an odd question but I really like the pattern for state management with re-frame however the CLJS prototype I’m using is more of a JS SDK to be consumed by other libraries (baby steps, boss still loves angular). There will eventually be a reagent component aspect but I’m currently only focused on the data layer. Would re-frame be useful or should I just copy the patterns?

danielcompton00:02:52

not quite clear what you’re doing with it. However keep in mind that currently re-frame only has one global context, so it might be a little difficult to use it as an SDK for other libraries. See https://github.com/Day8/re-frame/issues/137 and https://github.com/Day8/re-frame/pull/107 for more details

kingoftheknoll00:02:56

I’m writing a API helper library for inhouse apps. It’s possible for it to be stateless but there’s some really cool things I can do if I can cache and keep state on some of the data being pulled down or say register an event-handler and poll the api to update a list of callback functions. Stuff like that.

kingoftheknoll00:02:37

But what would be most cool would be being able to allow consumers of the library to register callbacks much like react components and when the db state changes call those functions as you would update components

mikethompson00:02:01

(I have no experience of it, I only know it exists)

kingoftheknoll00:02:23

We’ll I’m wanting to write this in cljs so I can have a path to coverting us completely over, by starting with a API and data layer abstraction.

kingoftheknoll00:02:57

I’d love to redo the whole UI in reagent but baby steps.

kingoftheknoll00:02:44

I’m looking through the re-frame source now and it’s not terribly complicated. I might be able to just borrow some of the patterns from there.

kingoftheknoll00:02:20

I’m also thinking of letting this helper library be compatable with Clojure or Node so I can get multiple target envs. So maybe re-frame would be bad either way.

mikethompson00:02:16

Yeah, there's not a lot to re-frame. A few hundred lines of code (a bit more if you include undo related stuff).

mikethompson00:02:02

But it does get to leverage both Reagent and React obviously, which is a pretty big leg-up.

kingoftheknoll00:02:00

totally and what I’ll probably do is circle back to using them if I can convince the rest of the team to do the view layer in cljs

richiardiandrea01:02:29

Hello guys, just something is bothering me a bit about async testing (it may be it will be very silly): I would like to perform the following test in re-frame (I know the code below is going to be wrong):

(deftest require-test
  (async done
      (dispatch [:evaluate-form "(require 'clojure.string)"])
      (let [res (subscribe [:get-console-answer])]
            (is (= @res val)) <- this is not blocking so I cannot wait for it to happen
            (done))))

richiardiandrea01:02:09

do I need to mock my handlers for this?

richiardiandrea01:02:40

ok I read all the Testing wiki, probably not straightforward this one

richiardiandrea01:02:55

it would be great to have something that transforms a reaction in a channel to wait on, ah wait, I have watches 😉

mikethompson01:02:58

So, it seems to me you need to test: 1. The event handler does the right thing. 2. That the subscription handler does the right thing So that's two simple tests, rather than one complicated one.

richiardiandrea01:02:30

@mikethompson: yes I agree with that I read that file 5 mins ago 😄

richiardiandrea01:02:35

my use case is for async interactions basically the handler does the right thing if given the right amount of time

richiardiandrea01:02:40

I know it's weird

richiardiandrea01:02:24

but it is basically calling sync to deal with it

jbaiter14:02:31

i'm having a really tricky problem with re-frame right now... I have a form with a file-input field. I trigger the upload of the file with an event. When the upload is finished, I would like to clear the input field (i.e. set its value attribute to the empty string).

jbaiter14:02:03

Usually I would do that by specifying the value prop on the input field and then set up a subscription to the application state

jbaiter14:02:00

but in this case it won't work, since I can programmatically only set the input's value to the empty string (seems to be a security thing)

danielcompton19:02:06

@jbaiter: is it a re-frame issue or a browser issue?

danielcompton19:02:19

happy to help either way, but just trying to be clear on the problem

dfcarpenter23:02:15

In the default re-frame template +secretary how would one pass a variable to a panel? I have a couple of top-level components and for two of them I would like to pass in a variable. Is there a better way/alternative way to do this?