Fork me on GitHub
#om
<
2017-10-02
>
timovanderkamp16:10:49

Ran into the same issues @wilkerlucio still haven’t found the way to do it correctly

wilkerlucio16:10:39

@timovanderkamp if you figure out, please let me know... the only "solution" now is putting keys on everyone, but it's very annoying

wilkerlucio16:10:03

and there are solutions around it, since re-frame custom components don't need that

timovanderkamp16:10:48

Ive tried to pass a keyfn that either takes the given key or generates a unique one, but thats clearly not the way it should work

wilkerlucio17:10:36

@timovanderkamp I found the problem, what generates this issue is the way the om factory calls the React.createElement

wilkerlucio17:10:51

if you use this custom factory method this problem can be avoided:

wilkerlucio17:10:54

(defn factory
     "Create a factory constructor from a component class created with
      om.next/defui."
     ([class] (factory class nil))
     ([class {:keys [validator keyfn instrument?]
              :or {instrument? true} :as opts}]
      {:pre [(fn? class)]}
      (fn self [props & children]
        (when-not (nil? validator)
          (assert (validator props)))
        (if (and *instrument* instrument?)
          (*instrument*
            {:props    props
             :children children
             :class    class
             :factory  (factory class (assoc opts :instrument? false))})
          (let [key (if-not (nil? keyfn)
                      (keyfn props)
                      (compute-react-key class props))
                ref (:ref props)
                ref (cond-> ref (keyword? ref) str)
                t   (if-not (nil? *reconciler*)
                      (p/basis-t *reconciler*)
                      0)]
            (apply js/React.createElement class
              #js {:key               key
                   :ref               ref
                   :omcljs$reactKey   key
                   :omcljs$value      (om-props props t)
                   :omcljs$path       (-> props meta :om-path)
                   :omcljs$reconciler *reconciler*
                   :omcljs$parent     *parent*
                   :omcljs$shared     *shared*
                   :omcljs$instrument *instrument*
                   :omcljs$depth      *depth*}
              (or (util/force-children children) [])))))))

wilkerlucio17:10:40

the problem was that, om.next factories are always sending the children as a single array to the element, by using an apply at that points solves the problem

timovanderkamp17:10:15

@wilkerlucio Thanks for this solution! Yet i find it so weird that it seems like not a lot of people run into this

wilkerlucio17:10:49

disclaimer: still testing this one, just found some issues with other cases, trying to find one that works in all cases

wilkerlucio17:10:59

I think most people do, and ignore it

timovanderkamp17:10:37

Ye thats what i figured aswell

wilkerlucio18:10:54

@timovanderkamp I realized something, after doing this all the key problems are gone, but if I try to (apply dom/div ... I get some weird error, but just leaving the (om/children) at the end now works fine

timovanderkamp18:10:20

@wilkerlucio oh nice, i will try to use this and will tell you whenever i find difficulties with it

wilkerlucio18:10:42

no problem, please let me know how it goes for you