@effectweb/tanstack-router 0.5.1
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 +21 -0
- package/README.md +11 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +105 -0
- package/package.json +29 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 EffectWeb contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# @effectweb/tanstack-router
|
|
2
|
+
|
|
3
|
+
EffectWeb adapter for TanStack Router Core.
|
|
4
|
+
|
|
5
|
+
- `createRouter` keeps TanStack's route-tree inference and navigation types.
|
|
6
|
+
- `RootRoute` and `Route` expose TanStack's route constructors: matching, params, validated search, redirects, loaders and errors remain in the core.
|
|
7
|
+
- `mountRouter(router)` owns the history subscription in an Effect scope and returns an EffectWeb `Source` of router state.
|
|
8
|
+
- The store adapter batches publications and copies plain state before EffectWeb freezes it. It never freezes TanStack's internal match records.
|
|
9
|
+
- The host program subscribes to that Source and renders its own matching views. Scope cleanup releases the Source, subscriptions and owned history.
|
|
10
|
+
|
|
11
|
+
Currently there is no JSX Link/Outlet API, route-level view/error boundary system, SSR adapter or file-route generator. Those can build on this binding without introducing a second route matcher.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Effect, type Scope } from 'effect';
|
|
2
|
+
import { type Source } from 'effectweb';
|
|
3
|
+
import { type AnyRouter, type CreateRouterFn, type RouterState } from '@tanstack/router-core';
|
|
4
|
+
export { BaseRoute as Route, BaseRootRoute as RootRoute, redirect, notFound, } from '@tanstack/router-core';
|
|
5
|
+
export { createBrowserHistory, createMemoryHistory } from '@tanstack/history';
|
|
6
|
+
/** TanStack supplies matching, loaders, search validation and typed navigation; EffectWeb owns publications. */
|
|
7
|
+
export declare const createRouter: CreateRouterFn;
|
|
8
|
+
/** Mount once per router in an Effect scope. The returned Source can drive an EffectWeb program or view. */
|
|
9
|
+
export declare const mountRouter: <Router extends AnyRouter>(router: Router) => Effect.Effect<Source<RouterState<Router["routeTree"]>>, Error, Scope.Scope>;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { Effect } from 'effect';
|
|
2
|
+
import { projectionSource } from 'effectweb';
|
|
3
|
+
import { RouterCore, createNonReactiveMutableStore, createNonReactiveReadonlyStore, } from '@tanstack/router-core';
|
|
4
|
+
export { BaseRoute as Route, BaseRootRoute as RootRoute, redirect, notFound, } from '@tanstack/router-core';
|
|
5
|
+
export { createBrowserHistory, createMemoryHistory } from '@tanstack/history';
|
|
6
|
+
// EffectWeb freezes published plain data. Copy it so TanStack can keep managing its mutable match resources.
|
|
7
|
+
const snapshotCopy = (value, seen = new WeakMap()) => {
|
|
8
|
+
if (value === null || typeof value !== 'object')
|
|
9
|
+
return value;
|
|
10
|
+
const prototype = Object.getPrototypeOf(value);
|
|
11
|
+
if (!Array.isArray(value) && prototype !== Object.prototype && prototype !== null)
|
|
12
|
+
return value;
|
|
13
|
+
if (seen.has(value))
|
|
14
|
+
return seen.get(value);
|
|
15
|
+
const copy = Array.isArray(value) ? [] : {};
|
|
16
|
+
seen.set(value, copy);
|
|
17
|
+
for (const key of Reflect.ownKeys(value)) {
|
|
18
|
+
if (key === 'length' && Array.isArray(value))
|
|
19
|
+
continue;
|
|
20
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
21
|
+
if ('value' in descriptor)
|
|
22
|
+
Object.defineProperty(copy, key, {
|
|
23
|
+
value: snapshotCopy(descriptor.value, seen),
|
|
24
|
+
writable: true,
|
|
25
|
+
enumerable: descriptor.enumerable ?? false,
|
|
26
|
+
configurable: true,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
return copy;
|
|
30
|
+
};
|
|
31
|
+
const publications = new WeakMap();
|
|
32
|
+
/** TanStack supplies matching, loaders, search validation and typed navigation; EffectWeb owns publications. */
|
|
33
|
+
export const createRouter = (options) => {
|
|
34
|
+
const listeners = new Set();
|
|
35
|
+
let batchDepth = 0;
|
|
36
|
+
let dirty = false;
|
|
37
|
+
const publish = () => {
|
|
38
|
+
dirty = true;
|
|
39
|
+
if (batchDepth)
|
|
40
|
+
return;
|
|
41
|
+
dirty = false;
|
|
42
|
+
for (const listener of listeners)
|
|
43
|
+
listener();
|
|
44
|
+
};
|
|
45
|
+
const instance = new RouterCore(options, () => ({
|
|
46
|
+
createMutableStore: (initial) => {
|
|
47
|
+
const store = createNonReactiveMutableStore(initial);
|
|
48
|
+
return {
|
|
49
|
+
get: store.get,
|
|
50
|
+
set: (next) => {
|
|
51
|
+
store.set((previous) => typeof next === 'function' ? next(previous) : next);
|
|
52
|
+
publish();
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
},
|
|
56
|
+
createReadonlyStore: createNonReactiveReadonlyStore,
|
|
57
|
+
batch: (run) => {
|
|
58
|
+
batchDepth++;
|
|
59
|
+
try {
|
|
60
|
+
run();
|
|
61
|
+
}
|
|
62
|
+
finally {
|
|
63
|
+
batchDepth--;
|
|
64
|
+
if (!batchDepth && dirty)
|
|
65
|
+
publish();
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
}));
|
|
69
|
+
publications.set(instance, listeners);
|
|
70
|
+
return instance;
|
|
71
|
+
};
|
|
72
|
+
/** Mount once per router in an Effect scope. The returned Source can drive an EffectWeb program or view. */
|
|
73
|
+
export const mountRouter = (router) => Effect.gen(function* () {
|
|
74
|
+
const source = yield* Effect.acquireRelease(Effect.sync(() => {
|
|
75
|
+
const listeners = publications.get(router);
|
|
76
|
+
const history = router.history;
|
|
77
|
+
if (!listeners)
|
|
78
|
+
throw new Error('Use @effectweb/tanstack-router.createRouter before mountRouter');
|
|
79
|
+
const source = projectionSource({
|
|
80
|
+
project: () => snapshotCopy(router.state),
|
|
81
|
+
});
|
|
82
|
+
listeners.add(source.changed);
|
|
83
|
+
source.start();
|
|
84
|
+
const unsubscribe = history.subscribe(() => {
|
|
85
|
+
void router
|
|
86
|
+
.load()
|
|
87
|
+
.catch((error) => console.error('Router navigation failed', error));
|
|
88
|
+
});
|
|
89
|
+
return {
|
|
90
|
+
source,
|
|
91
|
+
dispose: () => {
|
|
92
|
+
unsubscribe();
|
|
93
|
+
listeners.delete(source.changed);
|
|
94
|
+
source.dispose();
|
|
95
|
+
history.flush();
|
|
96
|
+
history.destroy();
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
}), (mounted) => Effect.sync(() => mounted.dispose()));
|
|
100
|
+
yield* Effect.tryPromise({
|
|
101
|
+
try: () => router.load(),
|
|
102
|
+
catch: (cause) => (cause instanceof Error ? cause : new Error(String(cause))),
|
|
103
|
+
});
|
|
104
|
+
return source.source;
|
|
105
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@effectweb/tanstack-router",
|
|
3
|
+
"version": "0.5.1",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"files": [
|
|
6
|
+
"dist",
|
|
7
|
+
"README.md",
|
|
8
|
+
"LICENSE"
|
|
9
|
+
],
|
|
10
|
+
"type": "module",
|
|
11
|
+
"sideEffects": false,
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"import": "./dist/index.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"publishConfig": {
|
|
19
|
+
"access": "public"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@tanstack/history": "1.162.4",
|
|
23
|
+
"@tanstack/router-core": "1.171.33"
|
|
24
|
+
},
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"effect": "4.0.0-rc.112",
|
|
27
|
+
"effectweb": "^0.5.1"
|
|
28
|
+
}
|
|
29
|
+
}
|