Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@solidjs/router

Package Overview
Dependencies
Maintainers
2
Versions
67
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@solidjs/router - npm Package Compare versions

Comparing version 0.11.5 to 0.12.0

9

dist/data/cache.d.ts

@@ -1,10 +0,9 @@

import { type ReconcileOptions } from "solid-js/store";
import { CacheEntry } from "../types.js";
export declare function revalidate(key?: string | string[] | void, force?: boolean): Promise<void>;
export declare function cacheKeyOp(key: string | string[] | void, fn: (cacheEntry: CacheEntry) => void): void;
export type CachedFunction<T extends (...args: any) => U | Response, U> = T & {
keyFor: (...args: Parameters<T>) => string;
export type CachedFunction<T extends (...args: any) => any> = T extends (...args: infer A) => infer R ? ([] extends A ? (...args: never[]) => R : T) & {
keyFor: (...args: A) => string;
key: string;
};
export declare function cache<T extends (...args: any) => U | Response, U>(fn: T, name: string, options?: ReconcileOptions): CachedFunction<T, U>;
} : never;
export declare function cache<T extends (...args: any) => any>(fn: T, name: string): CachedFunction<T>;
export declare namespace cache {

@@ -11,0 +10,0 @@ var set: (key: string, value: any) => void;

import { createSignal, getListener, getOwner, onCleanup, sharedConfig, startTransition } from "solid-js";
import { createStore, reconcile } from "solid-js/store";
import { getRequestEvent, isServer } from "solid-js/web";

@@ -44,4 +43,3 @@ import { useNavigate, getIntent } from "../routing.js";

}
export function cache(fn, name, options) {
const [store, setStore] = createStore({});
export function cache(fn, name) {
// prioritize GET for server functions

@@ -93,4 +91,4 @@ if (fn.GET)

res =
"then" in cached[1]
? cached[1].then(handleResponse(false), handleResponse(true))
"then" in (cached[1])
? (cached[1]).then(handleResponse(false), handleResponse(true))
: handleResponse(false)(cached[1]);

@@ -129,4 +127,4 @@ !isServer && intent === "navigate" && startTransition(() => cached[3][1](cached[0])); // update version

res =
"then" in res
? res.then(handleResponse(false), handleResponse(true))
"then" in (res)
? (res).then(handleResponse(false), handleResponse(true))
: handleResponse(false)(res);

@@ -159,6 +157,3 @@ }

throw v;
if (isServer)
return v;
setStore(key, reconcile(v, options));
return store[key];
return v;
};

@@ -165,0 +160,0 @@ }

@@ -5,3 +5,4 @@ /**

import { type Accessor } from "solid-js";
export declare function createAsync<T>(fn: () => Promise<T>, options: {
import { type ReconcileOptions } from "solid-js/store";
export declare function createAsync<T>(fn: (prev: T) => Promise<T>, options: {
name?: string;

@@ -11,3 +12,3 @@ initialValue: T;

}): Accessor<T>;
export declare function createAsync<T>(fn: () => Promise<T>, options?: {
export declare function createAsync<T>(fn: (prev: T | undefined) => Promise<T>, options?: {
name?: string;

@@ -17,1 +18,13 @@ initialValue?: T;

}): Accessor<T | undefined>;
export declare function createAsyncStore<T>(fn: (prev: T) => Promise<T>, options: {
name?: string;
initialValue: T;
deferStream?: boolean;
reconcile?: ReconcileOptions;
}): Accessor<T>;
export declare function createAsyncStore<T>(fn: (prev: T | undefined) => Promise<T>, options?: {
name?: string;
initialValue?: T;
deferStream?: boolean;
reconcile?: ReconcileOptions;
}): Accessor<T | undefined>;
/**
* This is mock of the eventual Solid 2.0 primitive. It is not fully featured.
*/
import { createResource, sharedConfig } from "solid-js";
import { createResource, sharedConfig, untrack } from "solid-js";
import { createStore, reconcile, unwrap } from "solid-js/store";
import { isServer } from "solid-js/web";
export function createAsync(fn, options) {
const [resource] = createResource(() => subFetch(fn), v => v, options);
let resource;
let prev = () => !resource || resource.state === "unresolved" ? undefined : resource.latest;
[resource] = createResource(() => subFetch(fn, untrack(prev)), v => v, options);
return () => resource();
}
export function createAsyncStore(fn, options = {}) {
let resource;
let prev = () => !resource || resource.state === "unresolved" ? undefined : unwrap(resource.latest);
[resource] = createResource(() => subFetch(fn, untrack(prev)), v => v, {
...options,
storage: (init) => createDeepSignal(init, options.reconcile)
});
return () => resource();
}
function createDeepSignal(value, options) {
const [store, setStore] = createStore({
value
});
return [
() => store.value,
(v) => {
typeof v === "function" && (v = v());
setStore("value", reconcile(v, options));
return store.value;
}
];
}
// mock promise while hydrating to prevent fetching

