1.1.3 • Published 4 months ago

otrie v1.1.3

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
4 months ago

Observable Path Trie Store

TrieStore is a RxJS-observable path tree store.

It keeps an instance of RxJS Subject associated with every monitored field in the state object and notifies observers when the node value or any child node value changes.

import {TrieStore} from 'otrie';

const initialState = {
    users: {
        user1: {wants: 'apple'},
        user2: {wants: 'orange'},
    }
};
const store = new TrieStore(initialState);
const userLevelObserver = store.observe(['users']);
const user1LevelObserver = store.observe(['users', 'user1']);
const user1WantsLevelObserver = store.observe(['users', 'user1', 'wants']);

// When the store is constructed first, it emits an initial state to all observers.
expect(await firstValueFrom(userLevelObserver)).toEqual({user1: {wants: 'apple'}, user2: {wants: 'orange'}});
expect(await firstValueFrom(user1LevelObserver)).toEqual({wants: 'apple'});
expect(await firstValueFrom(user1WantsLevelObserver)).toBe('apple');

// When a tree node value is changed all parent node observers are notified.
store.set(['users', 'user1', 'wants'], 'carrot');
expect(await firstValueFrom(userLevelObserver)).toEqual({user1: {wants: 'carrot'}, user2: {wants: 'orange'}});
expect(await firstValueFrom(user1LevelObserver)).toEqual({wants: 'carrot'});
expect(await firstValueFrom(user1WantsLevelObserver)).toBe('carrot');

See sources and related unit tests for details.

1.1.3

4 months ago

1.1.2

6 months ago

1.1.1

8 months ago

1.1.0

8 months ago

1.0.0

9 months ago

0.9.4

9 months ago

0.9.3

9 months ago

0.9.2

9 months ago

0.9.1

9 months ago

0.9.0

9 months ago