1.1.5 • Published 5 years ago

svelte-deep-store v1.1.5

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

GitHub license GitHub issues Twitter

svelte-deep-store

Svelte deep store - react only when specified property of the object was changed.

Usage

import { onDestroy } from 'svelte';
import Store from 'svelte-deep-store';

const state = new Store({ some: 'value', someOther: { nested: 'value' } });

let nestedValue;
onDestroy(
  state.subscribe('someOther.nested', (value) => {
    nestedValue = value;
  })
);

let some;
onDestroy(
  state.subscribeAll(['some', 'someOther'], (which, value) => {
    if (which === 'some') {
      some = value;
    } else if (which === 'someOther') {
      nestedValue = value.nested;
    }
  })
);

state.update('someOther.nested', (currentValue) => {
  return 'new value';
});

onDestroy(
  state.subscribe('some', (value) => {
    state.update('someOther.nested', (oldValue) => {
      return 'nested changed after some changed';
    });
  })
);

let currentState = state.get();
console.log(currentState.some);

onDestroy(state.destroy);

There are also watch and watchAll methods instead of subscribe and subscribeAll which do the same thing. And set is equivalent of update;

1.1.5

5 years ago

1.1.4

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago