Options
All
  • Public
  • Public/Protected
  • All
Menu

Index

Variables

Const global

global: globalThis = typeof window !== "undefined" ? window : this

Represents the current global object, Window (Browser) / Global (Server)

Const local_storage

local_storage: null | function = global.localStorage? storage(global.localStorage, {event: "storage",event_source: global}): null

Returns a storage Svelte Store with a reactive binding to window.localStorage

NOTE: Only JSON-compatible values are supported

As a minimal example:

import {local_storage} from "svelte-commons/lib/stores/browser";

const store = local_storage("my_string_key", "some default string");

store.subscribe((value) => {
    console.log(value);
}); // Will log any changes to the Store

store.set("a non-default string"); // logs: `a non-default string`

console.log(
    window.localStorage.getItem("svelte-commons.my_string_key")
); // logs: `"a non-default string"`

Const session_storage

session_storage: null | function = global.sessionStorage? storage(global.sessionStorage, {event: "storage",event_source: global}): null

Returns a storage Svelte Store with a reactive binding to window.sessionStorage

NOTE: Only JSON-compatible values are supported

As a minimal example:

import {session_storage} from "svelte-commons/lib/stores/browser";

const store = session_storage("my_string_key", "some default string");

store.subscribe((value) => {
    console.log(value);
}); // Will log any changes to the Store

store.set("a non-default string"); // logs: `a non-default string`

console.log(
    window.sessionStorage.getItem("svelte-commons.my_string_key")
); // logs: `"a non-default string"`

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Type alias with type parameter
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc