All Projects → bryanmylee → svelte-previous

bryanmylee / svelte-previous

Licence: other
A Svelte store that remembers previous values

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to svelte-previous

esbuild-svelte
An esbuild plugin to compile Svelte components
Stars: ✭ 163 (+254.35%)
Mutual labels:  svelte
eleventy-plugin-svelte
Eleventy plugin to support svelte templates
Stars: ✭ 40 (-13.04%)
Mutual labels:  svelte
svelte-form
JSON Schema form for Svelte v3
Stars: ✭ 47 (+2.17%)
Mutual labels:  svelte
svelte-local-storage-store
Adds pub/sub to local storage.
Stars: ✭ 194 (+321.74%)
Mutual labels:  svelte
turbosvelte
A SvelteKit monorepo starter project powered by Turborepo!
Stars: ✭ 47 (+2.17%)
Mutual labels:  svelte
svelte-typescript
Typescript monorepo for Svelte v3 (preprocess, template, types)
Stars: ✭ 214 (+365.22%)
Mutual labels:  svelte
hstdb
Better history management for zsh. Based on ideas from https://github.com/larkery/zsh-histdb.
Stars: ✭ 25 (-45.65%)
Mutual labels:  history
jRouting
Great routing mechanism for client-side web applications
Stars: ✭ 16 (-65.22%)
Mutual labels:  history
awesome
A curated list of delightful developers resources.
Stars: ✭ 13 (-71.74%)
Mutual labels:  svelte
ItroublveTSC
Official Source of ItroublveTSC, totally open source. No virus or anything. Feel free to have a look :)
Stars: ✭ 82 (+78.26%)
Mutual labels:  history
svelteify
📲 Customizable and dependencies-less Material components with Svelte
Stars: ✭ 43 (-6.52%)
Mutual labels:  svelte
svelte-pagination
Example of a pagination component in Svelte
Stars: ✭ 15 (-67.39%)
Mutual labels:  svelte
svelte-component-library-template
A base for building Svelte component library.
Stars: ✭ 62 (+34.78%)
Mutual labels:  svelte
chrome-extension-svelte-typescript-boilerplate
Boilerplate for Chrome Extension Svelte Typescript project
Stars: ✭ 35 (-23.91%)
Mutual labels:  svelte
tabler-icons-svelte
A library of SVG Svelte components for Tabler Icons.
Stars: ✭ 50 (+8.7%)
Mutual labels:  svelte
History-Disabler-for-Chromium
Disable all browsing history in Chromium browsers.
Stars: ✭ 29 (-36.96%)
Mutual labels:  history
svelte-intersection-observer
Detect if an element is in the viewport using the Intersection Observer API
Stars: ✭ 151 (+228.26%)
Mutual labels:  svelte
microzord
Simple and powerful Micro Frontends framework
Stars: ✭ 81 (+76.09%)
Mutual labels:  svelte
pushu.ps
A simple Svelte app that let's you track your daily push-ups routine
Stars: ✭ 41 (-10.87%)
Mutual labels:  svelte
svelte-persistent-store
A Svelte store that keep its value through pages and reloads
Stars: ✭ 111 (+141.3%)
Mutual labels:  svelte

svelte-previous-banner

svelte-previous

npm version npm downloads license build coverage size

Svelte stores that remember previous values!

This allows us to perform actions that depend on previous values, such as transitions between old and new values.

Installation

$ npm i -D svelte-previous

Since Svelte automatically bundles all required dependencies, you only need to install this package as a dev dependency with the -D flag.

Demo

Visit the REPL demo.

Usage

withPrevious accepts an initial value, and returns a tuple comprising a Writable and a Readable store.

<script>
  import { withPrevious } from 'svelte-previous';

  export let name;
  // current is writable, while previous is read-only.
  const [currentName, previousName] = withPrevious(0);
  // To update the values, assign to the writable store.
  $: $currentName = name;
</script>

transition from {$previousName} to {$currentName}.

Options

withPrevious takes an options object as its second argument.

numToTrack: number

By default, withPrevious tracks one previous value.

To track more than one value, set numToTrack.

<script>
  const [current, prev1, prev2] = withPrevious(0, { numToTrack: 2 });
</script>

from {$prev2} to {$prev1} to {$current}.

requireChange: boolean

Due to how reactivity is handled in Svelte, some assignments may assign the same value multiple times to a variable. Therefore, to prevent a single value from overwriting all previous values, a change in value is required before the current and previous values are updated.

Set requireChange = false to change this behaviour.

<script>
  const [current, previous] = withPrevious(0, { requireChange: false });
</script>

isEqual: (a: T, b: T) => boolean

By default, equality is determined with the === operator. However, === only checks equality by reference when comparing objects.

Provide a custom isEqual function to compare objects.

<script>
  const [current, previous] = withPrevious(0, {
    isEqual: (a, b) => a.name === b.name && a.age === b.age,
  });
</script>

It is also possible to use lodash.isequal.

<script>
  import isEqual from 'lodash.isequal';

  const [current, previous] = withPrevious(0, {
    isEqual: isEqual,
  });
</script>
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].