@dnd-kit/state 0.0.3 → 0.0.4-beta-20240621131401
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/dist/index.d.mts +16 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.js +21 -32
- package/dist/index.mjs +21 -32
- package/package.json +3 -3
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ReadonlySignal } from '@preact/signals-core';
|
|
2
|
+
export { ReadonlySignal, Signal, batch, effect, signal, untracked } from '@preact/signals-core';
|
|
3
|
+
|
|
4
|
+
declare function computed<T>(compute: () => T, comparator?: (a: T, b: T) => boolean): ReadonlySignal<T>;
|
|
5
|
+
|
|
6
|
+
declare function deepEqual<T>(a: T, b: T): boolean;
|
|
7
|
+
|
|
8
|
+
declare function reactive({ get }: ClassAccessorDecoratorTarget<any, any>, _: ClassAccessorDecoratorContext<any, any>): ClassAccessorDecoratorResult<any, any>;
|
|
9
|
+
declare function derived<This, Return>(target: (this: This) => Return, _: ClassGetterDecoratorContext<This, Return>): (this: This) => Return;
|
|
10
|
+
|
|
11
|
+
type CleanupFunction = () => void;
|
|
12
|
+
type Effect = () => CleanupFunction | void;
|
|
13
|
+
|
|
14
|
+
declare function effects(...entries: Effect[]): CleanupFunction;
|
|
15
|
+
|
|
16
|
+
export { type CleanupFunction, type Effect, computed, deepEqual, derived, effects, reactive };
|
package/dist/index.d.ts
CHANGED
|
@@ -5,12 +5,12 @@ declare function computed<T>(compute: () => T, comparator?: (a: T, b: T) => bool
|
|
|
5
5
|
|
|
6
6
|
declare function deepEqual<T>(a: T, b: T): boolean;
|
|
7
7
|
|
|
8
|
-
declare function reactive(
|
|
9
|
-
declare function derived(target:
|
|
8
|
+
declare function reactive({ get }: ClassAccessorDecoratorTarget<any, any>, _: ClassAccessorDecoratorContext<any, any>): ClassAccessorDecoratorResult<any, any>;
|
|
9
|
+
declare function derived<This, Return>(target: (this: This) => Return, _: ClassGetterDecoratorContext<This, Return>): (this: This) => Return;
|
|
10
10
|
|
|
11
11
|
type CleanupFunction = () => void;
|
|
12
12
|
type Effect = () => CleanupFunction | void;
|
|
13
13
|
|
|
14
14
|
declare function effects(...entries: Effect[]): CleanupFunction;
|
|
15
15
|
|
|
16
|
-
export { CleanupFunction, Effect, computed, deepEqual, derived, effects, reactive };
|
|
16
|
+
export { type CleanupFunction, type Effect, computed, deepEqual, derived, effects, reactive };
|
package/dist/index.js
CHANGED
|
@@ -85,45 +85,34 @@ function deepEqual(a, b) {
|
|
|
85
85
|
|
|
86
86
|
// src/decorators.ts
|
|
87
87
|
var import_signals_core2 = require("@preact/signals-core");
|
|
88
|
-
function reactive(
|
|
89
|
-
|
|
90
|
-
|
|
88
|
+
function reactive({ get }, _) {
|
|
89
|
+
return {
|
|
90
|
+
init() {
|
|
91
|
+
return (0, import_signals_core2.signal)(void 0);
|
|
92
|
+
},
|
|
91
93
|
get() {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}
|
|
95
|
-
const stored = store.get(this);
|
|
96
|
-
const value = stored == null ? void 0 : stored.value;
|
|
97
|
-
return value;
|
|
94
|
+
const current = get.call(this);
|
|
95
|
+
return current.value;
|
|
98
96
|
},
|
|
99
|
-
set(
|
|
100
|
-
const
|
|
101
|
-
if (
|
|
102
|
-
if (stored.peek() !== value) {
|
|
103
|
-
stored.value = value;
|
|
104
|
-
}
|
|
97
|
+
set(newValue) {
|
|
98
|
+
const current = get.call(this);
|
|
99
|
+
if (current.peek() === newValue) {
|
|
105
100
|
return;
|
|
106
101
|
}
|
|
107
|
-
|
|
102
|
+
current.value = newValue;
|
|
108
103
|
}
|
|
109
|
-
}
|
|
104
|
+
};
|
|
110
105
|
}
|
|
111
|
-
function derived(target,
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
}
|
|
119
|
-
if (!store.get(this)) {
|
|
120
|
-
store.set(this, computed(compute.bind(this)));
|
|
121
|
-
}
|
|
122
|
-
const stored = store.get(this);
|
|
123
|
-
const value = stored == null ? void 0 : stored.value;
|
|
124
|
-
return value;
|
|
106
|
+
function derived(target, _) {
|
|
107
|
+
const map = /* @__PURE__ */ new WeakMap();
|
|
108
|
+
return function() {
|
|
109
|
+
let result = map.get(this);
|
|
110
|
+
if (!result) {
|
|
111
|
+
result = computed(target.bind(this));
|
|
112
|
+
map.set(this, result);
|
|
125
113
|
}
|
|
126
|
-
|
|
114
|
+
return result.value;
|
|
115
|
+
};
|
|
127
116
|
}
|
|
128
117
|
|
|
129
118
|
// src/effects.ts
|
package/dist/index.mjs
CHANGED
|
@@ -60,45 +60,34 @@ function deepEqual(a, b) {
|
|
|
60
60
|
|
|
61
61
|
// src/decorators.ts
|
|
62
62
|
import { signal } from "@preact/signals-core";
|
|
63
|
-
function reactive(
|
|
64
|
-
|
|
65
|
-
|
|
63
|
+
function reactive({ get }, _) {
|
|
64
|
+
return {
|
|
65
|
+
init() {
|
|
66
|
+
return signal(void 0);
|
|
67
|
+
},
|
|
66
68
|
get() {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
-
const stored = store.get(this);
|
|
71
|
-
const value = stored == null ? void 0 : stored.value;
|
|
72
|
-
return value;
|
|
69
|
+
const current = get.call(this);
|
|
70
|
+
return current.value;
|
|
73
71
|
},
|
|
74
|
-
set(
|
|
75
|
-
const
|
|
76
|
-
if (
|
|
77
|
-
if (stored.peek() !== value) {
|
|
78
|
-
stored.value = value;
|
|
79
|
-
}
|
|
72
|
+
set(newValue) {
|
|
73
|
+
const current = get.call(this);
|
|
74
|
+
if (current.peek() === newValue) {
|
|
80
75
|
return;
|
|
81
76
|
}
|
|
82
|
-
|
|
77
|
+
current.value = newValue;
|
|
83
78
|
}
|
|
84
|
-
}
|
|
79
|
+
};
|
|
85
80
|
}
|
|
86
|
-
function derived(target,
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
}
|
|
94
|
-
if (!store.get(this)) {
|
|
95
|
-
store.set(this, computed(compute.bind(this)));
|
|
96
|
-
}
|
|
97
|
-
const stored = store.get(this);
|
|
98
|
-
const value = stored == null ? void 0 : stored.value;
|
|
99
|
-
return value;
|
|
81
|
+
function derived(target, _) {
|
|
82
|
+
const map = /* @__PURE__ */ new WeakMap();
|
|
83
|
+
return function() {
|
|
84
|
+
let result = map.get(this);
|
|
85
|
+
if (!result) {
|
|
86
|
+
result = computed(target.bind(this));
|
|
87
|
+
map.set(this, result);
|
|
100
88
|
}
|
|
101
|
-
|
|
89
|
+
return result.value;
|
|
90
|
+
};
|
|
102
91
|
}
|
|
103
92
|
|
|
104
93
|
// src/effects.ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dnd-kit/state",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4-beta-20240621131401",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"module": "./dist/index.mjs",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@dnd-kit/eslint-config": "*",
|
|
24
24
|
"eslint": "^8.38.0",
|
|
25
|
-
"tsup": "^
|
|
26
|
-
"typescript": "^5.
|
|
25
|
+
"tsup": "^8.1.0",
|
|
26
|
+
"typescript": "^5.5.2"
|
|
27
27
|
},
|
|
28
28
|
"publishConfig": {
|
|
29
29
|
"access": "public"
|