Socket
Socket
Sign inDemoInstall

sswr

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sswr - npm Package Compare versions

Comparing version 1.6.4 to 1.7.0

3

dist/sswr.es.js

@@ -132,3 +132,2 @@ var __defProp = Object.defineProperty;

onMount(() => {
data.set(this.get(this.resolveKey(key)));
const onData = (d) => {

@@ -140,3 +139,3 @@ error.set(void 0);

unsubscribe = this.use(key, onData, onError, __spreadValues({
loadInitialCache: false
loadInitialCache: true
}, options)).unsubscribe;

@@ -143,0 +142,0 @@ });

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

var J=Object.defineProperty;var E=Object.getOwnPropertySymbols;var N=Object.prototype.hasOwnProperty,Q=Object.prototype.propertyIsEnumerable;var O=(t,i,o)=>i in t?J(t,i,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[i]=o,W=(t,i)=>{for(var o in i||(i={}))N.call(i,o)&&O(t,o,i[o]);if(E)for(var o of E(i))Q.call(i,o)&&O(t,o,i[o]);return t};(function(t,i){typeof exports=="object"&&typeof module!="undefined"?i(exports,require("swrev"),require("svelte")):typeof define=="function"&&define.amd?define(["exports","swrev","svelte"],i):(t=typeof globalThis!="undefined"?globalThis:t||self,i(t.sswr={},t.swrev,t.svelte))})(this,function(t,i,o){"use strict";function h(){}function D(e){return e()}function K(e){e.forEach(D)}function j(e){return typeof e=="function"}function M(e,n){return e!=e?n==n:e!==n||e&&typeof e=="object"||typeof e=="function"}function T(e,...n){if(e==null)return h;const s=e.subscribe(...n);return s.unsubscribe?()=>s.unsubscribe():s}Promise.resolve();const w=[];function z(e,n){return{subscribe:y(e,n).subscribe}}function y(e,n=h){let s;const r=new Set;function l(a){if(M(e,a)&&(e=a,s)){const b=!w.length;for(const u of r)u[1](),w.push(u,e);if(b){for(let u=0;u<w.length;u+=2)w[u][0](w[u+1]);w.length=0}}}function d(a){l(a(e))}function S(a,b=h){const u=[a,b];return r.add(u),r.size===1&&(s=n(l)||h),a(e),()=>{r.delete(u),r.size===0&&(s(),s=null)}}return{set:l,update:d,subscribe:S}}function _(e,n,s){const r=!Array.isArray(e),l=r?[e]:e,d=n.length<2;return z(s,S=>{let a=!1;const b=[];let u=0,g=h;const c=()=>{if(u)return;g();const f=n(r?b[0]:b,S);d?S(f):g=j(f)?f:h},v=l.map((f,R)=>T(f,H=>{b[R]=H,u&=~(1<<R),a&&c()},()=>{u|=1<<R}));return a=!0,c(),function(){K(v),g()}})}class q extends i.SWR{useSWR(n,s){let r;const l=y(void 0,()=>()=>r==null?void 0:r()),d=y(void 0,()=>()=>r==null?void 0:r());o.onMount(()=>{l.set(this.get(this.resolveKey(n)));const c=f=>{d.set(void 0),l.set(f)},v=f=>d.set(f);r=this.use(n,c,v,W({loadInitialCache:!1},s)).unsubscribe}),o.onDestroy(()=>r==null?void 0:r());const S=(c,v)=>this.mutate(this.resolveKey(n),c,W({revalidateOptions:s},v)),a=c=>this.revalidate(this.resolveKey(n),W(W({},s),c)),b=c=>this.clear(this.resolveKey(n),c),u=_([l,d],([c,v])=>c===void 0&&v===void 0),g=_([l,d],([c,v])=>c!==void 0&&v===void 0);return{data:l,error:d,mutate:S,revalidate:a,clear:b,isLoading:u,isValid:g}}}const m=e=>new q(e);t.swr=m();const A=e=>(t.swr=m(e),t.swr),P=(e,n)=>t.swr.subscribe(e,n),C=(e,n)=>t.swr.subscribeErrors(e,n),I=e=>t.swr.get(e),L=e=>t.swr.getOrWait(e),V=(e,n,s,r)=>t.swr.use(e,n,s,r),$=(e,n)=>t.swr.useSWR(e,n),B=(e,n,s)=>t.swr.mutate(e,n,s),F=(e,n)=>t.swr.revalidate(e,n),G=(e,n)=>t.swr.clear(e,n);t.SSWR=q,t.clear=G,t.createDefaultSWR=A,t.createSWR=m,t.get=I,t.getOrWait=L,t.mutate=B,t.revalidate=F,t.subscribe=P,t.subscribeErrors=C,t.use=V,t.useSWR=$,Object.defineProperty(t,"__esModule",{value:!0}),t[Symbol.toStringTag]="Module"});
var J=Object.defineProperty;var E=Object.getOwnPropertySymbols;var N=Object.prototype.hasOwnProperty,Q=Object.prototype.propertyIsEnumerable;var O=(t,u,o)=>u in t?J(t,u,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[u]=o,g=(t,u)=>{for(var o in u||(u={}))N.call(u,o)&&O(t,o,u[o]);if(E)for(var o of E(u))Q.call(u,o)&&O(t,o,u[o]);return t};(function(t,u){typeof exports=="object"&&typeof module!="undefined"?u(exports,require("swrev"),require("svelte")):typeof define=="function"&&define.amd?define(["exports","swrev","svelte"],u):(t=typeof globalThis!="undefined"?globalThis:t||self,u(t.sswr={},t.swrev,t.svelte))})(this,function(t,u,o){"use strict";function w(){}function D(e){return e()}function j(e){e.forEach(D)}function K(e){return typeof e=="function"}function M(e,n){return e!=e?n==n:e!==n||e&&typeof e=="object"||typeof e=="function"}function T(e,...n){if(e==null)return w;const s=e.subscribe(...n);return s.unsubscribe?()=>s.unsubscribe():s}Promise.resolve();const h=[];function z(e,n){return{subscribe:y(e,n).subscribe}}function y(e,n=w){let s;const r=new Set;function l(a){if(M(e,a)&&(e=a,s)){const b=!h.length;for(const i of r)i[1](),h.push(i,e);if(b){for(let i=0;i<h.length;i+=2)h[i][0](h[i+1]);h.length=0}}}function d(a){l(a(e))}function S(a,b=w){const i=[a,b];return r.add(i),r.size===1&&(s=n(l)||w),a(e),()=>{r.delete(i),r.size===0&&(s(),s=null)}}return{set:l,update:d,subscribe:S}}function _(e,n,s){const r=!Array.isArray(e),l=r?[e]:e,d=n.length<2;return z(s,S=>{let a=!1;const b=[];let i=0,W=w;const c=()=>{if(i)return;W();const f=n(r?b[0]:b,S);d?S(f):W=K(f)?f:w},v=l.map((f,R)=>T(f,H=>{b[R]=H,i&=~(1<<R),a&&c()},()=>{i|=1<<R}));return a=!0,c(),function(){j(v),W()}})}class q extends u.SWR{useSWR(n,s){let r;const l=y(void 0,()=>()=>r==null?void 0:r()),d=y(void 0,()=>()=>r==null?void 0:r());o.onMount(()=>{const c=f=>{d.set(void 0),l.set(f)},v=f=>d.set(f);r=this.use(n,c,v,g({loadInitialCache:!0},s)).unsubscribe}),o.onDestroy(()=>r==null?void 0:r());const S=(c,v)=>this.mutate(this.resolveKey(n),c,g({revalidateOptions:s},v)),a=c=>this.revalidate(this.resolveKey(n),g(g({},s),c)),b=c=>this.clear(this.resolveKey(n),c),i=_([l,d],([c,v])=>c===void 0&&v===void 0),W=_([l,d],([c,v])=>c!==void 0&&v===void 0);return{data:l,error:d,mutate:S,revalidate:a,clear:b,isLoading:i,isValid:W}}}const m=e=>new q(e);t.swr=m();const A=e=>(t.swr=m(e),t.swr),P=(e,n)=>t.swr.subscribe(e,n),C=(e,n)=>t.swr.subscribeErrors(e,n),I=e=>t.swr.get(e),L=e=>t.swr.getOrWait(e),V=(e,n,s,r)=>t.swr.use(e,n,s,r),$=(e,n)=>t.swr.useSWR(e,n),B=(e,n,s)=>t.swr.mutate(e,n,s),F=(e,n)=>t.swr.revalidate(e,n),G=(e,n)=>t.swr.clear(e,n);t.SSWR=q,t.clear=G,t.createDefaultSWR=A,t.createSWR=m,t.get=I,t.getOrWait=L,t.mutate=B,t.revalidate=F,t.subscribe=P,t.subscribeErrors=C,t.use=V,t.useSWR=$,Object.defineProperty(t,"__esModule",{value:!0}),t[Symbol.toStringTag]="Module"});
{
"name": "sswr",
"version": "1.6.4",
"version": "1.7.0",
"description": "Svelte stale while revalidate (SWR) data fetching strategy",

@@ -5,0 +5,0 @@ "repository": "github.com/ConsoleTVs/sswr",

@@ -18,2 +18,3 @@ # SSWR (Svelte Stale While Revalidate)

- [Clear Cache](#clear-cache)
- [Using with SvelteKit SSR](#using-with-sveltekit-ssr)
- [Contributors](#contributors)

@@ -383,2 +384,52 @@

## Using with SvelteKit SSR
SvelteKit allows you to fetch data on the backend. This allows you to combine SSR (where your data is present in the HTML) with the live updating that this package provides.
Here is an example of how to implement the [Getting Started](#getting-started) example with support for SSR. In this example, we have disabled the
revalidation on the client, althought it is also possible to re-hydrate the
information on it if needed.
```svelte
<script lang="ts" context="module">
import type { Load } from '@sveltejs/kit';
const url = 'https://jsonplaceholder.typicode.com/posts';
export const load: Load = async ({ fetch }) => {
const response = await fetch(url);
return {
props: {
initialData: await response.json()
}
};
};
</script>
<script lang="ts">
import { useSWR } from 'sswr';
interface Post {
id: number;
title: string;
body: string;
}
export let initialData: Post[];
const { data: posts } = useSWR<Post[]>(url, {
initialData,
revalidateOnStart: false
});
</script>
{#if $posts}
{#each $posts as post (post.id)}
<h1>{post.title}</h1>
<p>{post.body}</p>
{/each}
{/if}
```
## Contributors

@@ -388,1 +439,2 @@

- [Len Boyette](https://github.com/kevlened)
- [Stanislav Khromov](https://github.com/khromov)
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