vue3.0有没可能更多借鉴clojure?
freemember007 opened this issue · comments
前段时间发了个状态,如下,尤大大考虑下,希望一如既往,vue3.0不是技术最牛的,但仍是用户体验最好的:
一直用vue,喜欢它的简洁。但不喜欢拆分组件,因为麻烦(Facebook有数千个研发,所以拆了1万个组件,咱没这么多人),往往一个页面就是一个组件,但是,当页面过于复杂时就有些不好维护了,目前手头的项目单页面过千行的已经不少了,这样模板500行,逻辑500行,可维护性已成问题。拆分又不想,否则用react去了。为了解决可维护性问题,前段时间一口气研究了所有的函数式编程语言,感觉最有潜力的的是Haskell/PureScript和Clojure(script),尤其是Clojurescript,结合reagent dom框架,感觉可维护性会有质的提升,而且真心喜欢这门语言的风格。可惜Clojure(script)的生态还不是太好,路由,服务端渲染都没有特别完美的框架,也担心引入新语言会影响产品进度。为了不折腾,新的项目还是继续vue。前两天,react-hook出来,以普通函数出现的UI组件简直和Clojure(script)的一模一样,但后者一切都是函数更有过之而不及。听说vue3.0明年出来,真心希望在这块超越react,学习Clojure(script)好的东西,做出更受**人喜欢的新版来。
我不是什么FP党,但使用Clojure(script),我感觉是可以非常自由,简单地纯函数式组织代码,并且有很好的可维护性:
(ns pages.home
(:require [reagent.core :refer [atom]]
["antd" :as A]
[ajax.core :refer [GET POST]]
[cljs.reader :refer [read-string]]))
; state
; ----------------------------------------------
(defonce users (atom []))
; action
; ----------------------------------------------
(defn get-users []
(GET "http://localhost:1110/user"
{:handler #(reset! users %)}))
; ui
; ----------------------------------------------
(defn ui-header []
[:div
[:h3 "This is home page"]
[:> A/DatePicker]
[:> A/Alert
{:banner true
:closable true
:message "请核对手机号"
:onClose #(js/alert "你关了我!")}]])
(defn ui-counter []
(let [counts (atom 0)
increment (fn [e] (.preventDefault e)(swap! counts inc))
decrement (fn [e] (.preventDefault e)(swap! counts dec))]
(fn []
[:div
(case @users
[] [:div "加载中..."]
nil [:div "暂无内容"]
[:div (str @users)])
[:button.btn {:on-click #(decrement %)} "-"]
[:button {:disabled true} @counts]
[:button.btn {:on-click #(increment %)} "+"]])))
; init
; ----------------------------------------------
(defn init []
(js/setTimeout get-users 100)
; 本地存储
(js/localStorage.clear)
(js/localStorage.setItem "prefs" "{:a localValue1 :b 2}")
; 全局常量
(js/alert goog.global.WX-URL))
; main
; ----------------------------------------------
(defn main []
(init)
[:div
[ui-header]
[ui-counter]
[:div.mt2
[:a {:href "/about?id=1"} "go to the about page 1"]]
[:div.mt2
[:a {:href "/about?id=8"} "go to the about page 8"]]])
你真的喜欢这种风格直接用 clojure 就好了...
Vue 就是 Vue,不是 clojure。