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 2.0.1 to 2.0.2

7

CHANGELOG.md

@@ -0,1 +1,8 @@

# 2.0.2
* Fixed #44, lazyObservable not accepting an array as initial value.
* ViewModel methods are now automatically bound, see #59, by @tekacs
* Fixed stream issue regarding disposing already completed streams, see #57, by @rkorohu
* Improved typings of lazy observables, see #38 by @jamiewinder
# 2.0.1

@@ -2,0 +9,0 @@

12

lib/create-view-model.js

@@ -16,2 +16,5 @@ "use strict";

this.localValues = mobx_1.observable.map({});
this.isPropertyDirty = function (key) {
return _this.localValues.has(key);
};
utils_1.invariant(mobx_1.isObservableObject(model), "createViewModel expects an observable object");

@@ -44,5 +47,2 @@ Object.keys(model).forEach(function (key) {

});
ViewModel.prototype.isPropertyDirty = function (key) {
return this.localValues.has(key);
};
ViewModel.prototype.submit = function () {

@@ -78,9 +78,9 @@ var _this = this;

__decorate([
mobx_1.action
mobx_1.action.bound
], ViewModel.prototype, "submit", null);
__decorate([
mobx_1.action
mobx_1.action.bound
], ViewModel.prototype, "reset", null);
__decorate([
mobx_1.action
mobx_1.action.bound
], ViewModel.prototype, "resetProperty", null);

@@ -87,0 +87,0 @@ /**

@@ -62,1 +62,7 @@ export declare type PromiseState = "pending" | "fulfilled" | "rejected";

export declare function fromPromise<T>(promise: PromiseLike<T>, initialValue?: T): IPromiseBasedObservable<T>;
/**
* Returns true if the provided value is a promise-based observable.
* @param value any
* @returns {boolean}
*/
export declare function isPromiseBasedObservable(value: any): value is IPromiseBasedObservable<any>;

@@ -105,1 +105,10 @@ "use strict";

exports.fromPromise = fromPromise;
/**
* Returns true if the provided value is a promise-based observable.
* @param value any
* @returns {boolean}
*/
function isPromiseBasedObservable(value) {
return value instanceof PromiseBasedObservable;
}
exports.isPromiseBasedObservable = isPromiseBasedObservable;

@@ -8,3 +8,3 @@ import { IDisposer } from "./utils";

/**
* `fromResource` creates an observable which current state can be inspected using `.current()`,
* `fromResource` creates an observable whose current state can be inspected using `.current()`,
* and which can be kept in sync with some external datasource that can be subscribed to.

@@ -11,0 +11,0 @@ *

@@ -5,3 +5,3 @@ "use strict";

/**
* `fromResource` creates an observable which current state can be inspected using `.current()`,
* `fromResource` creates an observable whose current state can be inspected using `.current()`,
* and which can be kept in sync with some external datasource that can be subscribed to.

@@ -8,0 +8,0 @@ *

@@ -0,4 +1,9 @@

export interface ILazyObservable<T> {
current(): T;
refresh(): T;
reset(): T;
}
/**
* `lazyObservable` creates an observable around a `fetch` method that will not be invoked
* util the observable is needed the first time.
* until the observable is needed the first time.
* The fetch method receives a `sink` callback which can be used to replace the

@@ -34,6 +39,2 @@ * current value of the lazyObservable. It is allowed to call `sink` multiple times

*/
export declare function lazyObservable<T>(fetch: (sink: (newValue: T) => void) => void, initialValue?: T, modifier?: (_: any) => any): {
current(): T;
refresh(): T;
reset(): T;
};
export declare function lazyObservable<T>(fetch: (sink: (newValue: T) => void) => void, initialValue?: T, modifier?: (_: any) => any): ILazyObservable<T>;

@@ -6,3 +6,3 @@ "use strict";

* `lazyObservable` creates an observable around a `fetch` method that will not be invoked
* util the observable is needed the first time.
* until the observable is needed the first time.
* The fetch method receives a `sink` callback which can be used to replace the

@@ -42,3 +42,3 @@ * current value of the lazyObservable. It is allowed to call `sink` multiple times

var started = false;
var value = mobx_1.observable(modifier(initialValue));
var value = mobx_1.observable.shallowBox(modifier(initialValue));
var currentFnc = function () {

@@ -45,0 +45,0 @@ if (!started) {

@@ -12,3 +12,3 @@ /**

*
* Countdown example: http://jsbin.com/roqesit/1/edit?js,output
* Countdown example: https://jsfiddle.net/mweststrate/na0qdmkw/
*

@@ -15,0 +15,0 @@ * @example

@@ -15,3 +15,3 @@ "use strict";

*
* Countdown example: http://jsbin.com/roqesit/1/edit?js,output
* Countdown example: https://jsfiddle.net/mweststrate/na0qdmkw/
*

@@ -18,0 +18,0 @@ * @example

@@ -69,3 +69,5 @@ "use strict";

StreamListener.prototype.dispose = function () {
this.subscription.unsubscribe();
if (this.subscription) {
this.subscription.unsubscribe();
}
};

@@ -76,3 +78,2 @@ StreamListener.prototype.next = function (value) {

StreamListener.prototype.complete = function () {
this.subscription.unsubscribe();
this.dispose();

@@ -79,0 +80,0 @@ };

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

!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("mobx")):"function"==typeof define&&define.amd?define(["mobx"],t):"object"==typeof exports?exports.mobxUtils=t(require("mobx")):e.mobxUtils=t(e.mobx)}(this,function(e){return function(e){function t(n){if(r[n])return r[n].exports;var o=r[n]={exports:{},id:n,loaded:!1};return e[n].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var r={};return t.m=e,t.c=r,t.p="",t(0)}([function(e,t,r){"use strict";function n(e){for(var r in e)t.hasOwnProperty(r)||(t[r]=e[r])}n(r(6)),n(r(9)),n(r(3)),n(r(11)),n(r(5)),n(r(7)),n(r(8)),n(r(12)),n(r(4)),n(r(10)),n(r(2))},function(t,r){t.exports=e},function(e,t){"use strict";function r(e,t){if(void 0===t&&(t="Illegal state"),!e)throw new Error("[mobx-utils] "+t)}function n(e){o.indexOf(e)===-1&&(o.push(e),console.error("[mobx-utils] Deprecated: "+e))}t.NOOP=function(){},t.IDENTITY=function(e){return e},t.invariant=r;var o=[];t.deprecated=n},function(e,t,r){"use strict";function n(e,t,r){void 0===t&&(t=i.NOOP),void 0===r&&(r=void 0);var n=!1,u=!1,s=r,c=function(){n&&(n=!1,t())},a=new o.Atom("ResourceBasedObservable",function(){i.invariant(!n&&!u),n=!0,e(function(e){o.extras.allowStateChanges(!0,function(){s=e,a.reportChanged()})})},c);return{current:function(){i.invariant(!u,"subscribingObservable has already been disposed");var e=a.reportObserved();return e||n||console.warn("Called `get` of an subscribingObservable outside a reaction. Current value will be returned but no new subscription has started"),s},dispose:function(){u=!0,c()},isAlive:function(){return n}}}var o=r(1),i=r(2);t.fromResource=n},function(e,t,r){"use strict";function n(e,t,r,n){if(void 0===r&&(r=0),void 0===n&&(n=0),!o.isObservableArray(e))throw new Error("Expected observable array as first argument");o.isAction(t)||(t=o.action("chunkProcessor",t));var i=function(){for(var r=function(){var r=0===n?e.length:Math.min(e.length,n),i=e.slice(0,r);o.runInAction(function(){return e.splice(0,r)}),t(i)};e.length>0;)r()};return r>0?o.autorunAsync(i,r):o.autorun(i)}var o=r(1);t.chunkProcessor=n},function(e,t,r){"use strict";function n(e){return new c(e)}var o=this&&this.__decorate||function(e,t,r,n){var o,i=arguments.length,u=i<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)u=Reflect.decorate(e,t,r,n);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(u=(i<3?o(u):i>3?o(t,r,u):o(t,r))||u);return i>3&&u&&Object.defineProperty(t,r,u),u},i=r(1),u=r(2),s=["model","reset","submit","isDirty","isPropertyDirty"],c=function(){function e(e){var t=this;this.model=e,this.localValues=i.observable.map({}),u.invariant(i.isObservableObject(e),"createViewModel expects an observable object"),Object.keys(e).forEach(function(e){u.invariant(s.indexOf(e)===-1,"The propertyname "+e+" is reserved and cannot be used with viewModels"),Object.defineProperty(t,e,{enumerable:!0,configurable:!0,get:function(){return t.isPropertyDirty(e)?t.localValues.get(e):t.model[e]},set:i.action(function(r){(t.isPropertyDirty(e)||r!==t.model[e])&&t.localValues.set(e,r)})})})}return Object.defineProperty(e.prototype,"isDirty",{get:function(){return this.localValues.size>0},enumerable:!0,configurable:!0}),e.prototype.isPropertyDirty=function(e){return this.localValues.has(e)},e.prototype.submit=function(){var e=this;this.localValues.keys().forEach(function(t){var r=e.localValues.get(t),n=e.model[t];i.isObservableArray(n)?n.replace(r):i.isObservableMap(n)?(n.clear(),n.merge(r)):e.model[t]=r}),this.localValues.clear()},e.prototype.reset=function(){this.localValues.clear()},e.prototype.resetProperty=function(e){this.localValues.delete(e)},e}();o([i.computed],c.prototype,"isDirty",null),o([i.action],c.prototype,"submit",null),o([i.action],c.prototype,"reset",null),o([i.action],c.prototype,"resetProperty",null),t.createViewModel=n},function(e,t,r){"use strict";function n(e,t){return void 0===t&&(t=void 0),new u(e,t)}var o=r(1),i=r(2);t.PENDING="pending",t.FULFILLED="fulfilled",t.REJECTED="rejected";var u=function(){function e(e,r){void 0===r&&(r=void 0);var n=this;this.promise=e,this._state=o.observable(t.PENDING),this._reason=o.observable.shallowBox(void 0),this._observable=o.observable.box(r),e.then(o.action("observableFromPromise-resolve",function(e){n._observable.set(e),n._state.set("fulfilled")}),o.action("observableFromPromise-reject",function(e){n._reason.set(e),n._observable.set(e),n._state.set("rejected")}))}return Object.defineProperty(e.prototype,"value",{get:function(){return this._observable.get()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"state",{get:function(){return this._state.get()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"reason",{get:function(){return i.deprecated("In `fromPromise`: `.reason` is deprecated, use `.value` instead"),this._reason.get()},enumerable:!0,configurable:!0}),e.prototype.case=function(e){switch(this.state){case"pending":return e.pending&&e.pending();case"rejected":return e.rejected&&e.rejected(this.value);case"fulfilled":return e.fulfilled&&e.fulfilled(this.value)}},e}();t.fromPromise=n},function(e,t,r){"use strict";function n(e,t,r,n){void 0===r&&(r=1e4),void 0===n&&(n=function(){});var i=!1,u=setTimeout(function(){i||(s(),n())},r),s=o.when(e,function(){i=!0,clearTimeout(u),t()});return function(){clearTimeout(u),s()}}var o=r(1);t.whenWithTimeout=n},function(e,t,r){"use strict";function n(e,t){var r=o.extras.getAtom(e,t);if(!r)throw new Error("No computed provided, please provide an object created with `computed(() => expr)` or an object + property name");return r.observe(function(){})}var o=r(1);t.keepAlive=n},function(e,t,r){"use strict";function n(e,t,r){void 0===t&&(t=void 0),void 0===r&&(r=o.IDENTITY);var n=!1,u=i.observable(r(t)),s=function(){return n||(n=!0,e(function(e){i.extras.allowStateChanges(!0,function(){u.set(e)})})),u.get()},c=i.action("lazyObservable-reset",function(){return u.set(t),u.get()});return{current:s,refresh:function(){return n?(n=!1,s()):u.get()},reset:function(){return c()}}}var o=r(2),i=r(1);t.lazyObservable=n},function(e,t,r){"use strict";function n(e){return void 0===e&&(e=1e3),s[e]||("number"==typeof e?s[e]=o(e):s[e]=i()),s[e].current()}function o(e){var t;return u.fromResource(function(r){t=setInterval(function(){return r(Date.now())},e)},function(){clearInterval(t)},Date.now())}function i(){var e=u.fromResource(function(t){function r(){window.requestAnimationFrame(function(){t(Date.now()),e.isAlive()&&r()})}r()},function(){},Date.now());return e}var u=r(3),s={};t.now=n},function(e,t,r){"use strict";function n(){return"function"==typeof Symbol&&Symbol.observable||"@@observable"}function o(){return this}function i(e){var t=c.computed(e);return r={subscribe:function(e){return{unsubscribe:t.observe("function"==typeof e?function(t){var r=t.newValue;return e(r)}:function(t){var r=t.newValue;return e.next(r)})}}},r[n()]=o,r;var r}function u(e,t){return void 0===t&&(t=void 0),new a(e,t)}var s=this&&this.__decorate||function(e,t,r,n){var o,i=arguments.length,u=i<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)u=Reflect.decorate(e,t,r,n);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(u=(i<3?o(u):i>3?o(t,r,u):o(t,r))||u);return i>3&&u&&Object.defineProperty(t,r,u),u},c=r(1);t.toStream=i;var a=function(){function e(e,t){var r=this;this.current=void 0,c.runInAction(function(){r.current=t,r.subscription=e.subscribe(r)})}return e.prototype.dispose=function(){this.subscription.unsubscribe()},e.prototype.next=function(e){this.current=e},e.prototype.complete=function(){this.subscription.unsubscribe(),this.dispose()},e.prototype.error=function(e){this.current=e,this.dispose()},e}();s([c.observable.ref],a.prototype,"current",void 0),s([c.action],a.prototype,"next",null),s([c.action],a.prototype,"complete",null),s([c.action],a.prototype,"error",null),t.fromStream=u},function(e,t,r){"use strict";function n(e,t,r){if(void 0===r&&(r=0),!o.isObservableArray(e))throw new Error("Expected observable array as first argument");o.isAction(t)||(t=o.action("queueProcessor",t));var n=function(){var r=e.slice(0);o.runInAction(function(){return e.splice(0)}),r.forEach(t)};return r>0?o.autorunAsync(n,r):o.autorun(n)}var o=r(1);t.queueProcessor=n}])});
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("mobx")):"function"==typeof define&&define.amd?define(["mobx"],t):"object"==typeof exports?exports.mobxUtils=t(require("mobx")):e.mobxUtils=t(e.mobx)}(this,function(e){return function(e){function t(n){if(r[n])return r[n].exports;var o=r[n]={exports:{},id:n,loaded:!1};return e[n].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var r={};return t.m=e,t.c=r,t.p="",t(0)}([function(e,t,r){"use strict";function n(e){for(var r in e)t.hasOwnProperty(r)||(t[r]=e[r])}n(r(6)),n(r(9)),n(r(3)),n(r(11)),n(r(5)),n(r(7)),n(r(8)),n(r(12)),n(r(4)),n(r(10)),n(r(2))},function(t,r){t.exports=e},function(e,t){"use strict";function r(e,t){if(void 0===t&&(t="Illegal state"),!e)throw new Error("[mobx-utils] "+t)}function n(e){o.indexOf(e)===-1&&(o.push(e),console.error("[mobx-utils] Deprecated: "+e))}t.NOOP=function(){},t.IDENTITY=function(e){return e},t.invariant=r;var o=[];t.deprecated=n},function(e,t,r){"use strict";function n(e,t,r){void 0===t&&(t=i.NOOP),void 0===r&&(r=void 0);var n=!1,u=!1,s=r,c=function(){n&&(n=!1,t())},a=new o.Atom("ResourceBasedObservable",function(){i.invariant(!n&&!u),n=!0,e(function(e){o.extras.allowStateChanges(!0,function(){s=e,a.reportChanged()})})},c);return{current:function(){i.invariant(!u,"subscribingObservable has already been disposed");var e=a.reportObserved();return e||n||console.warn("Called `get` of an subscribingObservable outside a reaction. Current value will be returned but no new subscription has started"),s},dispose:function(){u=!0,c()},isAlive:function(){return n}}}var o=r(1),i=r(2);t.fromResource=n},function(e,t,r){"use strict";function n(e,t,r,n){if(void 0===r&&(r=0),void 0===n&&(n=0),!o.isObservableArray(e))throw new Error("Expected observable array as first argument");o.isAction(t)||(t=o.action("chunkProcessor",t));var i=function(){for(var r=function(){var r=0===n?e.length:Math.min(e.length,n),i=e.slice(0,r);o.runInAction(function(){return e.splice(0,r)}),t(i)};e.length>0;)r()};return r>0?o.autorunAsync(i,r):o.autorun(i)}var o=r(1);t.chunkProcessor=n},function(e,t,r){"use strict";function n(e){return new c(e)}var o=this&&this.__decorate||function(e,t,r,n){var o,i=arguments.length,u=i<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)u=Reflect.decorate(e,t,r,n);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(u=(i<3?o(u):i>3?o(t,r,u):o(t,r))||u);return i>3&&u&&Object.defineProperty(t,r,u),u},i=r(1),u=r(2),s=["model","reset","submit","isDirty","isPropertyDirty"],c=function(){function e(e){var t=this;this.model=e,this.localValues=i.observable.map({}),this.isPropertyDirty=function(e){return t.localValues.has(e)},u.invariant(i.isObservableObject(e),"createViewModel expects an observable object"),Object.keys(e).forEach(function(e){u.invariant(s.indexOf(e)===-1,"The propertyname "+e+" is reserved and cannot be used with viewModels"),Object.defineProperty(t,e,{enumerable:!0,configurable:!0,get:function(){return t.isPropertyDirty(e)?t.localValues.get(e):t.model[e]},set:i.action(function(r){(t.isPropertyDirty(e)||r!==t.model[e])&&t.localValues.set(e,r)})})})}return Object.defineProperty(e.prototype,"isDirty",{get:function(){return this.localValues.size>0},enumerable:!0,configurable:!0}),e.prototype.submit=function(){var e=this;this.localValues.keys().forEach(function(t){var r=e.localValues.get(t),n=e.model[t];i.isObservableArray(n)?n.replace(r):i.isObservableMap(n)?(n.clear(),n.merge(r)):e.model[t]=r}),this.localValues.clear()},e.prototype.reset=function(){this.localValues.clear()},e.prototype.resetProperty=function(e){this.localValues.delete(e)},e}();o([i.computed],c.prototype,"isDirty",null),o([i.action.bound],c.prototype,"submit",null),o([i.action.bound],c.prototype,"reset",null),o([i.action.bound],c.prototype,"resetProperty",null),t.createViewModel=n},function(e,t,r){"use strict";function n(e,t){return void 0===t&&(t=void 0),new s(e,t)}function o(e){return e instanceof s}var i=r(1),u=r(2);t.PENDING="pending",t.FULFILLED="fulfilled",t.REJECTED="rejected";var s=function(){function e(e,r){void 0===r&&(r=void 0);var n=this;this.promise=e,this._state=i.observable(t.PENDING),this._reason=i.observable.shallowBox(void 0),this._observable=i.observable.box(r),e.then(i.action("observableFromPromise-resolve",function(e){n._observable.set(e),n._state.set("fulfilled")}),i.action("observableFromPromise-reject",function(e){n._reason.set(e),n._observable.set(e),n._state.set("rejected")}))}return Object.defineProperty(e.prototype,"value",{get:function(){return this._observable.get()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"state",{get:function(){return this._state.get()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"reason",{get:function(){return u.deprecated("In `fromPromise`: `.reason` is deprecated, use `.value` instead"),this._reason.get()},enumerable:!0,configurable:!0}),e.prototype.case=function(e){switch(this.state){case"pending":return e.pending&&e.pending();case"rejected":return e.rejected&&e.rejected(this.value);case"fulfilled":return e.fulfilled&&e.fulfilled(this.value)}},e}();t.fromPromise=n,t.isPromiseBasedObservable=o},function(e,t,r){"use strict";function n(e,t,r,n){void 0===r&&(r=1e4),void 0===n&&(n=function(){});var i=!1,u=setTimeout(function(){i||(s(),n())},r),s=o.when(e,function(){i=!0,clearTimeout(u),t()});return function(){clearTimeout(u),s()}}var o=r(1);t.whenWithTimeout=n},function(e,t,r){"use strict";function n(e,t){var r=o.extras.getAtom(e,t);if(!r)throw new Error("No computed provided, please provide an object created with `computed(() => expr)` or an object + property name");return r.observe(function(){})}var o=r(1);t.keepAlive=n},function(e,t,r){"use strict";function n(e,t,r){void 0===t&&(t=void 0),void 0===r&&(r=o.IDENTITY);var n=!1,u=i.observable.shallowBox(r(t)),s=function(){return n||(n=!0,e(function(e){i.extras.allowStateChanges(!0,function(){u.set(e)})})),u.get()},c=i.action("lazyObservable-reset",function(){return u.set(t),u.get()});return{current:s,refresh:function(){return n?(n=!1,s()):u.get()},reset:function(){return c()}}}var o=r(2),i=r(1);t.lazyObservable=n},function(e,t,r){"use strict";function n(e){return void 0===e&&(e=1e3),s[e]||("number"==typeof e?s[e]=o(e):s[e]=i()),s[e].current()}function o(e){var t;return u.fromResource(function(r){t=setInterval(function(){return r(Date.now())},e)},function(){clearInterval(t)},Date.now())}function i(){var e=u.fromResource(function(t){function r(){window.requestAnimationFrame(function(){t(Date.now()),e.isAlive()&&r()})}r()},function(){},Date.now());return e}var u=r(3),s={};t.now=n},function(e,t,r){"use strict";function n(){return"function"==typeof Symbol&&Symbol.observable||"@@observable"}function o(){return this}function i(e){var t=c.computed(e);return r={subscribe:function(e){return{unsubscribe:t.observe("function"==typeof e?function(t){var r=t.newValue;return e(r)}:function(t){var r=t.newValue;return e.next(r)})}}},r[n()]=o,r;var r}function u(e,t){return void 0===t&&(t=void 0),new a(e,t)}var s=this&&this.__decorate||function(e,t,r,n){var o,i=arguments.length,u=i<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)u=Reflect.decorate(e,t,r,n);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(u=(i<3?o(u):i>3?o(t,r,u):o(t,r))||u);return i>3&&u&&Object.defineProperty(t,r,u),u},c=r(1);t.toStream=i;var a=function(){function e(e,t){var r=this;this.current=void 0,c.runInAction(function(){r.current=t,r.subscription=e.subscribe(r)})}return e.prototype.dispose=function(){this.subscription&&this.subscription.unsubscribe()},e.prototype.next=function(e){this.current=e},e.prototype.complete=function(){this.dispose()},e.prototype.error=function(e){this.current=e,this.dispose()},e}();s([c.observable.ref],a.prototype,"current",void 0),s([c.action],a.prototype,"next",null),s([c.action],a.prototype,"complete",null),s([c.action],a.prototype,"error",null),t.fromStream=u},function(e,t,r){"use strict";function n(e,t,r){if(void 0===r&&(r=0),!o.isObservableArray(e))throw new Error("Expected observable array as first argument");o.isAction(t)||(t=o.action("queueProcessor",t));var n=function(){var r=e.slice(0);o.runInAction(function(){return e.splice(0)}),r.forEach(t)};return r>0?o.autorunAsync(n,r):o.autorun(n)}var o=r(1);t.queueProcessor=n}])});
{
"name": "mobx-utils",
"version": "2.0.1",
"version": "2.0.2",
"description": "Utility functions and common patterns for MobX",

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

@@ -27,3 +27,3 @@ # MobX-utils

[lib/from-promise.js:100-103](https://github.com/mobxjs/mobx-utils/blob/626e6e984b7b8d52457873cdb5c1ab72e6d0d5da/lib/from-promise.js#L100-L103 "Source code on GitHub")
[lib/from-promise.js:100-103](https://github.com/mobxjs/mobx-utils/blob/2e0d881a4901917426571319d529adbc9a3b3afa/lib/from-promise.js#L100-L103 "Source code on GitHub")

@@ -81,8 +81,20 @@ `fromPromise` takes a Promise and returns an object with 3 observable properties that track

## isPromiseBasedObservable
[lib/from-promise.js:110-112](https://github.com/mobxjs/mobx-utils/blob/2e0d881a4901917426571319d529adbc9a3b3afa/lib/from-promise.js#L110-L112 "Source code on GitHub")
Returns true if the provided value is a promise-based observable.
**Parameters**
- `value` any
Returns **[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)**
## lazyObservable
[lib/lazy-observable.js:37-72](https://github.com/mobxjs/mobx-utils/blob/626e6e984b7b8d52457873cdb5c1ab72e6d0d5da/lib/lazy-observable.js#L37-L72 "Source code on GitHub")
[lib/lazy-observable.js:37-72](https://github.com/mobxjs/mobx-utils/blob/2e0d881a4901917426571319d529adbc9a3b3afa/lib/lazy-observable.js#L37-L72 "Source code on GitHub")
`lazyObservable` creates an observable around a `fetch` method that will not be invoked
util the observable is needed the first time.
until the observable is needed the first time.
The fetch method receives a `sink` callback which can be used to replace the

@@ -121,5 +133,5 @@ current value of the lazyObservable. It is allowed to call `sink` multiple times

[lib/from-resource.js:68-104](https://github.com/mobxjs/mobx-utils/blob/626e6e984b7b8d52457873cdb5c1ab72e6d0d5da/lib/from-resource.js#L68-L104 "Source code on GitHub")
[lib/from-resource.js:68-104](https://github.com/mobxjs/mobx-utils/blob/2e0d881a4901917426571319d529adbc9a3b3afa/lib/from-resource.js#L68-L104 "Source code on GitHub")
`fromResource` creates an observable which current state can be inspected using `.current()`,
`fromResource` creates an observable whose current state can be inspected using `.current()`,
and which can be kept in sync with some external datasource that can be subscribed to.

@@ -187,3 +199,3 @@

[lib/observable-stream.js:37-57](https://github.com/mobxjs/mobx-utils/blob/626e6e984b7b8d52457873cdb5c1ab72e6d0d5da/lib/observable-stream.js#L37-L57 "Source code on GitHub")
[lib/observable-stream.js:37-57](https://github.com/mobxjs/mobx-utils/blob/2e0d881a4901917426571319d529adbc9a3b3afa/lib/observable-stream.js#L37-L57 "Source code on GitHub")

@@ -216,3 +228,3 @@ Converts an expression to an observable stream (a.k.a. TC 39 Observable / RxJS observable).

[lib/observable-stream.js:121-124](https://github.com/mobxjs/mobx-utils/blob/626e6e984b7b8d52457873cdb5c1ab72e6d0d5da/lib/observable-stream.js#L121-L124 "Source code on GitHub")
[lib/observable-stream.js:122-125](https://github.com/mobxjs/mobx-utils/blob/2e0d881a4901917426571319d529adbc9a3b3afa/lib/observable-stream.js#L122-L125 "Source code on GitHub")

@@ -244,3 +256,3 @@ Converts an subscribable, observable stream (TC 39 observable / RxJS stream)

[lib/create-view-model.js:127-129](https://github.com/mobxjs/mobx-utils/blob/626e6e984b7b8d52457873cdb5c1ab72e6d0d5da/lib/create-view-model.js#L127-L129 "Source code on GitHub")
[lib/create-view-model.js:127-129](https://github.com/mobxjs/mobx-utils/blob/2e0d881a4901917426571319d529adbc9a3b3afa/lib/create-view-model.js#L127-L129 "Source code on GitHub")

@@ -296,3 +308,3 @@ `createViewModel` takes an object with observable properties (model)

[lib/guarded-when.js:32-51](https://github.com/mobxjs/mobx-utils/blob/626e6e984b7b8d52457873cdb5c1ab72e6d0d5da/lib/guarded-when.js#L32-L51 "Source code on GitHub")
[lib/guarded-when.js:32-51](https://github.com/mobxjs/mobx-utils/blob/2e0d881a4901917426571319d529adbc9a3b3afa/lib/guarded-when.js#L32-L51 "Source code on GitHub")

@@ -333,3 +345,3 @@ Like normal `when`, except that this `when` will automatically dispose if the condition isn't met within a certain amount of time.

[lib/keep-alive.js:31-36](https://github.com/mobxjs/mobx-utils/blob/626e6e984b7b8d52457873cdb5c1ab72e6d0d5da/lib/keep-alive.js#L31-L36 "Source code on GitHub")
[lib/keep-alive.js:31-36](https://github.com/mobxjs/mobx-utils/blob/2e0d881a4901917426571319d529adbc9a3b3afa/lib/keep-alive.js#L31-L36 "Source code on GitHub")

@@ -357,3 +369,3 @@ **Parameters**

[lib/keep-alive.js:31-36](https://github.com/mobxjs/mobx-utils/blob/626e6e984b7b8d52457873cdb5c1ab72e6d0d5da/lib/keep-alive.js#L31-L36 "Source code on GitHub")
[lib/keep-alive.js:31-36](https://github.com/mobxjs/mobx-utils/blob/2e0d881a4901917426571319d529adbc9a3b3afa/lib/keep-alive.js#L31-L36 "Source code on GitHub")

@@ -385,3 +397,3 @@ MobX normally suspends any computed value that is not in use by any reaction,

[lib/queue-processor.js:22-40](https://github.com/mobxjs/mobx-utils/blob/626e6e984b7b8d52457873cdb5c1ab72e6d0d5da/lib/queue-processor.js#L22-L40 "Source code on GitHub")
[lib/queue-processor.js:22-40](https://github.com/mobxjs/mobx-utils/blob/2e0d881a4901917426571319d529adbc9a3b3afa/lib/queue-processor.js#L22-L40 "Source code on GitHub")

@@ -414,3 +426,3 @@ `queueProcessor` takes an observable array, observes it and calls `processor`

[lib/chunk-processor.js:27-52](https://github.com/mobxjs/mobx-utils/blob/626e6e984b7b8d52457873cdb5c1ab72e6d0d5da/lib/chunk-processor.js#L27-L52 "Source code on GitHub")
[lib/chunk-processor.js:27-52](https://github.com/mobxjs/mobx-utils/blob/2e0d881a4901917426571319d529adbc9a3b3afa/lib/chunk-processor.js#L27-L52 "Source code on GitHub")

@@ -448,3 +460,3 @@ `chunkProcessor` takes an observable array, observes it and calls `processor`

[lib/now.js:30-39](https://github.com/mobxjs/mobx-utils/blob/626e6e984b7b8d52457873cdb5c1ab72e6d0d5da/lib/now.js#L30-L39 "Source code on GitHub")
[lib/now.js:30-39](https://github.com/mobxjs/mobx-utils/blob/2e0d881a4901917426571319d529adbc9a3b3afa/lib/now.js#L30-L39 "Source code on GitHub")

@@ -461,3 +473,3 @@ Returns the current date time as epoch number.

Countdown example: <http://jsbin.com/roqesit/1/edit?js,output>
Countdown example: <https://jsfiddle.net/mweststrate/na0qdmkw/>

@@ -464,0 +476,0 @@ **Parameters**

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