Options
All
  • Public
  • Public/Protected
  • All
Menu

Index

Type aliases

Functions

Type aliases

ICloner

ICloner<T>: function

Represents the "cloner" function that returns a clone of the input

Type parameters

  • T

Type declaration

    • (value: T): T
    • Parameters

      • value: T

      Returns T

Functions

clone_value

  • clone_value(value: any): any
  • Returns a shallow clone of the value object

    NOTE: Only object or Array types are supported

    Parameters

    • value: any

    Returns any

immutable

  • Returns a Readable / Writable Svelte Store, that clones the stored value before every I/O operation, to prevent untracked data mutations

    NOTE: If a non-Store value is passed as store, then it will be wrapped in a Writable Store

    NOTE: By default, immutable can ONLY shallow clone Objects and Arrays. If deep or specific cloning is needed, pass a clone function

    For a simple example, in making a Readable Store immutable:

    import {readable} from "svelte/store";
    import {immutable} from "svelte-commons/lib/stores/shared";
    
    const initial_value = {key: "value"};
    
    const readable_store = readable(initial_value);
    
    const store = immutable(readable_store);
    
    store.subscribe((value) => {
        console.log({initial_value, value});
        console.log(value === initial_value);
    }); // logs: `false`

    Another simple example, but this time making a Writable Store immutable:

    import {derived, writable} from "svelte/store";
    import {immutable} from "svelte-commons/lib/stores/shared";
    
    const initial_value = {key: "value"};
    
    const writable_store = writable(initial_value);
    
    const store = immutable(writable_store);
    
    // NOTE: A `derived` Store is used here for simpler looking code
    const derived_store = derived([writable_store, store], ([$writable, $store]) => {
        console.log({$writable, $store});
        console.log($writable === $store);
    });
    
    // NOTE: This subscription is just so the `derived` callback starts running
    derived_store.subscribe(() => {}); // logs: `false`
    
    store.set({key: "not a value!"}); // logs: `false`

    Type parameters

    • T

    Parameters

    Returns Readable<T> | Writable<T>

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