clojurescript

by Jacek Schae

由Jacek Schae

为什么ClojureScript在NPM上如此出色 (Why ClojureScript works so well with NPM)

Every language that complies/transpiles to JavaScript wants to connect to npm to use this huge ecosystem. The master of this is, of course, ECMAScript. The second one — in my humble opinion — is ClojureScript, due to shadow-cljs.

每种符合/编译为JavaScript的语言都希望连接到npm以使用这个庞大的生态系统。 当然,最主要的是ECMAScript。 我的第二个观点是我的拙见-由于有shadow-cljs ,它是ClojureScript 。

Disclaimer: I know there is a lot of work going on in different communities that tap into npm. By all means I’m not trying to diminish any of that by stating that CLJS (ClojureScript) is the best . I just want to give you a glance at how this works in ClojureScript.

免责声明:我知道在npm中,不同社区中正在进行很多工作。 无论如何,我并不想通过声明CLJS(ClojureScript)是最好的方法来减少任何这种情况。 我只想让您了解一下ClojureScript中的工作方式。

安装npm软件包 (Installing npm packages)

In ClojureScript, we install npm packages as we would in JavaScript. We use the standard package.json and shadow-cljs build tool and you’ll figure out the rest.

在ClojureScript中,我们将像在JavaScript中那样安装npm软件包。 我们使用标准的package.json和shadow-cljs构建工具,其余的您将了解。

After the installation, we have to require the package. The require statement is almost identical to import from JS. In CLJS we swap the order — first we say from where, and then what.

安装后,我们需要包装。 require语句与从JS import几乎相同。 在CLJS中,我们交换顺序-首先我们从哪里说,然后是什么。

Every ClojureScript file starts with a ns — namespace declaration. Following that we have require instead of import . And then we define a function with defn. This function will tap into our required firebase packages, and instead of using . to navigate to our method initializeApp, we use / . We make sure that when we invoke the JS method initializeApp we convert CLJS map (datastructure) to a JS Object with #js.

每个ClojureScript文件都以ns —名称空间声明开头。 接下来,我们需要而不是import。 然后我们用defn定义一个函数。 此功能将使用我们所需的firebase软件包,而不是使用。 导航到我们的方法initializeApp,我们使用/。 我们确信,当我们调用JS方法initializeApp我们把CLJS图(数据结构)的JS对象与#js

Let’s try some other npm packages to get a better feeling for the interop between npm and ClojureScript.

让我们尝试其他npm软件包,以更好地了解npm和ClojureScript之间的互操作。

React (React)

How about using React? ClojureScript has a couple of wrappers for React— the most popular one is Reagent. Here is a simple counter example with React hooks and Reagent.

如何使用React? ClojureScript有几个React的包装器-最受欢迎的是Reagent 。 这是一个带有React挂钩和Reagent的简单计数器示例。

In both examples, we first import/require React and Reagent. Then we define state in React using hooks (and in Reagent using atoms).

在这两个示例中,我们首先导入/需要React和Reagent。 然后,我们在React中使用钩子定义状态(在Reagent中使用原子定义)。

What follows is a JSX (JavaScript) and hiccup (ClojureScript) component.

接下来是一个JSX(JavaScript)和打ic(ClojureScript)组件。

This is cool, but how do we use React UI Libraries from Reagent?

这很酷,但是我们如何使用Reagent中的React UI库?

React UI库 (React UI Libraries)

One of the most popular UI libraries is material-ui. After the installation we require this library and then import our Button component as well as React. In Clojure Script we only require the Button. We don’t need to require Reagent since it’s in our ClojureScript deps. To interop with React we would use :> form and pass all of the properties that we want in a {} .

最受欢迎的UI库之一是material-ui 。 安装后,我们需要这个库,然后导入我们的Button组件以及React。 在Clojure脚本中,我们仅需要按钮。 因为它在我们的ClojureScript deps中,所以我们不需要Reagent。 要与React互操作,我们将使用:& gt; 形成并通过的所有属性,我们希望在a {}。

Redux (Redux)

