前端框架选型是企业提升开发效率与用户体验的关键因素
761
2022-10-08
brutal.js:一个疯狂的小框架,用于构建野蛮的Web应用程序
Chosen by toddlers, insects, and stupid coders.
Be boring, be dumb. Be too stupid for complex tools.
Make components from cross-browser web standards without thinking too hard.
Dumbass is a library to help you do this. It is not taught by exposing its concepts, but rather through examples. Which are provided below.
The aim is to aquire an intuitive understanding of what works, and to be able to use it without thinking.
Much care has been given to crafting the developer experience to enable this.
Why?
Kernighan's Law
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.(Brian Kernighan)
Kernighan's Law is named for Brian Kernighan and derived from a quote from Kernighan and Plauger's book The Elements of Programming Style:
Everyone knows that debugging is twice as hard as writing a program in the first place. So if you're as clever as you can be when you write it, how will you ever debug it?
While hyperbolic, Kernighan's Law makes the argument that simple code is to be preferred over complex code, because debugging any issues that arise in complex code may be costly or even infeasible.
So, what's this?
No JSX, no Shadow DOM, no fancy framworks, no opinions.
Just HTML, CSS and JavaScript—No JSX, no Shadow DOM, no fancy frameworks, no opinions.Stop learning, stagnate!—Use the syntax you already know. Stop learning new things. Do more with what's already here.Crazy and fun, but in a serious way—Dumbass is the tool for people who don't want to think too hard to make UI.
To learn more...oh wait, you already know enough.
Gorgeous dumbass
function Spin(n) { return d`
Still not bored?
You soon will be. Nothing amazing here: Play with the full example on CodePen
See even more boring code in a 250 line TodoMVC test
Install mantras
Install dumbass with npm:
npm i --save dumbass
Parcel or Webpack dumbass and import:
import { d } from 'dumbass'
See a CodeSandbox how-to of above
Or import in a module:
See a CodePen how-to of above
Basic Examples
Components
Defining
const Title = state => d`
Nesting
const Parent = state => d`
Inserting
Parent("Hello").to('body', 'beforeEnd');
Updating
Parent("Greetings");let i = 1;setTimeout(() => Parent(`${i++} 'Hi's`), 3000);
ToDo MVC Example
function App(state) { const {list} = state; return d` todos
Updating on events
function newTodoIfEnter(keyEvent) { if ( keyEvent.key !== 'Enter' ) return; State.todos.push(makeTodo(keyEvent.target.value)); TodoList(State.todos); keyEvent.target.value = ''; }
Properties
Do not exist.
Global State
is nothing special.
Routing
function changeHash(e) { e.preventDefault(); history.replaceState(null,null,e.target.href); routeHash();}function routeHash() { switch(location.hash) { case "#/active": listActive(); break; case "#/completed": listCompleted(); break; case "#/": default: listAll(); break; }}function Routes() { return d`
Most of the examples above are taken from in a 250 line TodoMVC test, the full code of which you can see here..
Go forth, stagnate and be dumb!
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~