Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Clojure 为什么在重新构建todomvc应用程序中使用此def?_Clojure_Clojurescript_Reagent_Re Frame - Fatal编程技术网

Clojure 为什么在重新构建todomvc应用程序中使用此def?

Clojure 为什么在重新构建todomvc应用程序中使用此def?,clojure,clojurescript,reagent,re-frame,Clojure,Clojurescript,Reagent,Re Frame,请参阅重新设置TOMVC的框架 此文件包含以下def (def todo-edit (with-meta todo-input {:component-did-mount #(.focus (r/dom-node %))})) 它是从todo项函数调用的 我知道'component did mount'是react.js组件生命周期中的一个阶段,但我不理解这个定义的目的和意义。为什么有必要 请解释。目的完全是为了提供组件安装生命周期功能 def正在创

请参阅重新设置TOMVC的框架

此文件包含以下def

(def todo-edit (with-meta todo-input
                      {:component-did-mount #(.focus (r/dom-node %))}))
它是从todo项函数调用的

我知道'component did mount'是react.js组件生命周期中的一个阶段,但我不理解这个定义的目的和意义。为什么有必要


请解释。

目的完全是为了提供组件安装生命周期功能

def正在创建
todo edit
,它只是一个
todo输入
,在装载dom节点时将运行一些代码。请注意,试剂组件是在dom节点存在之前运行的函数,因此通常不能执行调用focus之类的操作。如果它们返回一个函数,则该函数将运行ever render,而您不希望对其调用focus,否则表单将无法使用

试剂在作为元数据附加的函数上查找生命周期方法。装载此输入时,它将调用dom节点上的focus方法

设置属性是一种轻量级的替代方法

使用元数据来实现这一点是笨拙的,应该避免

Form-3组件定义如下所示:

(defn my-component
  [x y z]  
  (let [some (local but shared state)      ;; <-- closed over by lifecycle fns
        can  (go here)]   
     (reagent/create-class                 ;; <-- expects a map of functions 
       {:component-did-mount               ;; the name of a lifecycle function
        #(println "component-did-mount")   ;; your implementation

        :component-will-mount              ;; the name of a lifecycle function
        #(println "component-will-mount")  ;; your implementation

        ;; other lifecycle funcs can go in here

        :display-name  "my-component"  ;; for more helpful warnings & errors

        :reagent-render        ;; Note:  is not :render
         (fn [x y z]           ;; remember to repeat parameters
            [:div (str x " " y " " z)])})))
(定义我的组件
[x y z]

(让[some(本地但共享状态);完全是为了提供组件安装生命周期功能

def正在创建
todo edit
,这只是一个
todo输入
,它将在安装dom节点时运行一些代码。请注意,试剂组件是在dom节点存在之前运行的函数,因此您通常无法执行调用focus之类的操作。如果它们返回一个函数,则该函数将运行ever render,您将无法执行该操作您不想呼叫focus on,否则表单将无法使用

试剂在作为元数据附加的函数上查找生命周期方法。装载此输入时,它将调用dom节点上的focus方法

设置属性是一种轻量级的替代方法

使用元数据来实现这一点是笨拙的,应该避免

Form-3组件定义如下所示:

(defn my-component
  [x y z]  
  (let [some (local but shared state)      ;; <-- closed over by lifecycle fns
        can  (go here)]   
     (reagent/create-class                 ;; <-- expects a map of functions 
       {:component-did-mount               ;; the name of a lifecycle function
        #(println "component-did-mount")   ;; your implementation

        :component-will-mount              ;; the name of a lifecycle function
        #(println "component-will-mount")  ;; your implementation

        ;; other lifecycle funcs can go in here

        :display-name  "my-component"  ;; for more helpful warnings & errors

        :reagent-render        ;; Note:  is not :render
         (fn [x y z]           ;; remember to repeat parameters
            [:div (str x " " y " " z)])})))
(定义我的组件
[x y z]

我同意,这看起来好多了。我同意,这看起来好多了。