How about Redux, you might ask? Well, there is a library that is build on top of Reagent, called re-frame. First designed in Dec 2014, it even pre-dates the official Elm Architecture.

您可能会问Redux呢? 好吧,有一个库是在Reagent之上构建的,称为re-frame 。 它于2014年12月首次设计,甚至早于官方Elm Architecture 。

By now you should have a pretty good picture as to why CLJS loves the npm ecosystem and how easy it is to interop from CLJS to JS. Maybe this is interesting to you, and you are wondering why? Why should you even try ClojureScript?

到目前为止,您应该对CLJS为什么喜欢npm生态系统以及从CLJS到JS互操作有多么容易有了一个很好的了解。 也许这对您来说很有趣,您想知道为什么吗? 为什么还要尝试ClojureScript?

为什么? (Why?)

一成不变的 (Immutable)

All ClojureScritp data structures are immutable and persistent. You don’t need to learn a new API if you want to leverage something like ImmutableJS.

所有ClojureScritp数据结构都是不可变的和持久的。 如果您想利用ImmutableJS之类的东西,则无需学习新的API。

功能性 (Functional)

ClojureScript embraces Functional Programming ideas at its core. You don’t need Lodash or Ramda.

ClojureScript以函数式编程思想为核心。 你不需要Lodash或Ramda 。

简单 (Simple)

With shadow-cljs you don’t need to spend time configuring your builds. You require what you need and the build tool will do the job.

使用shadow-cljs,您无需花费时间来配置构建。 您需要所需的内容,构建工具将完成这项工作。

简洁 (Concise)

You liability is the LoC you write . ClojureScript is one of the concise programming languages out there. Check out the last section of this comparison.

您的责任是您编写的LoC。 ClojureScript是其中一种简洁的编程语言。 查看此比较的最后一部分。

强大 (Powerful)

ClojureScript uses Google Closure Tools for code minification and tree shaking. The same tools that Google is using to build Gmail, Google Calendar, Google Docs, and Google Maps.

ClojureScript使用Google Closure Tools进行代码最小化和摇树。 Google用于构建Gmail,Google日历,Google文档和Google地图的工具相同。

JavaScript (JavaScript)

It compiles/transpiles to JavaScript. Just as ES (EcmaScript) ReasonML, PureScript, and Elm.

它编译/编译为JavaScript。 就像ES(EcmaScript)ReasonML,PureScript和Elm。

友好 (Friendly)

The ClojureScript community is the most friendly and welcoming group of people that I have ever meet online. We mainly hang out on Slack and ClojureVerse.

ClojureScript社区是我网上见过的最友好,最热情的一群人。 我们主要在Slack和ClojureVerse上闲逛 。

全栈 (Full-Stack)

ClojureScript’s older brother, Clojure, embraces all of these ideas with Java. If you want to write your server on one of the most performant and stable platforms there is — the Java Virtuel Machine — you can do that using the same language.

ClojureScript的哥哥Clojure用Java拥抱了所有这些想法。 如果要在性能最高且最稳定的平台之一上编写服务器-Java Virtuel Machine,则可以使用相同的语言来完成。

If you like this article you should follow me on Twitter. I only write/tweet about programming and technology — mainly about ClojureScript and Clojure.

如果您喜欢这篇文章,应该在Twitter上关注我。 我只写/推文有关编程和技术-主要是关于ClojureScript和Clojure。

翻译自: https://www.freecodecamp.org/news/why-clojurescript-works-so-well-with-npm-128221d302ba/

clojurescript

