@cclr/trigger 0.1.21
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 +11 -0
- package/lib/cjs/index.js +1 -0
- package/lib/esm/index.js +1 -0
- package/lib/type/index.d.ts +57 -0
- package/package.json +46 -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
package/lib/cjs/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Function.prototype.call.bind(Object.prototype.hasOwnProperty);var t=Function.prototype.call.bind(Object.prototype.toString),n={boolean:"boolean",undefined:"undefined",number:"number",string:"string",symbol:"symbol",null:"null","[object Object]":"object","[object Function]":"function","[object RegExp]":"regexp","[object Array]":"array","[object Date]":"date","[object Error]":"error","[object Blob]":"blob","[object File]":"file","[object ArrayBuffer]":"arrayBuffer"};function r(r){return"function"===function(r){return n[typeof r]||n[t(r)]||(r?"object":"null")}(r)}function e(t){return Array.isArray(t)}var o=function(){},u=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=new Set,e=function(){n.forEach((function(n){return n(t)}))};return{getter:function(){return t},setter:function(n){var u=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];return t=r(n)?n(t):n,u?(e(),o):e},trigger:e,onChange:function(t){return n.add(t),function(){return n.delete(t)}},destroy:function(){n.clear()}}};exports.dataTrigger=u,exports.dataTriggers=function(t){var n=new Map,r=function(r){n.has(r)||n.set(r,u(t[r]))};return{getter:function(t){if(!e(t))return r(t),n.get(t).getter();var o=t;return o.forEach((function(t){return r(t)})),o.reduce((function(t,r){return t[r]=n.get(r).getter(),t}),{})},setter:function(t){var e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],o=[];Object.keys(t).forEach((function(e){r(e),o.push(n.get(e).setter(t[e],!1))}));var u=function(){o.forEach((function(t){return t()}))};return e?u():u},onChange:function(t,o){var u=e(t)?t:[t],c=[];return u.forEach((function(t){r(t),c.push(n.get(t).onChange(o))})),function(){c.forEach((function(t){return t()}))}},destroy:function(){n.forEach((function(t){return t.destroy()})),n.clear()}}};
|
package/lib/esm/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Function.prototype.call.bind(Object.prototype.hasOwnProperty);var n=Function.prototype.call.bind(Object.prototype.toString),t={boolean:"boolean",undefined:"undefined",number:"number",string:"string",symbol:"symbol",null:"null","[object Object]":"object","[object Function]":"function","[object RegExp]":"regexp","[object Array]":"array","[object Date]":"date","[object Error]":"error","[object Blob]":"blob","[object File]":"file","[object ArrayBuffer]":"arrayBuffer"};function r(r){return"function"===function(r){return t[typeof r]||t[n(r)]||(r?"object":"null")}(r)}function e(n){return Array.isArray(n)}var o=function(){},u=function(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=new Set,e=function(){t.forEach((function(t){return t(n)}))};return{getter:function(){return n},setter:function(t){var u=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];return n=r(t)?t(n):t,u?(e(),o):e},trigger:e,onChange:function(n){return t.add(n),function(){return t.delete(n)}},destroy:function(){t.clear()}}},c=function(n){var t=new Map,r=function(r){t.has(r)||t.set(r,u(n[r]))};return{getter:function(n){if(!e(n))return r(n),t.get(n).getter();var o=n;return o.forEach((function(n){return r(n)})),o.reduce((function(n,r){return n[r]=t.get(r).getter(),n}),{})},setter:function(n){var e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],o=[];Object.keys(n).forEach((function(e){r(e),o.push(t.get(e).setter(n[e],!1))}));var u=function(){o.forEach((function(n){return n()}))};return e?u():u},onChange:function(n,o){var u=e(n)?n:[n],c=[];return u.forEach((function(n){r(n),c.push(t.get(n).onChange(o))})),function(){c.forEach((function(n){return n()}))}},destroy:function(){t.forEach((function(n){return n.destroy()})),t.clear()}}};export{u as dataTrigger,c as dataTriggers};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { TAny, TPlainObject, TNoop } from '@cclr/lang';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 创建一个数据触发器
|
|
5
|
+
* @param value
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
8
|
+
declare const dataTrigger: <T extends TAny>(value?: T) => {
|
|
9
|
+
/**
|
|
10
|
+
* 获取值
|
|
11
|
+
* @returns
|
|
12
|
+
*/
|
|
13
|
+
getter: () => T;
|
|
14
|
+
/**
|
|
15
|
+
* 设置值
|
|
16
|
+
* @param v 值,或者函数,会返回上一次的值
|
|
17
|
+
* @param autoTrigger 自动触发监听 default: true
|
|
18
|
+
* @returns autoTrigger 为 false 时返回 触发监听 函数
|
|
19
|
+
*/
|
|
20
|
+
setter: (v: T | ((value: T) => T), autoTrigger?: boolean) => () => void;
|
|
21
|
+
/**
|
|
22
|
+
* 触发监听
|
|
23
|
+
*/
|
|
24
|
+
trigger: () => void;
|
|
25
|
+
/**
|
|
26
|
+
* 添加监听
|
|
27
|
+
* @param cb
|
|
28
|
+
* @returns 返回取消监听函数
|
|
29
|
+
*/
|
|
30
|
+
onChange: (cb: (value: T) => void) => () => boolean;
|
|
31
|
+
/**
|
|
32
|
+
* 销毁
|
|
33
|
+
*/
|
|
34
|
+
destroy: () => void;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
type TDataTriggersApi<T extends TPlainObject, KK extends keyof T = keyof T> = {
|
|
38
|
+
getter: {
|
|
39
|
+
<K extends KK = KK>(key: K): T[K];
|
|
40
|
+
<K extends KK = KK>(key: K[]): {
|
|
41
|
+
[P in K]: T[P];
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
setter: (obj: {
|
|
45
|
+
[K in keyof T]?: T[K] | ((value: T[K]) => T[K]);
|
|
46
|
+
}, trigger?: boolean) => void;
|
|
47
|
+
onChange: <K extends keyof T>(key: K | K[], cb: (value: T[K]) => void) => () => void;
|
|
48
|
+
destroy: TNoop;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* 创建一个数据触发器
|
|
52
|
+
* @param value
|
|
53
|
+
* @returns
|
|
54
|
+
*/
|
|
55
|
+
declare const dataTriggers: <T extends TPlainObject>(value: T) => TDataTriggersApi<T>;
|
|
56
|
+
|
|
57
|
+
export { type TDataTriggersApi, dataTrigger, dataTriggers };
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cclr/trigger",
|
|
3
|
+
"version": "0.1.21",
|
|
4
|
+
"description": "> TODO: description",
|
|
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": "ccf build",
|
|
27
|
+
"g:test": "vitest run",
|
|
28
|
+
"g:build": "ccf build"
|
|
29
|
+
},
|
|
30
|
+
"gitHead": "82b59c24ac9b3031e9ce241e4e6c5425643f2bc2",
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@cclr/emitter": "0.1.21",
|
|
33
|
+
"@cclr/front": "0.1.21",
|
|
34
|
+
"@cclr/lang": "0.1.21",
|
|
35
|
+
"@cclr/model": "0.1.21",
|
|
36
|
+
"@cclr/react": "0.1.21",
|
|
37
|
+
"@cclr/react-model": "0.1.21",
|
|
38
|
+
"@cclr/utils": "0.1.21"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@types/react": "^18.3.18",
|
|
42
|
+
"@types/react-dom": "^18.3.5",
|
|
43
|
+
"react": "^18.3.1",
|
|
44
|
+
"react-dom": "^18.3.1"
|
|
45
|
+
}
|
|
46
|
+
}
|