@cclr/atom 0.1.45

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 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,11 @@
1
+ # `trigger`
2
+
3
+ > TODO: description
4
+
5
+ ## Usage
6
+
7
+ ```
8
+ const trigger = require('trigger');
9
+
10
+ // TODO: DEMONSTRATE API
11
+ ```
@@ -0,0 +1 @@
1
+ "use strict";var n=require("@cclr/lang");exports.createAtom=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=new Set,r=function(){e.forEach(function(n){return n(t)})};return{getter:function(){return t},setter:function(e){var o=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];return t=n.isFunction(e)?e(t):e,o?(r(),n.noop):r},emit:r,onChange:function(n){return e.add(n),function(){e.delete(n)}},destroy:function(){e.clear()}}};
@@ -0,0 +1 @@
1
+ import{isFunction as n,noop as t}from"@cclr/lang";var r=function(){var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=new Set,o=function(){e.forEach(function(n){return n(r)})};return{getter:function(){return r},setter:function(e){var u=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];return r=n(e)?e(r):e,u?(o(),t):o},emit:o,onChange:function(n){return e.add(n),function(){e.delete(n)}},destroy:function(){e.clear()}}};export{r as createAtom};
@@ -0,0 +1,45 @@
1
+ import { TAny } from '@cclr/lang';
2
+
3
+ type TAtom<T = any> = {
4
+ getter: () => T;
5
+ setter: (v: T | ((value: T) => T), autoTrigger?: boolean) => () => void;
6
+ emit: () => void;
7
+ onChange: (cb: (value: T) => void) => () => void;
8
+ destroy: () => void;
9
+ };
10
+ /**
11
+ * 创建一个数据触发器
12
+ * @param value
13
+ * @returns
14
+ */
15
+ declare const createAtom: <T extends TAny>(value?: T) => {
16
+ /**
17
+ * 获取值
18
+ * @returns
19
+ */
20
+ getter: () => T;
21
+ /**
22
+ * 设置值
23
+ * @param v 值,或者函数,会返回上一次的值
24
+ * @param autoTrigger 自动触发监听 default: true
25
+ * @returns autoTrigger 为 false 时返回 触发监听 函数
26
+ */
27
+ setter: (v: T | ((value: T) => T), autoTrigger?: boolean) => () => void;
28
+ /**
29
+ * 触发监听
30
+ */
31
+ emit: () => void;
32
+ /**
33
+ * 添加监听
34
+ * @param cb
35
+ * @returns 返回取消监听函数
36
+ */
37
+ onChange: (cb: (value: T) => void) => () => void;
38
+ /**
39
+ * 销毁
40
+ */
41
+ destroy: () => void;
42
+ };
43
+
44
+ export { createAtom };
45
+ export type { TAtom };
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@cclr/atom",
3
+ "version": "0.1.45",
4
+ "description": "> react data modal",
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": "drr build",
27
+ "g:test": "vitest run",
28
+ "g:build": "drr build"
29
+ },
30
+ "gitHead": "488cc80648aa3c5ccebce98955cc03c93d13aef4",
31
+ "dependencies": {
32
+ "@cclr/lang": "0.1.45",
33
+ "@cclr/utils": "0.1.45"
34
+ }
35
+ }