Fork me on GitHub
#reagent
<
2016-05-27
>
mikethompson04:05:35

@mccraigmccraig @petrus even though that document is marked as "experimental"., that approach has been working pretty well for us. It certainly delivers a lot of flexibility.

mccraigmccraig07:05:09

@mikethompson: yeah, the fact that the queries share the sub's lifecycle seems to take away a lot of complexity... how do you do "loading" indicators though ?

mikethompson07:05:21

We make our query mechanism return (reactively) a triple of values:

{ :connected  true  
  :query-status  :waiting
  :query-result  []
}

mikethompson07:05:52

The first two just say "how are things going". The final one is the real result of the query (which is initially nil)

mccraigmccraig07:05:23

yep, gotit. i think i am converted

mikethompson07:05:24

Then the GUI sees the :waiting it has the option to put up a "Loading..."

mikethompson07:05:48

If ever the :connected (web-socket status ??) goes to false then we can show "Dear User, you are offline".

mccraigmccraig07:05:01

i've been doing loading indicators from app-db, but this is much better

mikethompson07:05:30

Just to be clear, this is kinda from app-db

mikethompson07:05:58

Further explanation: 1. The query mechanism has a query result callback 2. The value given to this callback is the triple described above 3. This callback dispatches this data to a handler which knows how to splice that data into app-db, including the :query-status which causes "Loading..."

mccraigmccraig07:05:24

