mobx-utils
Advanced tools
Comparing version 5.1.0 to 5.2.0
@@ -0,1 +1,7 @@ | ||
# 5.2.0 | ||
* `createViewModel` now has an additional field `changedValues` on the returned viewmodel, that returns a map with all the pending changes. See [#172](https://github.com/mobxjs/mobx-utils/pull/172) by [@ItamarShDev](https://github.com/ItamarShDev). Fixes [#171](https://github.com/mobxjs/mobx-utils/issues/171) and [#173](https://github.com/mobxjs/mobx-utils/issues/173) | ||
* `fromPromise().case`: if the `onFullfilled` handler is omitted, `case` will now return the resolved value, rather than `undefined`. See [#167](https://github.com/mobxjs/mobx-utils/pull/167/) by [@JefHellemans](https://github.com/JefHellemans) | ||
* `createViewModel` will now respect the enumerability of properties. See [#169](https://github.com/mobxjs/mobx-utils/pull/169) by [dr0p](https://github.com/dr0p) | ||
# 5.1.0 | ||
@@ -2,0 +8,0 @@ |
@@ -15,2 +15,3 @@ import { ObservableMap } from "mobx"; | ||
readonly isDirty: boolean; | ||
readonly changedValues: Map<any, any>; | ||
constructor(model: T); | ||
@@ -35,2 +36,3 @@ isPropertyDirty: (key: string) => boolean; | ||
* - `isPropertyDirty(propName)`: returns true if the specified property is dirty | ||
* - `changedValues`: returns a key / value map with the properties that have been changed in the model so far | ||
* - `model`: The original model object for which this viewModel was created | ||
@@ -37,0 +39,0 @@ * |
@@ -29,4 +29,5 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { | ||
} | ||
var enumerable = Object.getOwnPropertyDescriptor(model, key).enumerable; | ||
Object.defineProperty(_this, key, { | ||
enumerable: true, | ||
enumerable: enumerable, | ||
configurable: true, | ||
@@ -42,5 +43,8 @@ get: function () { | ||
set: action(function (value) { | ||
if (_this.isPropertyDirty(key) || value !== _this.model[key]) { | ||
if (value !== _this.model[key]) { | ||
_this.localValues.set(key, value); | ||
} | ||
else { | ||
_this.localValues.delete(key); | ||
} | ||
}) | ||
@@ -57,2 +61,9 @@ }); | ||
}); | ||
Object.defineProperty(ViewModel.prototype, "changedValues", { | ||
get: function () { | ||
return this.localValues.toJS(); | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
ViewModel.prototype.submit = function () { | ||
@@ -87,2 +98,5 @@ var _this = this; | ||
__decorate([ | ||
computed | ||
], ViewModel.prototype, "changedValues", null); | ||
__decorate([ | ||
action.bound | ||
@@ -112,2 +126,3 @@ ], ViewModel.prototype, "submit", null); | ||
* - `isPropertyDirty(propName)`: returns true if the specified property is dirty | ||
* - `changedValues`: returns a key / value map with the properties that have been changed in the model so far | ||
* - `model`: The original model object for which this viewModel was created | ||
@@ -114,0 +129,0 @@ * |
@@ -13,4 +13,6 @@ import { IObjectDidChange, IArrayChange, IArraySplice, IMapDidChange } from "mobx"; | ||
* | ||
* The returned disposer can be invoked to clean up the listner | ||
* The returned disposer can be invoked to clean up the listener | ||
* | ||
* deepObserve cannot be used on computed values. | ||
* | ||
* @example | ||
@@ -17,0 +19,0 @@ * const disposer = deepObserve(target, (change, path) => { |
@@ -19,4 +19,6 @@ import { observe, isObservableMap, isObservableObject, isObservableArray, values, entries } from "mobx"; | ||
* | ||
* The returned disposer can be invoked to clean up the listner | ||
* The returned disposer can be invoked to clean up the listener | ||
* | ||
* deepObserve cannot be used on computed values. | ||
* | ||
* @example | ||
@@ -23,0 +25,0 @@ * const disposer = deepObserve(target, (change, path) => { |
@@ -11,3 +11,3 @@ export declare type PromiseState = "pending" | "fulfilled" | "rejected"; | ||
rejected?: (e: any) => U; | ||
}): U; | ||
}, defaultFulfilled?: boolean): U; | ||
} & PromiseLike<T>; | ||
@@ -28,4 +28,4 @@ export declare type IPendingPromise = { | ||
/** | ||
* `fromPromise` takes a Promise and returns a new Promise wrapping the original one. The returned Promise is also extended with 2 observable properties that track | ||
* the status of the promise. The returned object has the following observable properties: | ||
* `fromPromise` takes a Promise, extends it with 2 observable properties that track | ||
* the status of the promise and returns it. The returned object has the following observable properties: | ||
* - `value`: either the initial value, the value the Promise resolved to, or the value the Promise was rejected with. use `.state` if you need to be able to tell the difference. | ||
@@ -32,0 +32,0 @@ * - `state`: one of `"pending"`, `"fulfilled"` or `"rejected"` |
@@ -13,3 +13,3 @@ import { action, extendObservable } from "mobx"; | ||
case FULFILLED: | ||
return handlers.fulfilled && handlers.fulfilled(this.value); | ||
return handlers.fulfilled ? handlers.fulfilled(this.value) : this.value; | ||
} | ||
@@ -47,4 +47,4 @@ } | ||
/** | ||
* `fromPromise` takes a Promise and returns a new Promise wrapping the original one. The returned Promise is also extended with 2 observable properties that track | ||
* the status of the promise. The returned object has the following observable properties: | ||
* `fromPromise` takes a Promise, extends it with 2 observable properties that track | ||
* the status of the promise and returns it. The returned object has the following observable properties: | ||
* - `value`: either the initial value, the value the Promise resolved to, or the value the Promise was rejected with. use `.state` if you need to be able to tell the difference. | ||
@@ -51,0 +51,0 @@ * - `state`: one of `"pending"`, `"fulfilled"` or `"rejected"` |
@@ -36,3 +36,3 @@ import { $mobx, _allowStateChanges, _getAdministration, _isComputingDerivation, action, autorun, computed, createAtom, entries, extendObservable, flow, getAtom, isAction, isComputed, isComputedProp, isObservableArray, isObservableMap, isObservableObject, keys, observable, observe, onBecomeUnobserved, runInAction, values, when } from 'mobx'; | ||
case FULFILLED: | ||
return handlers.fulfilled && handlers.fulfilled(this.value); | ||
return handlers.fulfilled ? handlers.fulfilled(this.value) : this.value; | ||
} | ||
@@ -70,4 +70,4 @@ } | ||
/** | ||
* `fromPromise` takes a Promise and returns a new Promise wrapping the original one. The returned Promise is also extended with 2 observable properties that track | ||
* the status of the promise. The returned object has the following observable properties: | ||
* `fromPromise` takes a Promise, extends it with 2 observable properties that track | ||
* the status of the promise and returns it. The returned object has the following observable properties: | ||
* - `value`: either the initial value, the value the Promise resolved to, or the value the Promise was rejected with. use `.state` if you need to be able to tell the difference. | ||
@@ -567,4 +567,5 @@ * - `state`: one of `"pending"`, `"fulfilled"` or `"rejected"` | ||
} | ||
var enumerable = Object.getOwnPropertyDescriptor(model, key).enumerable; | ||
Object.defineProperty(_this, key, { | ||
enumerable: true, | ||
enumerable: enumerable, | ||
configurable: true, | ||
@@ -580,5 +581,8 @@ get: function () { | ||
set: action(function (value) { | ||
if (_this.isPropertyDirty(key) || value !== _this.model[key]) { | ||
if (value !== _this.model[key]) { | ||
_this.localValues.set(key, value); | ||
} | ||
else { | ||
_this.localValues.delete(key); | ||
} | ||
}) | ||
@@ -595,2 +599,9 @@ }); | ||
}); | ||
Object.defineProperty(ViewModel.prototype, "changedValues", { | ||
get: function () { | ||
return this.localValues.toJS(); | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
ViewModel.prototype.submit = function () { | ||
@@ -625,2 +636,5 @@ var _this = this; | ||
__decorate$1([ | ||
computed | ||
], ViewModel.prototype, "changedValues", null); | ||
__decorate$1([ | ||
action.bound | ||
@@ -649,2 +663,3 @@ ], ViewModel.prototype, "submit", null); | ||
* - `isPropertyDirty(propName)`: returns true if the specified property is dirty | ||
* - `changedValues`: returns a key / value map with the properties that have been changed in the model so far | ||
* - `model`: The original model object for which this viewModel was created | ||
@@ -1127,4 +1142,6 @@ * | ||
* | ||
* The returned disposer can be invoked to clean up the listner | ||
* The returned disposer can be invoked to clean up the listener | ||
* | ||
* deepObserve cannot be used on computed values. | ||
* | ||
* @example | ||
@@ -1131,0 +1148,0 @@ * const disposer = deepObserve(target, (change, path) => { |
@@ -40,3 +40,3 @@ (function (global, factory) { | ||
case FULFILLED: | ||
return handlers.fulfilled && handlers.fulfilled(this.value); | ||
return handlers.fulfilled ? handlers.fulfilled(this.value) : this.value; | ||
} | ||
@@ -74,4 +74,4 @@ } | ||
/** | ||
* `fromPromise` takes a Promise and returns a new Promise wrapping the original one. The returned Promise is also extended with 2 observable properties that track | ||
* the status of the promise. The returned object has the following observable properties: | ||
* `fromPromise` takes a Promise, extends it with 2 observable properties that track | ||
* the status of the promise and returns it. The returned object has the following observable properties: | ||
* - `value`: either the initial value, the value the Promise resolved to, or the value the Promise was rejected with. use `.state` if you need to be able to tell the difference. | ||
@@ -571,4 +571,5 @@ * - `state`: one of `"pending"`, `"fulfilled"` or `"rejected"` | ||
} | ||
var enumerable = Object.getOwnPropertyDescriptor(model, key).enumerable; | ||
Object.defineProperty(_this, key, { | ||
enumerable: true, | ||
enumerable: enumerable, | ||
configurable: true, | ||
@@ -584,5 +585,8 @@ get: function () { | ||
set: mobx.action(function (value) { | ||
if (_this.isPropertyDirty(key) || value !== _this.model[key]) { | ||
if (value !== _this.model[key]) { | ||
_this.localValues.set(key, value); | ||
} | ||
else { | ||
_this.localValues.delete(key); | ||
} | ||
}) | ||
@@ -599,2 +603,9 @@ }); | ||
}); | ||
Object.defineProperty(ViewModel.prototype, "changedValues", { | ||
get: function () { | ||
return this.localValues.toJS(); | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
ViewModel.prototype.submit = function () { | ||
@@ -629,2 +640,5 @@ var _this = this; | ||
__decorate$1([ | ||
mobx.computed | ||
], ViewModel.prototype, "changedValues", null); | ||
__decorate$1([ | ||
mobx.action.bound | ||
@@ -653,2 +667,3 @@ ], ViewModel.prototype, "submit", null); | ||
* - `isPropertyDirty(propName)`: returns true if the specified property is dirty | ||
* - `changedValues`: returns a key / value map with the properties that have been changed in the model so far | ||
* - `model`: The original model object for which this viewModel was created | ||
@@ -1131,4 +1146,6 @@ * | ||
* | ||
* The returned disposer can be invoked to clean up the listner | ||
* The returned disposer can be invoked to clean up the listener | ||
* | ||
* deepObserve cannot be used on computed values. | ||
* | ||
* @example | ||
@@ -1135,0 +1152,0 @@ * const disposer = deepObserve(target, (change, path) => { |
{ | ||
"name": "mobx-utils", | ||
"version": "5.1.0", | ||
"version": "5.2.0", | ||
"description": "Utility functions and common patterns for MobX", | ||
@@ -48,2 +48,3 @@ "main": "mobx-utils.umd.js", | ||
"rxjs": "^5.0.2", | ||
"shelljs": "^0.8.3", | ||
"ts-jest": "^22.4.1", | ||
@@ -50,0 +51,0 @@ "typescript": "^2.9.0" |
@@ -27,4 +27,4 @@ # MobX-utils | ||
`fromPromise` takes a Promise and returns a new Promise wrapping the original one. The returned Promise is also extended with 2 observable properties that track | ||
the status of the promise. The returned object has the following observable properties: | ||
`fromPromise` takes a Promise, extends it with 2 observable properties that track | ||
the status of the promise and returns it. The returned object has the following observable properties: | ||
@@ -299,2 +299,3 @@ - `value`: either the initial value, the value the Promise resolved to, or the value the Promise was rejected with. use `.state` if you need to be able to tell the difference. | ||
- `isPropertyDirty(propName)`: returns true if the specified property is dirty | ||
- `changedValues`: returns a key / value map with the properties that have been changed in the model so far | ||
- `model`: The original model object for which this viewModel was created | ||
@@ -638,4 +639,6 @@ | ||
The returned disposer can be invoked to clean up the listner | ||
The returned disposer can be invoked to clean up the listener | ||
deepObserve cannot be used on computed values. | ||
**Parameters** | ||
@@ -642,0 +645,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
262590
5575
653
16