helix

https://github.com/Lokeh/helix
Luis C. Arbildo 2020-02-27T16:20:39.041Z

why is undefined?

Luis C. Arbildo 2020-02-27T16:29:35.042500Z

why when scientist is passed through openData apparently isn't the same object?

Luis C. Arbildo 2020-02-27T16:47:32.043300Z

:face_palm: my bad, I have used defnc instead defn

lilactown 2020-02-27T16:50:48.044500Z

aha, I didn’t notice that either 😂 I was going down a rabbit hole thinking it was something to do with lazy evaluation and side effects

Luis C. Arbildo 2020-02-27T16:51:10.045200Z

lol

lilactown 2020-02-27T16:52:27.046700Z

FYI It might be a little more readable to use for here:

(for [[index scientist] (map-indexed vector scientists)]
  ($ Overly ,,,))

lilactown 2020-02-27T16:53:06.047600Z

eh I guess it’s not that much more readable than what you have

Luis C. Arbildo 2020-02-27T16:53:45.047800Z

interesting!

Luis C. Arbildo 2020-02-27T16:56:48.048400Z

work in the same way, But what is vector?

Luis C. Arbildo 2020-02-27T16:57:37.049700Z

me a little before

😂 2
lilactown 2020-02-27T16:58:07.050700Z

vector creates a vector from it’s arguments. so doing (map-indexed vector scientists) will produce a seq that looks like: ([0 {,,,}] [1 {,,,}])

Luis C. Arbildo 2020-02-27T16:58:34.051100Z

oh very nice!

Luis C. Arbildo 2020-02-27T16:58:44.051300Z

thank you, I'm learning a lot

lilactown 2020-02-27T16:58:51.051500Z

sure thing

Luis C. Arbildo 2020-02-27T18:05:41.052400Z

@lilactown, how can I made destructuring like ...props or style={...props.style}?

lilactown 2020-02-27T18:08:09.054500Z

you should be able to do

(d/div {:style (:style props)})
or if you want to spread all the props to a component, you can do:
(d/div {& props})

Luis C. Arbildo 2020-02-27T18:08:35.055200Z

oh, I understand

Luis C. Arbildo 2020-02-27T18:09:05.055700Z

Very nice

Luis C. Arbildo 2020-02-27T18:18:05.056800Z

and if I want replace some keys of props like style={...props.style, height: 10}

Luis C. Arbildo 2020-02-27T18:19:29.057900Z

and how I can extended this {& props} like {& props :style {:height 10}}

Luis C. Arbildo 2020-02-27T18:21:02.058Z

I thought something like that but don't work

lilactown 2020-02-27T18:21:53.058700Z

hmm, what doesn’t work? is there an error?

Luis C. Arbildo 2020-02-27T18:22:50.058800Z

Luis C. Arbildo 2020-02-27T18:23:50.059100Z

Luis C. Arbildo 2020-02-27T18:25:49.059400Z

I want to do something like style={...props.style, height: 10}

Luis C. Arbildo 2020-02-27T18:26:27.059600Z

and <div ...props style={height: 20}

Luis C. Arbildo 2020-02-27T18:27:55.059800Z

if I do

Luis C. Arbildo 2020-02-27T18:28:30.060200Z

this error throw

lilactown 2020-02-27T18:28:46.060600Z

yes, the one you posted in the channel looks good

lilactown 2020-02-27T18:29:02.060800Z

(merge (:style props) {:height 42 ,,,})

lilactown 2020-02-27T18:29:19.061Z

I’m not sure what the compilation error is, it looks like it might be something else

Luis C. Arbildo 2020-02-27T18:32:53.061200Z

Is strange cuz the error is in other function

Luis C. Arbildo 2020-02-27T18:37:51.061500Z

If I move the function over

jaime 2020-02-27T18:40:29.063400Z

How to translate this react version into helix?