(warning - it's early here and i am on zero coffees - i may not be thinking clearly 😫 )

mccraigmccraig07:05:57

ok - so the app-db entry will have the same schema as the map above, but the sub will alter the :connected and :query-status keys returned to reflect a query in-flight ?

mikethompson07:05:13

app-db is the local source of truth. But data is flowing into it (conceptually from the database).

mikethompson07:05:22

app-db is kinda like an intermediate node in a Signal graph which is rooted in the database.

mccraigmccraig07:05:49

dyu mean the back-end database there ?

mikethompson07:05:49

I have to head off to watch a VERY important game of football

mikethompson07:05:58

Sorry, yes, backend database

mccraigmccraig07:05:13

american or original type football ?

mccraigmccraig07:05:24

ah, much better

mccraigmccraig07:05:53

thanks for the explanation @mikethompson 😄

mikethompson07:05:12

np .. I;ll be interested to hear how you go

kauko11:05:39

This probably gets asked quite often, but does Reagent have server-side rendering? There's reagent.core/render-to-string, which sounds like it could be used for that

madstap11:05:32

I think Yogthos wrote a blogpost about that. Seems like it's quite simple using reader conditionals.

kauko11:05:57

I don't think he really got it to work though: "React is fairly picky about the structure and the data-reactid tags. So, it can be tricky to generate a DOM tree that it likes. The example in the post will give a React warning about the DOM being different. Some more work is needed around this."

kauko11:05:57

If he's talking about the warning I think he's talking about, it basically means that he lost out on some benefits of server-side rendering

luposlip11:05:47

It doesn’t work. Have tried smth like this: (defn ons-toolbar (r/adapt-react-class (. js/Ons -Toolbar))) There seem to be no react classes defined by react-onsenui. But there are elements such as js/OnsToolbarElement. Any input on how to use this to create a react class? Or other ways?

kauko11:05:12

Maybe I'll just have to give it a try myself. I'll honestly be quite surprised if it's terribly difficult to setup, seems quite straight forward. I believe the only thing you need is to have matching react-ids on your DOM elements

kauko11:05:32

And if it actually works, it will definitely have to be mentioned in the README. To many people server-side rendering of React was/is one of its main selling points

kauko11:05:41

Not really in the clojure world, but still 🙂

luposlip13:05:49

@pesterhazy: perhaps. If I define it like this: (def ons-toolbar (r/adapt-react-class (. js/Ons -Toolbar))), and use it like this in a hiccup form: [ons-toolbar], I get this in my console:

template.js:395 Uncaught Error: Assert failed: Invalid Hiccup form: [nil] (in app > view)
(valid-tag? tag)

luposlip13:05:15

Seems like there is no such thing as (. js/Ons -Toolbar)

pesterhazy13:05:21

check what -Toolbar is returning

pesterhazy13:05:27

it's probably nil

luposlip13:05:28

It returns nil

luposlip13:05:49

I can get js/OnsToolbarElement though

pesterhazy13:05:12

then look at its keys, (js/Object.keys js/OnsToolbarElement)

luposlip13:05:23

js/OnsToolbarElement -> #object[ons-toolbar "function ons-toolbar() { [native code] }”]

luposlip13:05:59

(js/OnsToolbarElement) -> #object[TypeError TypeError: DOM object constructor cannot be called as a function.]

luposlip13:05:54

So I’m thinking perhaps the js/OnsToolbarElement can somehow be wrapped with r/create-element or such. Just didn’t succeed when I tried.

savelichalex13:05:42

@luposlip: or maybe you need require components from lib. Just see how it do in js, and wrap in is adopt-react-class

luposlip13:05:10

perhaps you’re right @savelichalex. I’ve looked into this page: https://onsen.io/v2/docs/guide/react/ And I load .js files with the <script/> tags as described. But not with require(…). I do have an Ons object from within my console though, so thought everything had loaded alright.

luposlip13:05:29

In their example they basically use their react-elements like this:

var App = React.createClass({
      handleClick: function() {
        ons.notification.alert('Hello world!');
      },

      render: function() {
        return (
          <Ons.Page>
            <Ons.Button onClick={this.handleClick}>Tap me!</Ons.Button>
          </Ons.Page>
        );
      }
    });
    ReactDOM.render(<App />, document.getElementById('app'));

savelichalex13:05:05

Try to use (def Ons (js/require «<ons-library>»))

savelichalex13:05:17

Of course you can use script tag

savelichalex13:05:46

However you need to know variable to call Ons

savelichalex13:05:02

If library designed for this

luposlip13:05:07

Did (var Ons2 (goog.require 'react-onsenui’)), Ons2 is nil afterwards.

luposlip13:05:30

gotta go for a while, will come back later. Thanks for your efforts for now.

savelichalex13:05:53

I think that goog.require not work in this case, because this is for Google Closure namespaces. If you use library from npm use js/require

lwhorton13:05:23

heya guys, I’m wondering if anyone has thought through the most effective way to debounce something in reframe?

lwhorton13:05:03

i’m curious if its smarter to do it at the view level - prevent a message from dispatching entirely, or if its wiser to use some temp key in app-db to track the debounciness

lwhorton13:05:43

both sides present challenges, so i’m wondering if someone already solved this problem

mikethompson14:05:44

Without knowing too much about what you are doing, I think I'd debounce in an event handler. For example, when the dispatch is handled for this bursty event, look at a time stamp for the last value put into app-db (you have to add both a value and a timestamp), and if this timestamp, is less than some delta from now, just drop the new event on the floor. Or something.

mikethompson14:05:38

Ie. I'd debounce by stopping excessive writes into app-db, Rather than doing those writes and then trying somehow to stop the view from updating.

mikethompson14:05:19

Remember that rerenders only happen each annimation frame. So there is a natural debounce to 16ms.

rohit16:05:47

@lwhorton: have you had a look at debouncer function in google closure library: https://google.github.io/closure-library/api/namespace_goog_functions.html#debounce

jcromartie16:05:16

I seem to be doing something wrong. my :on-click handlers aren't firing, and I can't seem to type in any <input> boxes

gadfly36116:05:21

@jcromartie: can you show code snippet?

jcromartie16:05:53

I've updated the gist to remove some redundant stuff

jcromartie16:05:54

specifically, when I click into an input box, and type anything, the caret moves to the end and nothing changes

jcromartie16:05:12

hm, actually, the on-click is firing

jcromartie16:05:35

but the change to the atom doesn't change the rest of the app

jcromartie16:05:31

oh, I should read the warnings

jcromartie16:05:33

react.inc.js:19368Warning: Failed form propType: You provided a value prop to a form field without an onChange handler. This will render a read-only field. If the field should be mutable use defaultValue. Otherwise, set either onChange or readOnly. Check the render method of ReagentInput.

rohit16:05:05

@jcromartie: i think it needs to be :onClick and not :on-click

jcromartie16:05:21

it's :on-click according to the Reagent home page

rohit16:05:46

right. sorry about that

rohit16:05:12

also are selected-app and selected-profile meant to be clojurescript atoms and not reagent atoms?

jcromartie16:05:14

I should set up my ns to replace atom with reagent atom

gadfly36116:05:20

@jcromartie: unfortunately, not able to help. A few things to note - getting warning from the use of for without supplying a ^{:key <id>}, and your input fields do not have on-change event handlers. Seems like are you wanting to be able to edit the key itself, such as foo which will make tracking its value, which starts off as bar a little tricky unless you make a copy. Id recommend starting off smaller, and particularly consolidating your reagent atoms into one. I find it makes reasoning about app-state a bit easier.

jcromartie17:05:43

yeah I think having one app state atom would be better

jcromartie17:05:17

and as for the key renaming bit... yeah I agree, maybe I'll convert it to a vector of name value pairs so they maintain order

jcromartie17:05:23

then I can give them ids with the index

jcromartie17:05:31

and I can update the app state based on the index

jcromartie17:05:58

I'm getting the hang of it.

jcromartie17:05:05

I'm NEVER. GOING. BACKKKKKKKKKKKK

luposlip17:05:38

@savelichalex: I don't have js/require?

luposlip18:05:13

js/require return nil. Not a function or object (sorry for the missing markup, writing from my phone)

savelichalex20:05:37

@luposlip: this is looks strange to me) guess you have wrong name of package in js/require

luposlip20:05:40

No, the vanilla js/require is undefined 😉 if I write js/Ons it returns something.