@barefootjs/form 0.2.0 → 0.4.0
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.js +2 -97
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,100 +1,5 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
var Listener = null;
|
|
4
|
-
var MAX_EFFECT_RUNS = 100;
|
|
5
|
-
var BatchDepth = 0;
|
|
6
|
-
var PendingEffects = new Set;
|
|
7
|
-
function createSignal(initialValue) {
|
|
8
|
-
let value = initialValue;
|
|
9
|
-
const subscribers = new Set;
|
|
10
|
-
const get = () => {
|
|
11
|
-
if (Listener) {
|
|
12
|
-
subscribers.add(Listener);
|
|
13
|
-
Listener.dependencies.add(subscribers);
|
|
14
|
-
}
|
|
15
|
-
return value;
|
|
16
|
-
};
|
|
17
|
-
const set = (valueOrFn) => {
|
|
18
|
-
const newValue = typeof valueOrFn === "function" ? valueOrFn(value) : valueOrFn;
|
|
19
|
-
if (Object.is(value, newValue)) {
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
value = newValue;
|
|
23
|
-
if (BatchDepth > 0) {
|
|
24
|
-
for (const effect of subscribers) {
|
|
25
|
-
PendingEffects.add(effect);
|
|
26
|
-
}
|
|
27
|
-
} else {
|
|
28
|
-
const effectsToRun = [...subscribers];
|
|
29
|
-
for (const effect of effectsToRun) {
|
|
30
|
-
runEffect(effect);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
return [get, set];
|
|
35
|
-
}
|
|
36
|
-
function createEffect(fn) {
|
|
37
|
-
const effect = {
|
|
38
|
-
fn,
|
|
39
|
-
cleanup: null,
|
|
40
|
-
dependencies: new Set,
|
|
41
|
-
owner: Owner,
|
|
42
|
-
children: [],
|
|
43
|
-
disposed: false,
|
|
44
|
-
runCount: 0
|
|
45
|
-
};
|
|
46
|
-
if (Owner)
|
|
47
|
-
Owner.children.push(effect);
|
|
48
|
-
runEffect(effect);
|
|
49
|
-
}
|
|
50
|
-
function runEffect(effect) {
|
|
51
|
-
if (effect.disposed)
|
|
52
|
-
return;
|
|
53
|
-
effect.runCount++;
|
|
54
|
-
if (effect.runCount > MAX_EFFECT_RUNS) {
|
|
55
|
-
effect.runCount = 0;
|
|
56
|
-
throw new Error(`Circular dependency detected: effect re-entered itself ${MAX_EFFECT_RUNS} times.`);
|
|
57
|
-
}
|
|
58
|
-
if (effect.cleanup) {
|
|
59
|
-
effect.cleanup();
|
|
60
|
-
effect.cleanup = null;
|
|
61
|
-
}
|
|
62
|
-
for (const dep of effect.dependencies) {
|
|
63
|
-
dep.delete(effect);
|
|
64
|
-
}
|
|
65
|
-
effect.dependencies.clear();
|
|
66
|
-
const prevOwner = Owner;
|
|
67
|
-
const prevListener = Listener;
|
|
68
|
-
Owner = effect;
|
|
69
|
-
Listener = effect;
|
|
70
|
-
try {
|
|
71
|
-
const result = effect.fn();
|
|
72
|
-
if (typeof result === "function") {
|
|
73
|
-
effect.cleanup = result;
|
|
74
|
-
}
|
|
75
|
-
} finally {
|
|
76
|
-
Owner = prevOwner;
|
|
77
|
-
Listener = prevListener;
|
|
78
|
-
effect.runCount--;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
function untrack(fn) {
|
|
82
|
-
const prevListener = Listener;
|
|
83
|
-
Listener = null;
|
|
84
|
-
try {
|
|
85
|
-
return fn();
|
|
86
|
-
} finally {
|
|
87
|
-
Listener = prevListener;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
function createMemo(fn) {
|
|
91
|
-
const [value, setValue] = createSignal(undefined);
|
|
92
|
-
createEffect(() => {
|
|
93
|
-
const result = fn();
|
|
94
|
-
setValue(() => result);
|
|
95
|
-
});
|
|
96
|
-
return value;
|
|
97
|
-
}
|
|
1
|
+
// src/create-form.ts
|
|
2
|
+
import { createSignal, createMemo, untrack } from "@barefootjs/client";
|
|
98
3
|
|
|
99
4
|
// ../../node_modules/.bun/@standard-schema+utils@0.3.0/node_modules/@standard-schema/utils/dist/index.js
|
|
100
5
|
function getDotPath(issue) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@barefootjs/form",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Signal-based form management for BarefootJS",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
],
|
|
18
18
|
"scripts": {
|
|
19
19
|
"build": "bun run build:js && bun run build:types",
|
|
20
|
-
"build:js": "bun build ./src/index.ts --outdir ./dist --format esm",
|
|
20
|
+
"build:js": "bun build ./src/index.ts --outdir ./dist --format esm --external @barefootjs/client",
|
|
21
21
|
"build:types": "tsgo --emitDeclarationOnly --outDir ./dist",
|
|
22
22
|
"test": "bun test",
|
|
23
23
|
"clean": "rm -rf dist"
|