clojurescript_为什么ClojureScript在NPM上如此出色相关推荐

  1. TypeScript故事—如何使用TypeScript在NPM上发布自定义钩子

    On this page: 在本页面: What is NPM? 什么是NPM? Why React Custom Hooks? 为什么要使用自定义挂钩? Where does TypeScript ...

  2. 从0到1,一步步开发React的loading组件,并发布到npm上

    没有发布过npm包的同学,可能会对NPM对开发有一种蜜汁敬畏,觉得这是一个很高大上的东西.甚至有次面试,面试官问我有没有发过npm包,当时只用过还没写过,我想应该挺难的,就小声说了没有,然后就让我回去 ...

  3. 从搭建脚手架到在npm上发布react组件

    从搭建脚手架到在npm上发布react组件 最近公司给公司里架设了私有的npm仓库,相应地也需要一个用来发布react组件用的脚手架,在这个过程中又又又又复习了一下webpack,在这里分享下脚手架搭 ...

  4. Vue封装预约日期插件和发布到npm上

    插件代码 <template><div class="subscribe-time" v-show="setting.display"> ...

  5. npm上传自己的项目

    npm安装就不介绍了,自行度娘.本文介绍npm上传 先初始化:npm init 根据提示填完系统介绍信息(package.json): 再登录npmjs: npm login 效果如图: 输入注册的用 ...

  6. 如何使用@vue/cli 3.0在npm上创建,发布和使用你自己的Vue.js组件库

    译者按: 你可能npm人家的包过成千上万次,但你是否有创建,发布和使用过自己的npm包? 原文: How to create, publish and use your own VueJS Compo ...

  7. Vue自定义组件npm上传私服,且从私服下载使用

    Vue自定义组件npm上传私服,yarn私服下载使用 安装镜像源管理工具nrm 发布自定义组件到公司私服 若未下载nrm源管理工具直接使用npm设置私服地址也可以 以下步骤都是基于npm命令 从私服下 ...

  8. 手写一个自己的 cli 并发布到 npm 上

    手写一个自己的 cli 并发布到 npm 上 简介:大家平时肯定用过 vue-cli 或者 create-react-app,只需要敲简单的命令行,就可以生成一个完整的项目,非常好用.由于本人所在公司 ...

  9. 使用cdn和npm引入的区别_在npm上发布自己的vue组件库(使用npm install 或者 CDN的方式引用)...

    一.npm publish 发布包到npm库的命令是npm publish npm publish发布包,需要先配置webpack.json文件,如果没有webpack.json文件,可以通过npm ...

最新文章

  1. python列表字典操作_Python 列表(list)、字典(dict)、字符串(string)常用基本操作小结...
  2. CrystalDiskInfo的下载使用
  3. c语言构造报文,构造一个缓冲区溢出的C语言的例子
  4. Linux下shell脚本指定程序运行时长
  5. 印度评论九章量子计算机,张礼立:中国 “九章”量子计算机到底厉害在哪?...
  6. 自学python买什么教材-Python 有哪些入门学习方法和值得推荐的经典教材?
  7. 电脑安装linux后打不开win,安装完linux后 windows无法启动
  8. [故事]Making machines with brains
  9. 游戏筑基开开发之指针数组及数组指针详解(C语言)
  10. FTP协议的命令与返回码
  11. C# 的基本数据类型
  12. Oracle约束的使用
  13. python写入access_使用Python对Access读写操作方法详解
  14. Linux下载Java包,Linux环境Java包的安装和环境配置
  15. 【报告分享】 2020-2021年数字内容产业趋势报告-企鹅智库 (附下载)
  16. python3下操作SVN
  17. i春秋《从0到1:CTFer成长之路》通关WP
  18. js正则之前瞻后顾与非捕获分组
  19. handsontable使用及遇到的坑--mergeCell、合并单元格
  20. 郭琳加冕 2022第三季完美大师 全球人气季军

热门文章

  1. 使用git命令上传本地文件到GitHub上
  2. 大数据岗位必知必会的53个Java基础
  3. iOS 异形tabBar, 中间item凸起
  4. javascript函数全解
  5. 小程序获取用户的操作轨迹日志
  6. 【git】git入门之把自己的项目上传到github
  7. C#图片处理常见方法性能比较
  8. webpack入门(二)what is webpack
  9. 图像处理之噪声---椒盐,白噪声,高斯噪声三种不同噪声的区别
  10. 《Two Dozen Short Lessons in Haskell》学习(八)- Function Types, Classes, and Polymorphism