Fork me on GitHub
#rum
<
2016-09-19
>
martinklepsch14:09:47

The way the debounced function is called is, ahem... a little bit interesting... but that wouldn't be hard to fix I guess

misha16:09:51

@martinklepsch wouldn't it be more appropriate to use goog.functions.throttle in this case of search?

If it is called multiple times while it is waiting, it will only perform the action once at the end of the interval, passing the arguments from the last call of the throttling decorator into the decorated function.

misha16:09:58

typing

a
aa
aaa
aaaa
would generate 2 fn calls (assuming everything is typed within single throttle interval):
(f "a")
(f "aaaa")

misha16:09:41

From the docstring I'm not even sure which calls would debounce generate

misha16:09:36

wait, no. throttle would generate just (f "aaaa"), right? what would debounce generate, assuming timeout expires after aaaa input?

misha16:09:38

@martinklepsch what are the benefits of mixin over just globally defined debounced function?

martinklepsch17:09:15

misha so in a search input I want to "submit" the last value the user entered after a certain period of inactivity

martinklepsch17:09:46

I do not want to recompute the result at most once every 300ms

martinklepsch17:09:02

at least that's my understanding of throttle vs. debounce @misha

martinklepsch17:09:34

and regarding mixin. The benefit is no global. E.g. what would I do if I have 20 debounced fns? would the all need to be globals?

honzabrecka19:09:43

Hi, does anyone know how to use “decorator” - a high order component with rum? I’m trying to rewrite this https://github.com/danielstocks/react-sortable/blob/master/example/index.js

martinklepsch19:09:12

honzabrecka you can pass components to other components as argument

martinklepsch19:09:47

@honzabrecka the only difference is that in react there's a special children prop whereas in rum there is not

honzabrecka19:09:30

It’s not possible to use (js/decorator rum-component), because rum/defc doesn’t return react class, but some Symbol.

misha19:09:54

@martinklepsch re debounce: makes sense. re global debounced fns: I found, that having too fat components slows me down, and I decided to keep those as stateless as possible, to be able to clearly separate representation from any logic. This led to "global" debounced functions in my case (those are namespaced anyway, so it's not a tragedy). I still have to find good balance though, because implicitly depending on "global" functions is meh, and passing every single symbol as argument to component is suboptimal too.

honzabrecka19:09:19

Decorator is a React class with render() { return React.createElement(Component); } under the hood, therefore it fails.

martinklepsch19:09:47

honzabrecka so defc defines a component constructor

martinklepsch19:09:18

and calling that constructor as a function will actually return the component class

martinklepsch19:09:30

eg (rum-component) vs rum-component

honzabrecka19:09:07

react-with-addons.inc.js:22480 Uncaught Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object. Check the render method of Constructor`.`

martinklepsch19:09:56

@honzabrecka an example and an issue on Github would probably go a long way

honzabrecka19:09:53

The only way it works is (:rum/class (meta rum-component)), but props doesn’t work.

martinklepsch19:09:58

> and calling that constructor as a function will actually return the component class thats actually wrong, it will return the instantiated component class, that is an object

martinklepsch19:09:08

so maybe that rum/class thing is the way to go