今日推薦開源項目:《 HTML控制框架Stimulus》
推薦理由:Stimulus 是一款炫酷有趣的針對 HTML 的 JavaScript 框架。它可以讓你的 HTML 更加閃耀。
如何使用Stimulus
- 安裝 Stimulus,可以通過 webpack 將 stimulus 加入 bundle 中或直接在<script>標籤中載入stimulus.umd.js:
- 若要嘗試使用 stimulus,可以運行作者提供的 stimulus-starter。使用方法:
- 通過 git 載入 stimulus-starter:
$ git clone https://github.com/stimulusjs/stimulus-starter.git $ cd stimulus-starter $ yarn install $ yarn start
完成後就可以在本地編輯,在 http://localhost:9000/ 查看效果 。
- 在 Glitch 上在線編輯,免去安裝的過程。
- 通過 git 載入 stimulus-starter:
- 使用範例:
在 html 文件中加入:
<div data-controller="hello"> <input data-target="hello.name" type="text"> <button data-action="click->hello#greet" >Greet</button> </div>
編寫控制器:
// src/controllers/hello_controller.js import { Controller } from "stimulus" export default class extends Controller { greet() { console.log(`Hello, ${this.name}!`) } get name() { return this.inputElement.value } get inputElement() { return this.targets.find("name") } }
通過 data-controller 連接控制器 hello_controller。
通過 data-target="hello.name" 使得控制器可以通過 name 訪問 <input> 的輸入。
通過 data-action="click->hello#greet" 執行控制器中 greet 函數。
通過 this.targets.find() 可以獲取匹配到的元素。
運行效果:
為何要用Stimulus
- 它通過增加一些效果,使網頁看起來更加炫酷。它並不想接管整個前端,相反,它的設計是為了讓 HTML 有足夠多的行為。這其實是一個普遍的 JavaScript 的思想。
- 重要的是,此框架可以與作者的另一個「單頁」應用JS客戶端框架 Turbolinks 配合的很好。這實現了讓web應用可以在移動端達到原生應用的體驗。Stimulus是在SPA即單頁面應用程序激增的現在應運而生的一個JS框架。
- Stimulus 計劃將最佳模式彙集到一個適度的小型框架中,圍繞三個主要概念:控制,目標,和動作屬性。
- Stimulus 可以不斷刷新頁面,只要屬性出現或者消失,就會進入頁面它適用於DOM的任何更新,無論是整頁載入,Turbolinks 頁面更改還是Ajax請求。
- 上手真的很快,開發者只需要根據 Stimulus 手冊花費五分鐘就可以寫一個控制器。
SPA(單頁應用程序)
顧名思義,單頁 web 應用就是只有一張 web 界面的應用,是載入單個 HTML 頁面並在用戶與應用程序交互時動態更新該頁面的web應用程序。
優點:主要體現在速度上,它可以給用戶更好的使用體驗,讓用戶在 web APP 感受原生 APP 的速度和流暢。
它快的秘訣在於它同時減少了下載資源的大小(除去第一次載入模板後,後續全部使用 JSON API ),以及極大提高了解析資源的速度(通過 JSON 數據就能更新頁面)。
使用Stimulus不得不知Turbolinks
Turbolinks 可以在不增加客戶端JS框架的複雜性的情況下,獲得單頁應用程序的性能優勢,使用HTML在伺服器端呈現您的視圖。當 Turbolinks 自動獲取網頁,不會招致全頁面載入的成本。
關於作者
Javan Makhmail:供職於 Basecamp,專研於前端開發,網頁製作。不僅是 Stimulus,他還有許多的開源項目製作。
今日推薦英文原文:《Linux is under your hood》作者:Steven J. Vaughan-Nichols
原文鏈接:https://www.zdnet.com/article/linux-is-under-your-hood/
推薦理由:事實上,BMW、雪佛來、本田、特思拉、梅賽德斯,你知道這些品牌的汽車有什麼共同特點嗎?即使你是一個資深開源愛好者你也不一定知道:它們的汽車都運行著 Linux 操作系統。
Linux is under your hood
Way back in 2004, Jonathan Schwartz, then Sun's chief operating officer, suggested that cars could become software platforms the same way feature phones were. He was right. But, it's Linux, not Java, which is making the most of "smart cars".
That's because Linux and open-source software are flexible enough to bring a complete software stack to any hardware, be it supercomputer, smartphone, or a car. There are other contenders, such as Blackberry's QNX and Microsoft IoT Connected Vehicles, but both have lost ground to Linux. Audi is moving to Linux-based Android and Microsoft lost is biggest car customer, Ford, years ago.
Today, as Dustin Kirkland, then Canonical product VP and now Google Cloud product manager, told me recently, "Ubuntu is in the Tesla and we support support auto manufacturers, but Tesla has gone on its own way. Tesla was so far ahead of the curve it doesn't surprise me that they did their own thing. But, Canonical expects most car manufacturers will work with Linux distributors to build operating systems that scale out for cars for the masses."
Much of that work is done via the Automotive Grade Linux (AGL). This Linux Foundation-based organization is a who's who of Linux-friendly car manufacturers. Its membership includes Ford, Honda, Mazda, Nissan, Mercedes, Suzuki, and the world's largest automobile company: Toyota.
"Automakers are becoming software companies, and just like in the tech industry, they are realizing that open source is the way forward," said Dan Cauchy, AGL's executive director, in a statement. Car companies know that while horsepower still sells, customers also want smart infotainment systems, automated safe drive features, and, eventually, self-driving cars.
I have two young grandsons. I seriously wonder if they'll learn to drive. Just like many people who no longer know how to drive a stick-shift, I can see people in the next 20 years never bothering with driving classes.
The AGL is helping this next generation of smart cars arrive with its infotainment source code and software development kit (SDK) AGL Unified Code Base (UCB) 4.0.
UCB, in turn, is based on Yocto 2.2, a set of tools for creating images for embedded Linux systems. AGL is expanding beyond infotainment to develop software profiles using the UCB for telematics, instrument cluster, and heads-up-display (HUD).
To support these new projects, AGL has formed a new Virtualization Expert Group (EG-VIRT) to identify a hypervisor and develop an AGL virtualization architecture that will speed up Linux car time-to-market, reduce costs, and increase security.
The ASL is also now working on car Speech Recognition and Vehicle-to-Cloud connectivity. Led by Amazon Alexa, Nuance and Voicebox, the Speech Expert Group will provide guidance for voice technologies including natural language, grammar development tools, on-board vs cloud based speech, and signal processing for noise reduction and echo cancellation.
Tesla, however, continues to go its own way. That said, under the hood, Tesla is moving forward. With the 8.1 update (17.24.30), Tesla upgraded its Linux kernel from the archaic 2.6.36 to 4.4.35.
The AGL isn't the only group working to integrate Linux and cars. The SmartDeviceLink (SDL) Consortium, which includes Ford, Toyota, Mazda, and Suzuki, is working on Linux-based open-source software for getting smartphones and cars to work together smoothly.
At the same time, Google has its own Linux for cars: Android Auto. Google is supporting this with the Open Automotive Alliance. Google is hoping to recapture the Open Handset Alliance magic, which led Android to smartphone dominance, in smart cars. This new alliance supporters include Acura, Audi, Cadillac, Ford, GMC, Honda, Hyundai, and many other car manufacturers.
And it's not just cars running on Linux. Lyft, the ride-sharing service, has been "running Ubuntu since day one across the board from server to desktop to cloud," said Kirkland. The company is also using Ubuntu in its autonomous vehicle team.
Kirkland added, "Top car equipment manufacturers, like Bosch and Continental Auto Parts, increasingly use Ubuntu IoT in their components." In addition, the GPS device company "TomTom uses Ubuntu on its back end."
Looking ahead, Kirkland can see a world where bitheads instead of gearheads will be modifying their car's software. But, "How much can you legally modify it? Gearheads have been molding for cars for years, but it still has to be street legal. I don't think we have the infrastructure for a shade-tree software engineer to pass inspection." Not yet anyway.
So, whether you're driving a car, riding in one, or working on its software, Linux is in your automotive future.
每天推薦一個 GitHub 優質開源項目和一篇精選英文科技或編程文章原文,歡迎關注開源日報。交流QQ群:202790710;電報群 https://t.me/OpeningSourceOrg