@cclr/react 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +19 -0
- package/README.md +17 -0
- package/lib/cjs/index.js +25 -0
- package/lib/esm/index.js +23 -0
- package/lib/type/index.d.ts +13 -0
- package/package.json +40 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
|
11
|
+
copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# `model`
|
|
2
|
+
|
|
3
|
+
> TODO: description
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
const front = require('front');
|
|
9
|
+
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## 功能
|
|
13
|
+
|
|
14
|
+
1. 正常的发布订阅
|
|
15
|
+
2. 在新建model实例之前,可以管理全局预设的中间件
|
|
16
|
+
3. 可以在model实例中,动态添加中间件,只能向洋葱模型的最外层添加(无法管理中间件顺序,除非是新建的配置里面)
|
|
17
|
+
4. 可以单独新建一个model,也可以同时新建多个model,每个model都是独立的
|
package/lib/cjs/index.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var react = require('react');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 简化 createContext 的使用
|
|
7
|
+
* @param defaultValue 默认值
|
|
8
|
+
* @param name 便于开发时候理解
|
|
9
|
+
* 在 React DevTools 中查看组件树时,每个使用 context 的组件都会显示与该 context 相关的名称
|
|
10
|
+
* @returns [ useCtx, Provider ]
|
|
11
|
+
*/
|
|
12
|
+
function createCtx(defaultValue, name) {
|
|
13
|
+
var ctx = /*#__PURE__*/react.createContext(defaultValue);
|
|
14
|
+
ctx.displayName = name;
|
|
15
|
+
function useCtx() {
|
|
16
|
+
var c = react.useContext(ctx);
|
|
17
|
+
if (c === undefined) {
|
|
18
|
+
throw new Error('useCtx must be inside a Provider with a value');
|
|
19
|
+
}
|
|
20
|
+
return c;
|
|
21
|
+
}
|
|
22
|
+
return [useCtx, ctx.Provider];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
exports.createCtx = createCtx;
|
package/lib/esm/index.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { createContext, useContext } from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 简化 createContext 的使用
|
|
5
|
+
* @param defaultValue 默认值
|
|
6
|
+
* @param name 便于开发时候理解
|
|
7
|
+
* 在 React DevTools 中查看组件树时,每个使用 context 的组件都会显示与该 context 相关的名称
|
|
8
|
+
* @returns [ useCtx, Provider ]
|
|
9
|
+
*/
|
|
10
|
+
function createCtx(defaultValue, name) {
|
|
11
|
+
var ctx = /*#__PURE__*/createContext(defaultValue);
|
|
12
|
+
ctx.displayName = name;
|
|
13
|
+
function useCtx() {
|
|
14
|
+
var c = useContext(ctx);
|
|
15
|
+
if (c === undefined) {
|
|
16
|
+
throw new Error('useCtx must be inside a Provider with a value');
|
|
17
|
+
}
|
|
18
|
+
return c;
|
|
19
|
+
}
|
|
20
|
+
return [useCtx, ctx.Provider];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export { createCtx };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { TPlainObject } from '@cclr/lang';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 简化 createContext 的使用
|
|
6
|
+
* @param defaultValue 默认值
|
|
7
|
+
* @param name 便于开发时候理解
|
|
8
|
+
* 在 React DevTools 中查看组件树时,每个使用 context 的组件都会显示与该 context 相关的名称
|
|
9
|
+
* @returns [ useCtx, Provider ]
|
|
10
|
+
*/
|
|
11
|
+
declare function createCtx<A extends TPlainObject | null>(defaultValue?: A, name?: string): readonly [() => A, react.Provider<A | undefined>];
|
|
12
|
+
|
|
13
|
+
export { createCtx };
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cclr/react",
|
|
3
|
+
"version": "0.1.9",
|
|
4
|
+
"description": "react 相关功能",
|
|
5
|
+
"author": "cclr <18843152354@163.com>",
|
|
6
|
+
"homepage": "",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"main": "lib/cjs/index.js",
|
|
9
|
+
"module": "lib/esm/index.js",
|
|
10
|
+
"types": "lib/type/index.d.ts",
|
|
11
|
+
"directories": {
|
|
12
|
+
"lib": "lib",
|
|
13
|
+
"test": "__tests__"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"lib",
|
|
17
|
+
"README.md"
|
|
18
|
+
],
|
|
19
|
+
"publishConfig": {
|
|
20
|
+
"access": "public",
|
|
21
|
+
"registry": "https://registry.npmjs.org/"
|
|
22
|
+
},
|
|
23
|
+
"scripts": {
|
|
24
|
+
"test": "vitest",
|
|
25
|
+
"relese": "npm run test && npm publish",
|
|
26
|
+
"build": "ccm lib",
|
|
27
|
+
"g:test": "vitest run",
|
|
28
|
+
"g:build": "ccm lib"
|
|
29
|
+
},
|
|
30
|
+
"gitHead": "ebe5ad930f1ae38c11e885ee8d781235558928e9",
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@cclr/lang": "^0.1.9",
|
|
33
|
+
"@cclr/model": "^0.1.9",
|
|
34
|
+
"@cclr/utils": "^0.1.9",
|
|
35
|
+
"@testing-library/react-hooks": "^8.0.1",
|
|
36
|
+
"@types/react": "^18.3.12",
|
|
37
|
+
"react": "^18.3.1",
|
|
38
|
+
"react-dom": "^18.3.1"
|
|
39
|
+
}
|
|
40
|
+
}
|