React Version:
<DayPickerInput component={props => <input {...props} />} /> ;; using native component "input"
<DayPickerInput component={props => <MyCustomInput {...props} />} /> ;; using custom component "MyCustomInput"

Luis C. Arbildo 2020-02-27T18:42:02.064500Z

($ DayPickerInput {:component #(YourInputComponent %)})

(defnc YourInputComponent [{:keys [props]}] ...)

jaime 2020-02-27T18:43:52.065500Z

oh! The $ is not needed here? #($ YourInputComponent %)

lilactown 2020-02-27T18:44:43.066400Z

you should use $, it is needed

lilactown 2020-02-27T18:44:56.066600Z

otherwise it’s correct

lilactown 2020-02-27T18:46:20.067100Z

what version of helix are you using?

Luis C. Arbildo 2020-02-27T18:46:28.067400Z

let me check

jaime 2020-02-27T18:47:15.068Z

we need to destructure the params to get the props?

(defnc YourInputComponent [{:keys [props]}] ...)

And not like?

(defnc YourInputComponent [props] ...)

Luis C. Arbildo 2020-02-27T18:47:19.068100Z

{:paths ["src"]
 :deps {lilactown/helix {:git/url "<https://github.com/Lokeh/helix.git>"
                         :sha "376a68da794c6051f6fe103a79fec7314df67eb7"}
        ;; {:local/root "../helix"}
        binaryage/devtools {:mvn/version "0.9.7"}
        thheller/shadow-cljs {:mvn/version "2.8.74"}}}

Luis C. Arbildo 2020-02-27T18:47:23.068300Z

I think the last?

Luis C. Arbildo 2020-02-27T18:47:39.068500Z

I fork the todo app example

lilactown 2020-02-27T18:48:19.069Z

oops, no, it does not require desctructuring

Luis C. Arbildo 2020-02-27T18:49:15.070Z

😅

😁 1
jaime 2020-02-27T18:49:23.070400Z

This does not seem to work?

(defnc date-picker-input [props]
  (js/console.log props)
  (d/input {:class "mb-2 p-2 border border-gray-400 w-full" &amp; props}))

(defnc date-picker [{:keys [id]}]
  (let [date-format "MM-dd-yyyy"]
    ($ DayPickerInput
       {:id id
        :component #($ date-picker-input %)
        :format date-format
        :format-date #(format %1 %2 #js {:locale %3})
        :parse-date #(parse %1 %2 (js/Date.) #js {:locale %3})
        :placeholder (format (js/Date.) date-format)})))

lilactown 2020-02-27T18:49:38.070600Z

(defnc your-input-component
  [props]
  ,,,)

($ DayPickerInput {:component #($ your-input-component {&amp; %})})

Luis C. Arbildo 2020-02-27T18:50:13.071200Z

{&amp; %}
^ oka my brain hurts

lilactown 2020-02-27T18:50:17.071400Z

haha

lilactown 2020-02-27T18:50:33.071600Z

this document explains it: https://github.com/Lokeh/helix/blob/master/docs/creating-elements.md#dynamic-props

❤️ 2
lilactown 2020-02-27T18:50:56.072Z

ah no that is old

Luis C. Arbildo 2020-02-27T18:51:04.072200Z

oh ...

lilactown 2020-02-27T18:51:13.072500Z

use the latest release, {:mvn/version "0.9.0"}

Luis C. Arbildo 2020-02-27T18:52:41.072700Z

updating ...

Luis C. Arbildo 2020-02-27T18:53:01.072900Z

and it todo should be updated

Luis C. Arbildo 2020-02-27T18:55:12.073100Z

Luis C. Arbildo 2020-02-27T18:55:26.073500Z

Luis C. Arbildo 2020-02-27T18:55:37.073900Z

II don't know how update the version

Luis C. Arbildo 2020-02-27T18:55:47.074100Z

😭

lilactown 2020-02-27T18:56:18.074300Z

gah I just can’t type

lilactown 2020-02-27T18:56:32.074500Z

0.0.9

lilactown 2020-02-27T18:56:34.074700Z

https://github.com/Lokeh/helix#installation

lilactown 2020-02-27T18:56:55.075Z

the README has the latest version, if you click on the badge it will take you to a page with the latest version

jaime 2020-02-27T19:02:45.075200Z

@lilactown Is the above code applicable if DayPickerInput is imported from a npm library?

lilactown 2020-02-27T19:13:43.075500Z

yes

jaime 2020-02-27T19:20:43.075700Z

ok cool! 🙂

jaime 2020-02-27T19:40:07.078900Z

Hello. Anyone have idea about this error? I'm trying to use react-day-picker react library. I want to customize the input component (library docs https://react-day-picker.js.org/api/DayPickerInput#component) But I'm getting this issue when having this code.

(ns limeray.web.components
  (:require
   [helix.core :refer [defnc $ factory]]
   [helix.dom :as d]
   [helix.hooks :as hooks]
   ["react-day-picker/DayPickerInput" :default DayPickerInput]
   ["date-fns" :refer [parse format]]))

(defnc date-picker-input [props]
  (js/console.log "props " props)
  (d/input {:class "mb-2 p-2 border border-gray-400 w-full" &amp; props}))

(defnc date-picker [{:keys [id]}]
  (let [date-format "MM-dd-yyyy"]
    ($ DayPickerInput
       {:id id
        :component #($ date-picker-input %)
        :format date-format
        :format-date #(format %1 %2 #js {:locale %3})
        :parse-date #(parse %1 %2 (js/Date.) #js {:locale %3})
        :placeholder (format (js/Date.) date-format)})))
inside date-picker-input component. console.log props outputs
{
   "meta": null,
   "obj": {
      "children": {
         "placeholder": "02-27-2020",
         "value": ""
      }
   },
   "recursive_QMARK_": false,
   "__arr": [
      "children"
   ],
   "__cnt": null,
   "__hash": null,
   "cljs$lang$protocol_mask$partition0$": 2164131599,
   "cljs$lang$protocol_mask$partition1$": 139268
}
And getting this error
//cljs-runtime/module$node_modules$react_dom$cjs$react_dom_development.js:188 Uncaught Error: Objects are not valid as a React child (found: object with keys {placeholder, value, onChange, onFocus, onBlur, onKeyDown, onKeyUp, onClick}). If you meant to render a collection of children, use an array instead.
    in input (created by limeray.web.components/date-picker-input)
    in limeray.web.components/date-picker-input (created by component)
    in component (created by DayPickerInput)
    in div (created by DayPickerInput)
    in DayPickerInput (created by limeray.web.components/date-picker)
    in limeray.web.components/date-picker (created by limeray.web.routes/add-goal-view)
    in div (created by limeray.web.components/field)
    in limeray.web.components/field (created by limeray.web.routes/add-goal-view)
    in form (created by limeray.web.routes/add-goal-view)
    in div (created by limeray.web.routes/add-goal-view)
    in limeray.web.routes/add-goal-view (created by <http://limeray.web.app/root|limeray.web.app/root>)
    in div (created by <http://limeray.web.app/root|limeray.web.app/root>)
    in div (created by <http://limeray.web.app/root|limeray.web.app/root>)
    in <http://limeray.web.app/root|limeray.web.app/root>
    at throwOnInvalidObjectType (//cljs-runtime/module$node_modules$react_dom$cjs$react_dom_development.js:188)
    at eval (//cljs-runtime/module$node_modules$react_dom$cjs$react_dom_development.js:219)
    at reconcileChildren (//cljs-runtime/module$node_modules$react_dom$cjs$react_dom_development.js:266)
    at beginWork$1 (//cljs-runtime/module$node_modules$react_dom$cjs$react_dom_development.js:340)
    at HTMLUnknownElement.callCallback (//cljs-runtime/module$node_modules$react_dom$cjs$react_dom_development.js:559)
    at Object.invokeGuardedCallbackImpl (//cljs-runtime/module$node_modules$react_dom$cjs$react_dom_development.js:560)
    at invokeGuardedCallback (//cljs-runtime/module$node_modules$react_dom$cjs$react_dom_development.js:5)
    at beginWork$$1 (//cljs-runtime/module$node_modules$react_dom$cjs$react_dom_development.js:772)
    at performUnitOfWork (//cljs-runtime/module$node_modules$react_dom$cjs$react_dom_development.js:467)
    at workLoopSync (//cljs-runtime/module$node_modules$react_dom$cjs$react_dom_development.js:467)

jaime 2020-02-27T19:41:03.079400Z

Error looks straightforward. But I have no idea 😅

jaime 2020-02-27T19:49:07.079700Z

adding the screenshot of console. just in case it might help

Luis C. Arbildo 2020-02-27T20:02:20.080100Z

@lilactown nice!, work with the last version

lilactown 2020-02-27T21:42:25.080600Z

@jaime.sangcap you’re passing in the props for date-picker-input as a child

lilactown 2020-02-27T21:42:46.081Z

you need to use spread props, so that helix’s $ macro will respect it as a dynamic props map

lilactown 2020-02-27T21:43:05.081400Z

:component #($ date-picker-input {&amp; %})

lilactown 2020-02-27T21:44:56.082400Z

notice in the console.log, you’re essentially getting {:children #js {:placeholder …}}

jaime 2020-02-27T21:48:51.083200Z

I'm getting this error when doing :component #($ date-picker-input {&amp; %})

//cljs-runtime/helix.impl.props.js:189 Uncaught TypeError: m.call is not a function
    at eval (//cljs-runtime/helix.impl.props.js:189)
    at Function.eval [as cljs$core$IFn$_invoke$arity$1] (//cljs-runtime/helix.impl.props.js:190)
    at component (//cljs-runtime/limeray.web.components.js:115)
    at renderWithHooks (//cljs-runtime/module$node_modules$react_dom$cjs$react_dom_development.js:230)
    at beginWork$1 (//cljs-runtime/module$node_modules$react_dom$cjs$react_dom_development.js:327)
    at HTMLUnknownElement.callCallback (//cljs-runtime/module$node_modules$react_dom$cjs$react_dom_development.js:559)
    at Object.invokeGuardedCallbackImpl (//cljs-runtime/module$node_modules$react_dom$cjs$react_dom_development.js:560)
    at invokeGuardedCallback (//cljs-runtime/module$node_modules$react_dom$cjs$react_dom_development.js:5)
    at beginWork$$1 (//cljs-runtime/module$node_modules$react_dom$cjs$react_dom_development.js:772)
    at performUnitOfWork (//cljs-runtime/module$node_modules$react_dom$cjs$react_dom_development.js:467)


//cljs-runtime/module$node_modules$react_dom$cjs$react_dom_development.js:398 The above error occurred in the &lt;component&gt; component:
    in component (created by DayPickerInput)
    in div (created by DayPickerInput)
    in DayPickerInput (created by limeray.web.components/date-picker)
    in limeray.web.components/date-picker (created by limeray.web.routes/add-goal-view)
    in div (created by limeray.web.components/field)
    in limeray.web.components/field (created by limeray.web.routes/add-goal-view)
    in form (created by limeray.web.routes/add-goal-view)
    in div (created by limeray.web.routes/add-goal-view)
    in limeray.web.routes/add-goal-view (created by <http://limeray.web.app/root|limeray.web.app/root>)
    in div (created by <http://limeray.web.app/root|limeray.web.app/root>)
    in div (created by <http://limeray.web.app/root|limeray.web.app/root>)
    in <http://limeray.web.app/root|limeray.web.app/root>

Consider adding an error boundary to your tree to customize error handling behavior.
Visit <https://fb.me/react-error-boundaries> to learn more about error boundaries.

lilactown 2020-02-27T21:54:01.083400Z

ah

lilactown 2020-02-27T21:54:11.083700Z

props is a JS object that gets passed back, yes?

lilactown 2020-02-27T21:55:17.084500Z

you’ll need to convert it to an associative object like a map. cljs-bean can do this very efficiently

lilactown 2020-02-27T21:56:02.085300Z

in your requires, add [cljs-bean.core :as b] then :component #($ date-picker-input {&amp; (b/bean %)})

Luis C. Arbildo 2020-02-27T21:58:45.085400Z

it isn't equivalent to this 😕 @lilactown any suggestion?

lilactown 2020-02-27T21:59:29.086100Z

@luis.cairampoma119 the syntax is wrong

Luis C. Arbildo 2020-02-27T21:59:35.086400Z

oh

Luis C. Arbildo 2020-02-27T21:59:39.086700Z

where 😧

lilactown 2020-02-27T22:00:04.087200Z

$ and the helix.dom divs expect props to usually be written literally {:foo "bar" :baz 42}

lilactown 2020-02-27T22:00:21.087700Z

all props need to be passed into the one map

lilactown 2020-02-27T22:00:48.088300Z

similar to how in JSX, props always appear in the element &lt;div foo="bar" baz={42}&gt;

Luis C. Arbildo 2020-02-27T22:01:01.088500Z

I don't using $

lilactown 2020-02-27T22:01:15.088900Z

it’it’s the same with helix.dom

lilactown 2020-02-27T22:01:49.089600Z

what you pasted above is the equivalent of doing:

&lt;div {...props}&gt;
 {{style: merge(props.style, { ... })}}
&lt;/div&gt;

🙈 1
lilactown 2020-02-27T22:01:56.089900Z

you see why it won’t work?

Luis C. Arbildo 2020-02-27T22:02:34.090300Z

:face_palm: my bad

🙂 1
jaime 2020-02-27T22:04:01.090500Z

it worked! 🙂 thanks a lot for your patience 😆 I think I missed the options keywordize-keys on js-&gt;cljwhen I tried it. THats why it did not worked.

:component #($ date-picker-input {&amp; (js-&gt;clj % :keywordize-keys true)})

lilactown 2020-02-27T22:04:15.090800Z

aha!

lilactown 2020-02-27T22:04:19.091Z

yay! glad it’s working now

jaime 2020-02-27T22:05:14.091200Z

I will check cljs-bean next. Thanks a lot for your time

lilactown 2020-02-27T22:05:51.091400Z

you’re welcome. cljs-bean can often be faster if the structure you are converting is very large. not a huge different it looks like in this case

jaime 2020-02-27T22:08:28.091600Z

cool! helix is awesome, I feel like I had enough knowledge within 2days. I can apply my react skills already. Just to be more cautious about interops 😆

jaime 2020-02-27T22:09:09.091800Z

Do you have suggestion about the error messaeg? Right now I don't see the actual code thats causing the error

jaime 2020-02-27T22:09:35.092Z

Is there something like source maps?

lilactown 2020-02-27T22:10:08.092200Z

you can turn on source maps. if you’re using shadow-cljs you can check out their user guide for how to do that

❤️ 1
lilactown 2020-02-27T22:10:18.092400Z

https://shadow-cljs.github.io/docs/UsersGuide.html

jaime 2020-02-27T22:11:31.092700Z

oh, I'm using shadow-cljs, AFAIK source map is enabled by default. I need to double check my setup

Luis C. Arbildo 2020-02-27T22:27:31.093600Z

@lilactown Please, Can you do a code-review of my code? https://github.com/f1729/map-science/blob/master/src/map_science/core.cljs I would appreciate any suggestions

lilactown 2020-02-27T22:55:14.094100Z

oof, the React range library involves a lot of JS interop

Luis C. Arbildo 2020-02-27T23:01:14.094200Z

@lilactown which would be the correct equivalent?