Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

otrie

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

otrie

Observable Path Trie Store

  • 1.1.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
390
increased by47.73%
Maintainers
1
Weekly downloads
 
Created
Source

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.

Keywords

FAQs

Package last updated on 02 Jan 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc