Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dismissable alert breaks #77

Open
ebellani opened this issue Jul 14, 2015 · 7 comments
Open

Dismissable alert breaks #77

ebellani opened this issue Jul 14, 2015 · 7 comments

Comments

@ebellani
Copy link

Executing the code at the branch https://github.com/ebellani/om-bootstrap/tree/dismissable-alert-timeout
will produce the exception

random.js:474 Uncaught TypeError: G__14921.set_timeout is not a function

which is the result IMO of this code

(defcomponentk alert*
  "Renders the alert component with timeout mixed in. TODO: This
   should probably use the component macro and be defined inline under
   the alert function. No need for a separate name."
  [[:data bs props children] owner]
  (:mixins m/set-timeout-mixin)
  (did-mount [_] (when (and (:on-dismiss bs) (:dismiss-after bs))
                   (doto owner 
                      ;;  BREAK
                     (.set-timeout (:on-dismiss bs)
                                   (:dismiss-after bs)))))
  (render
   [_]
   (let [classes (t/bs-class-set bs)
         dismiss-button (when-let [od (:on-dismiss bs)]
                          (d/button {:type "button"
                                     :class "close"
                                     :on-click od
                                     :aria-hidden true}
                                    "×"))]
     (d/div (u/merge-props props {:class (d/class-set classes)})
            dismiss-button
            children))))
@ebellani
Copy link
Author

This seems to be related to the timeout-mixin, but frankly I'm not exactly sure as of now. Any ideas?

@sritchie
Copy link
Contributor

Yeah, that's right. This is a bug with om-tools's mixins in advanced compilation mode. Check out the "Button Loading State" example text.

To fix it, you'll need to alias that call:

   ;; This is required to get around
         ;; https://github.com/Prismatic/om-tools/issues/29.
         set-timeout (aget owner "set_timeout")

Then call set-timeout as a function instead of .set-timeout as a method.

@sritchie
Copy link
Contributor

Actually, according to @swannodette you can add a line to your externs:

plumatic/om-tools#29

@sritchie sritchie reopened this Jul 14, 2015
@ebellani
Copy link
Author

Another thing, is the order of arguments of defcomponentk alert* correct?
I mean [[:data bs props children] owner] instead of [owner [:data bs props children]]

@ebellani
Copy link
Author

btw, the aget doesn't seem to work, since the owner in question does not have that property. Perhaps the externs?

@sritchie
Copy link
Contributor

@ebellani the order of arguments doesn't matter, as om-tools passes the argument vector of defcomponentk onto the fnk macro. What that argument vector is expanding to is:

{owner :owner {:keys [bs props children} :data}

It's just easier to directly write the keys that you want to access.

@sritchie
Copy link
Contributor

@ebellani huh, confused on the aget not working. Is this in dev mode or advanced compilation mode? Can you get the "Button loading state" example from the docs site to work?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants