Socket
Socket
Sign inDemoInstall

mobx-utils

Package Overview
Dependencies
Maintainers
4
Versions
58
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mobx-utils

Utility functions and common patterns for MobX


Version published
Weekly downloads
45K
decreased by-80.39%
Maintainers
4
Weekly downloads
 
Created

What is mobx-utils?

The mobx-utils package provides a set of utility functions and classes to complement MobX, a state management library for JavaScript applications. These utilities help simplify common patterns and enhance the functionality of MobX.

What are mobx-utils's main functionalities?

fromPromise

The `fromPromise` utility converts a promise into an observable object, allowing you to easily track the state of asynchronous operations within MobX.

const { fromPromise } = require('mobx-utils');
const { observable } = require('mobx');

const fetchData = () => new Promise(resolve => setTimeout(() => resolve('data'), 1000));
const observablePromise = fromPromise(fetchData());

observablePromise.case({
  pending: () => console.log('Loading...'),
  fulfilled: value => console.log('Data:', value),
  rejected: error => console.log('Error:', error)
});

lazyObservable

The `lazyObservable` utility creates an observable that only starts producing values when it is first observed. This is useful for deferring expensive computations or data fetching until necessary.

const { lazyObservable } = require('mobx-utils');

const lazyData = lazyObservable(sink => {
  setTimeout(() => sink('Lazy data'), 1000);
});

lazyData.observe(newValue => console.log('New value:', newValue));

keepAlive

The `keepAlive` utility ensures that a computed value remains active and is not garbage collected, even if there are no observers. This can be useful for maintaining the state of certain computations.

const { keepAlive } = require('mobx-utils');
const { observable, computed } = require('mobx');

const data = observable.box(1);
const computedValue = computed(() => data.get() * 2);

keepAlive(computedValue);

console.log(computedValue.get()); // 2
data.set(2);
console.log(computedValue.get()); // 4

Other packages similar to mobx-utils

Keywords

FAQs

Package last updated on 25 Mar 2023

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc