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

mobx-utils

Package Overview
Dependencies
Maintainers
1
Versions
59
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

  • 5.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
215K
decreased by-16.94%
Maintainers
1
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 04 Jun 2018

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