试剂/适配器反应类由于:optimizations:advanced失败 [英] reagent/adapt-react-class fails with :optimizations :advanced

查看:89
本文介绍了试剂/适配器反应类由于:optimizations:advanced失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在导入反应组件(使用:npm-deps支持),然后用adapt-react-class适配器包装:

(:require [reagent.core :as reagent]
          [react-helmet]) 

(def meta-tags* (reagent/adapt-react-class (aget react-helmet "default")))

(defn main-panel []
  (let []
    (fn []
      [meta-tags*])))

这对于开发工作正常,但是在启用高级编译器后:

未捕获的TypeError:无法将类作为函数调用

最小回购: https://github.com/fbielejec/npm-deps-demo

解决方案

meta-tags*是一个类,但是您试图通过将其放在Reagent方括号(即meta-tags*)中来像函数一样调用它. >

在您发布在GitHub上的源代码中,您还定义了一个名为meta-tags的函数.看来您是不小心误调用了meta-tags*.您的完整代码(基于Github演示)应显示为:

(ns app.views
  (:require [reagent.core :as reagent]
            [react-helmet]))

(def meta-tags* (reagent/adapt-react-class (aget react-helmet "default")))

(defn meta-tags [{:keys [:title :description]
                  :or {title "Some title"
                       description "some description"}}]
  [meta-tags* {:id "app-meta-tags"}
   [:title {:id "title" :title title}]
   [:meta {:id "description" :content description}]])

(defn main-panel []
  (let []
    (fn []
      [:div.container
       [meta-tags] ; <- no * star!
       [:h1 "Check for the meta-tags presence"]])))

I'm importing a react component (using the :npm-deps support) and wrapping with the adapt-react-class adapter:

(:require [reagent.core :as reagent]
          [react-helmet]) 

(def meta-tags* (reagent/adapt-react-class (aget react-helmet "default")))

(defn main-panel []
  (let []
    (fn []
      [meta-tags*])))

This works fine for development, but when advanced compiler is on:

Uncaught TypeError: Cannot call a class as a function

Minimimal repo: https://github.com/fbielejec/npm-deps-demo

解决方案

meta-tags* is a class, but you're trying to call it like a function by placing it inside the Reagent square braces i.e. meta-tags*.

In the source code that you posted on GitHub, you also define a function called meta-tags. It looks like you're accidentally calling meta-tags* by mistake. Your full code (based on the Github demo) should read:

(ns app.views
  (:require [reagent.core :as reagent]
            [react-helmet]))

(def meta-tags* (reagent/adapt-react-class (aget react-helmet "default")))

(defn meta-tags [{:keys [:title :description]
                  :or {title "Some title"
                       description "some description"}}]
  [meta-tags* {:id "app-meta-tags"}
   [:title {:id "title" :title title}]
   [:meta {:id "description" :content description}]])

(defn main-panel []
  (let []
    (fn []
      [:div.container
       [meta-tags] ; <- no * star!
       [:h1 "Check for the meta-tags presence"]])))

这篇关于试剂/适配器反应类由于:optimizations:advanced失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