0.10.0 • Published 5 months ago

react-mug v0.10.0

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
5 months ago

React Mug

概要    特性    安装    指南    API    许可    赞助

中文    English

概要

下一代 React 状态库,为极致的体验而生 —— 极致的既是用户体验,也是开发者体验。

特性

好写

秉承函数式内核,但化繁为简:

// CountState.ts
import { construction, upon } from 'react-mug';

const { r, w } = upon<number>({
  [construction]: 0,
});

export const get = r((count) => count);

export const increase = w((count, delta: number) => count + delta);

透传值的读操作,进一步化简:

// CountState.ts

export const get = r();

好调用

所有状态操作既可以直接调用:

const count = get();

increase(1);

也可以在 React 组件结合调用:

// Count.tsx
import { useR } from 'react-mug';
import { get, increase } from './CountState';

export function Count() {
  const count = useR(get);
  return <button onClick={() => increase(1)}>Count: {count}</button>;
}

好复用

所有操作均可以借助函数态相互复用:

// CountState.ts

export const addOne = w((count) => increase(count, 1));

好读

不必深入函数体就能看明白读写范围:

// CountState.ts

export const increase = w((count, delta: number) => ...);

好测

直接以函数态轻松测试操作:

// CountState.test.ts
import { increase } from './CountState';

describe('increase', () => {
  test('adds up count and delta', () => {
    expect(increase(1, 2)).toBe(3);
  });
});

可组合

参见下方指南。

可分隔

参见下方指南。

可异步

直接以普通的异步函数定义异步操作:

// CountState.ts

export const set = w();

export const query = async () => {
  const { data: count } = await fetch('/api/count').then((res) => res.json());
  set(count);
};

安装

npm i react-mug

指南

管理单个状态 组合多个状态 分隔通用特质

API

参见 src/index

许可

Apache 2.0(免费商用)。

赞助

喜欢就赞助一下吧!

(国内) (海外)


返回顶部

0.10.0-alpha.2

5 months ago

0.10.0-alpha.1

5 months ago

0.10.0-alpha.0

5 months ago

0.8.1-alpha.0

7 months ago

0.5.1-alpha.1

9 months ago

0.8.1-alpha.1

7 months ago

0.5.1-alpha.2

9 months ago

0.5.1-alpha.0

9 months ago

0.7.0-alpha.0

8 months ago

0.9.0

7 months ago

0.5.0

9 months ago

0.7.0

8 months ago

0.5.1

9 months ago

0.9.0-alpha.0

7 months ago

0.9.0-alpha.1

7 months ago

0.9.0-alpha.2

7 months ago

0.9.0-alpha.3

7 months ago

0.6.0-alpha.0

9 months ago

0.5.0-alpha.1

9 months ago

0.10.0

5 months ago

0.5.0-alpha.0

9 months ago

0.8.0-alpha.0

7 months ago

0.8.1

7 months ago

0.8.0

7 months ago

0.6.0

9 months ago

0.4.1-alpha.0

10 months ago

0.4.0

11 months ago

0.4.0-alpha.2

11 months ago

0.4.0-alpha.1

11 months ago

0.4.0-alpha.0

11 months ago

0.3.0

11 months ago

0.3.0-alpha.0

11 months ago

0.2.0

11 months ago

0.2.0-alpha.0

11 months ago

0.1.5

11 months ago

0.1.4

11 months ago

0.1.4-alpha.0

11 months ago

0.1.3

11 months ago

0.1.3-alpha.0

11 months ago

0.1.2

11 months ago

0.1.2-alpha.0

11 months ago

0.1.1

11 months ago

0.1.1-alpha.0

11 months ago

0.1.0

11 months ago

0.0.1-alpha.3

12 months ago

0.0.1-alpha.2

12 months ago

0.0.1-alpha.1

12 months ago

0.0.0

1 year ago