Socket
Socket
Sign inDemoInstall

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 - npm Package Compare versions

Comparing version 3.2.0 to 3.2.1

lib/when-async.d.ts

5

CHANGELOG.md

@@ -0,1 +1,6 @@

# 3.2.1
* Fixed issue where `whenAsync` was not exposed correctly.
* Added `timeout` parameter to `whenAsync`
# 3.2.0

@@ -2,0 +7,0 @@

1

lib/mobx-utils.d.ts

@@ -13,1 +13,2 @@ export * from "./from-promise";

export * from "./async-action";
export * from "./when-async";

@@ -13,1 +13,2 @@ export * from "./from-promise";

export * from "./async-action";
export * from "./when-async";

@@ -931,2 +931,30 @@ import { Atom, action, autorun, autorunAsync, computed, extendShallowObservable, extras, isAction, isObservableArray, isObservableMap, isObservableObject, observable, runInAction, when } from 'mobx';

export { PENDING, FULFILLED, REJECTED, fromPromise, isPromiseBasedObservable, lazyObservable, fromResource, toStream, fromStream, createViewModel, whenWithTimeout, keepAlive, queueProcessor, chunkProcessor, now, NOOP, IDENTITY, invariant, deprecated, asyncAction, createAsyncActionGenerator };
/**
* Like normal `when`, except that this `when` will return a promise that resolves when the expression becomes truthy
*
* @example
* await whenAsync(() => !state.someBoolean)
*
* @export
* @param {() => boolean} fn see when, the expression to await
* @param {number} timeout maximum amount of time to wait, before the promise rejects
* @returns Promise for when an observable eventually matches some condition. Rejects if timeout is provided and has expired
*/
function whenAsync(fn, timeout) {
if (timeout === void 0) { timeout = 0; }
return new Promise(function (resolve, reject) {
var timeoutHandle;
var disposer = when(fn, function () {
if (timeout > 0)
clearTimeout(timeoutHandle);
resolve();
});
if (timeout > 0)
setTimeout(function () {
disposer();
reject(new Error("TIMEOUT"));
}, timeout);
});
}
export { PENDING, FULFILLED, REJECTED, fromPromise, isPromiseBasedObservable, lazyObservable, fromResource, toStream, fromStream, createViewModel, whenWithTimeout, keepAlive, queueProcessor, chunkProcessor, now, NOOP, IDENTITY, invariant, deprecated, asyncAction, createAsyncActionGenerator, whenAsync };

@@ -935,2 +935,30 @@ (function (global, factory) {

/**
* Like normal `when`, except that this `when` will return a promise that resolves when the expression becomes truthy
*
* @example
* await whenAsync(() => !state.someBoolean)
*
* @export
* @param {() => boolean} fn see when, the expression to await
* @param {number} timeout maximum amount of time to wait, before the promise rejects
* @returns Promise for when an observable eventually matches some condition. Rejects if timeout is provided and has expired
*/
function whenAsync(fn, timeout) {
if (timeout === void 0) { timeout = 0; }
return new Promise(function (resolve, reject) {
var timeoutHandle;
var disposer = mobx.when(fn, function () {
if (timeout > 0)
clearTimeout(timeoutHandle);
resolve();
});
if (timeout > 0)
setTimeout(function () {
disposer();
reject(new Error("TIMEOUT"));
}, timeout);
});
}
exports.PENDING = PENDING;

@@ -957,2 +985,3 @@ exports.FULFILLED = FULFILLED;

exports.createAsyncActionGenerator = createAsyncActionGenerator;
exports.whenAsync = whenAsync;

@@ -959,0 +988,0 @@ Object.defineProperty(exports, '__esModule', { value: true });

2

package.json
{
"name": "mobx-utils",
"version": "3.2.0",
"version": "3.2.1",
"description": "Utility functions and common patterns for MobX",

@@ -5,0 +5,0 @@ "main": "mobx-utils.umd.js",

@@ -332,6 +332,2 @@ # MobX-utils

MobX normally suspends any computed value that is not in use by any reaction,
and lazily re-evaluates the expression if needed outside a reaction while not in use.
`keepAlive` marks a computed value as always in use, meaning that it will always fresh, but never disposed automatically.
**Parameters**

@@ -341,4 +337,3 @@

- `_2`
- `target` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** an object that has a computed property, created by `@computed` or `extendObservable`
- `property` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** the name of the property to keep alive
- `computedValue` **IComputedValue<any>** created using the `computed` function

@@ -348,7 +343,8 @@ **Examples**

```javascript
const obj = observable({
number: 3,
doubler: function() { return this.number * 2 }
})
const stop = keepAlive(obj, "doubler")
const number = observable(3)
const doubler = computed(() => number.get() * 2)
const stop = keepAlive(doubler)
// doubler will now stay in sync reactively even when there are no further observers
stop()
// normal behavior, doubler results will be recomputed if not observed but needed, but lazily
```

@@ -360,2 +356,6 @@

MobX normally suspends any computed value that is not in use by any reaction,
and lazily re-evaluates the expression if needed outside a reaction while not in use.
`keepAlive` marks a computed value as always in use, meaning that it will always fresh, but never disposed automatically.
**Parameters**

@@ -365,3 +365,4 @@

- `_2`
- `computedValue` **IComputedValue<any>** created using the `computed` function
- `target` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** an object that has a computed property, created by `@computed` or `extendObservable`
- `property` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** the name of the property to keep alive

@@ -371,8 +372,7 @@ **Examples**

```javascript
const number = observable(3)
const doubler = computed(() => number.get() * 2)
const stop = keepAlive(doubler)
// doubler will now stay in sync reactively even when there are no further observers
stop()
// normal behavior, doubler results will be recomputed if not observed but needed, but lazily
const obj = observable({
number: 3,
doubler: function() { return this.number * 2 }
})
const stop = keepAlive(obj, "doubler")
```

@@ -539,1 +539,18 @@

Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)**
## whenAsync
Like normal `when`, except that this `when` will return a promise that resolves when the expression becomes truthy
**Parameters**
- `fn`
- `timeout` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** maximum amount of time to wait, before the promise rejects
**Examples**
```javascript
await whenAsync(() => !state.someBoolean)
```
Returns **any** Promise for when an observable eventually matches some condition. Rejects if timeout is provided and has expired
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