@@ -40,5 +65,5 @@ class MockPromise {

}
function subFetch(fn) {
function subFetch(fn, prev) {
if (isServer || !sharedConfig.context)
return fn();
return fn(prev);
const ogFetch = fetch;

@@ -49,3 +74,3 @@ const ogPromise = Promise;

Promise = MockPromise;
return fn();
return fn(prev);
}

@@ -52,0 +77,0 @@ finally {

@@ -1,4 +0,4 @@

export { createAsync } from "./createAsync.js";
export { createAsync, createAsyncStore } from "./createAsync.js";
export { action, useSubmission, useSubmissions, useAction, type Action } from "./action.js";
export { cache, revalidate, type CachedFunction } from "./cache.js";
export { redirect, reload, json } from "./response.js";

@@ -1,4 +0,4 @@

export { createAsync } from "./createAsync.js";
export { createAsync, createAsyncStore } from "./createAsync.js";
export { action, useSubmission, useSubmissions, useAction } from "./action.js";
export { cache, revalidate } from "./cache.js";
export { redirect, reload, json } from "./response.js";
import { isServer, getRequestEvent, createComponent as createComponent$1, delegateEvents, spread, mergeProps as mergeProps$1, template } from 'solid-js/web';
import { getOwner, runWithOwner, createMemo, createContext, onCleanup, useContext, untrack, createSignal, createRenderEffect, on, startTransition, resetErrorBoundaries, createComponent, children, mergeProps, createRoot, Show, getListener, sharedConfig, $TRACK, splitProps, createResource } from 'solid-js';
import { createStore, reconcile } from 'solid-js/store';
import { createStore, reconcile, unwrap } from 'solid-js/store';

@@ -882,4 +882,3 @@ function createBeforeLeave() {

}
function cache(fn, name, options) {
const [store, setStore] = createStore({});
function cache(fn, name) {
// prioritize GET for server functions

@@ -976,5 +975,3 @@ if (fn.GET) fn = fn.GET;

if (error) throw v;
if (isServer) return v;
setStore(key, reconcile(v, options));
return store[key];
return v;
};

@@ -1452,5 +1449,26 @@ }

function createAsync(fn, options) {
const [resource] = createResource(() => subFetch(fn), v => v, options);
let resource;
let prev = () => !resource || resource.state === "unresolved" ? undefined : resource.latest;
[resource] = createResource(() => subFetch(fn, untrack(prev)), v => v, options);
return () => resource();
}
function createAsyncStore(fn, options = {}) {
let resource;
let prev = () => !resource || resource.state === "unresolved" ? undefined : unwrap(resource.latest);
[resource] = createResource(() => subFetch(fn, untrack(prev)), v => v, {
...options,
storage: init => createDeepSignal(init, options.reconcile)
});
return () => resource();
}
function createDeepSignal(value, options) {
const [store, setStore] = createStore({
value
});
return [() => store.value, v => {
typeof v === "function" && (v = v());
setStore("value", reconcile(v, options));
return store.value;
}];
}

@@ -1487,4 +1505,4 @@ // mock promise while hydrating to prevent fetching

}
function subFetch(fn) {
if (isServer || !sharedConfig.context) return fn();
function subFetch(fn, prev) {
if (isServer || !sharedConfig.context) return fn(prev);
const ogFetch = fetch;

@@ -1495,3 +1513,3 @@ const ogPromise = Promise;

Promise = MockPromise;
return fn();
return fn(prev);
} finally {

@@ -1556,2 +1574,2 @@ window.fetch = ogFetch;

export { A, HashRouter, MemoryRouter, Navigate, Route, Router, StaticRouter, mergeSearchString as _mergeSearchString, action, cache, createAsync, createBeforeLeave, createMemoryHistory, createRouter, json, keepDepth, notifyIfNotBlocked, redirect, reload, revalidate, saveCurrentDepth, useAction, useBeforeLeave, useHref, useIsRouting, useLocation, useMatch, useNavigate, useParams, useResolvedPath, useSearchParams, useSubmission, useSubmissions };
export { A, HashRouter, MemoryRouter, Navigate, Route, Router, StaticRouter, mergeSearchString as _mergeSearchString, action, cache, createAsync, createAsyncStore, createBeforeLeave, createMemoryHistory, createRouter, json, keepDepth, notifyIfNotBlocked, redirect, reload, revalidate, saveCurrentDepth, useAction, useBeforeLeave, useHref, useIsRouting, useLocation, useMatch, useNavigate, useParams, useResolvedPath, useSearchParams, useSubmission, useSubmissions };

@@ -9,3 +9,3 @@ {

"license": "MIT",
"version": "0.11.5",
"version": "0.12.0",
"homepage": "https://github.com/solidjs/solid-router#readme",

@@ -12,0 +12,0 @@ "repository": {

@@ -32,3 +32,2 @@ <p>

- [useIsRouting](#useisrouting)
- [useRouteData](#useroutedata)
- [useMatch](#usematch)

@@ -494,3 +493,3 @@ - [useBeforeLeave](#usebeforeleave)

```jsx
const user = createAsync(() => getUser(params.id))
const user = createAsync((currentValue) => getUser(params.id))
```

@@ -679,3 +678,3 @@

By default, Solid Router uses `location.pathname` as route path. You can simply switch to hash mode through the `source` property on `<Router>` component.
By default, Solid Router uses `location.pathname` as route path. You can simply switch to hash mode through using `<HashRouter>`.

@@ -682,0 +681,0 @@ ```jsx

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc