Fre 小而美的前端框架

开源网站开源项目 24-03-26 16:23:39

Fre (发音/fri:/, like free)是一个小而美的前端框架,实现了 Concurrent和Suspense

特性:

函数式组件与hooks API

并发与 Suspense

keyed reconcilation algorithm

安装

yarn add fre -S

使用

import { render, h, useState } from 'fre'function Counter() {  const [count, setCount] = useState(0)  return (    <div>      <h1>{count}</h1>      <button onClick={() => setCount(count + 1)}>+</button>    </div>  )}render(<Counter />, document.getElementById('app'))

hooks API

import { render, useState, h } from "fre"function Sex() {  const [sex, setSex] = useState("boy")  return (    <div class="sex">      <button onClick={() => setSex(sex === "boy" ? "girl" : "boy")}>x</button>      <Counter sex={sex} />    </div>  )}function Counter(props) {  const [count, setCount] = useState(0)  return (    <div class="counter">      <h1>{props.sex}</h1>      <button onClick={() => setCount(count + 1)}>+</button>      <h1>{count}</h1>    </div>  )}render(<Sex />, document.getElementById("app"))

props

虽然 hooks API 使得 state 在 function 内部受控,但是 props 仍然是这个组件从外部接受的√

如下,sex 就是从父组件传下来的

function Counter(props) {  const [count, setCount] = useState(0)  return (    <div class="counter">      <h1>{props.sex}</h1>      <button onClick={() => setCount(count + 1)}>+</button>      <h1>{count}</h1>    </div>  )}

JSX

默认也对外暴露了 h 函数,可以选用 JSX

import { h } from 'fre'

webpack 需配置:

{  "plugins": [    ["transform-react-jsx", { "pragma":"Fre.h" }]  ]}

keyed-diff-patch

基于fiber链表的diff方案,使用hash标记位置,更方便的比对

Concurrent

异步渲染,通过时间切片,suspense的方式,对任务进行优先级调度,打断继续任务

[Fre 小而美的前端框架]相关推荐

nodemon Node.js 监控工具

Nodemon 是一款非常实用的工具,用来监控你 node.js 源代码的任何变化和自动重启你的服务器。 Nodemon 是……...

par markdown 转换 html 工具

par 是一个基于 pyPEG 写的转換 markdown 为 html 的工具,它是用 python 语言开发的。 除了支持标准的 m……...

CDNJS 前端 CDN 服务

CDNJS 是一个通过快速 CDN 基础设施为开发人员和组织提供流行的前端 Web 开发资源的项目,帮助代码库与框……...

今日开源
  1. Stencil CodeIgniter 模板引擎

    Stencil 是一个 CodeIgniter 的模板引擎,通过简单可靠的方式来渲染 HTML 页面。 控制器: <?phpif(!defined('BASEPATH'))exit('Nodirectscriptaccessallowed');classHomeextendsCI_Controller{publicfunction_……

    开源软件 2024-05-07

  2. TeamTalk 开源即时通讯解决方案

    TeamTalk 开源即时通讯解决方案

    项目背景 蘑菇街能有今天的快速发展,得益于开源软件群雄崛起的大环境背景,我们一直对开源社区怀有感恩之情,因此也一直希望能为开源社区贡献一份力量。 2013年我们蘑菇街从社区导购华丽转身时尚电商平台,为解决……

    开源软件 2024-05-07

  3. GoDS Go 数据结构包

    GoDS 是一个 Go 语言实现的各种数据结构的工具包,包括: Containers (Sets, Lists, Stacks, Maps, Trees), Sets (HashSet, TreeSet, LinkedHashSet), Lists (ArrayList, SinglyLinkedList, DoublyLinkedList), St……

    开源软件 2024-05-07

返回顶部小火箭