lilactown / helix

A simple, easy to use library for React development in ClojureScript.
Eclipse Public License 2.0
627 stars 52 forks source link

$ error when used with native components #61

Closed wilkerlucio closed 4 years ago

wilkerlucio commented 4 years ago

Hello,

I found a bug in the $ with native components.

Reproduce example:

($ "div" {:style #js {:flex 1}})

This gets an error of Error: [object Object] is not ISeqable

I did a little dig, the problem seems to be in this line here: https://github.com/Lokeh/helix/blob/37aca5e65704da96915a4435e6825da4e4de3af7/src/helix/impl/props.cljc#L57

At my example, this ends up calling seq with a JS object, which triggers the error.

wilkerlucio commented 4 years ago

Ok, I just figured that on native components we can't send :style as js-obj.

This leads to a confusing situation in React Native, because some of the components there are native (string-based) and others are not (for example, View is a native component, but Button is not), and then figuring when one style should be used over the other gets confusing.

Maybe Helix could always accept the #js version as well, so the client could wrap those consistently?

wilkerlucio commented 4 years ago

Another option could be some validation at dev mode to let the user know that it was supposed to use a clojure or a js map in each case.

alidcast commented 4 years ago

it can maybe check (or (sequential? x) (map? x)) instead, those operations don't seem to throw errors for js objects

tekacs commented 4 years ago

As it stands I end up having to do {:style (bean style) somewhat often, when a style is passed to me either from a library or the result of Helix's own conversion.

lilactown commented 4 years ago

Thanks for reporting. @tekacs your use case is very motivating. I'll release 0.0.12 with a fix soon!