@frui.ts/dirtycheck
Advanced tools
Comparing version 0.17.0-generator.2 to 1.0.0-alpha.1
import { PropertyName } from "@frui.ts/helpers"; | ||
import { DirtyPropertiesList, IDirtyWatcher } from "./types"; | ||
export interface DirtyWatchConfig<TTarget> { | ||
exclude?: PropertyName<TTarget>[]; | ||
import DirtyWatcherBase from "./dirtyWatcherBase"; | ||
export interface AutomaticDirtyWatcherParams<TEntity> { | ||
isVisible?: boolean; | ||
includedProperties?: PropertyName<TEntity>[]; | ||
excludedProperties?: PropertyName<TEntity>[]; | ||
} | ||
export default class AutomaticDirtyWatcher<TTarget extends Record<string, any>> implements IDirtyWatcher<TTarget> { | ||
export default class AutomaticDirtyWatcher<TEntity = any> extends DirtyWatcherBase<TEntity> { | ||
private target; | ||
private config?; | ||
isDirtyFlagVisible: boolean; | ||
dirtyProperties: DirtyPropertiesList<TTarget>; | ||
private checkedProperties; | ||
constructor(target: TTarget, isDirtyFlagVisible: boolean, config?: DirtyWatchConfig<TTarget> | undefined); | ||
get isDirty(): boolean; | ||
private _includedProperties?; | ||
private _excludedProperties?; | ||
private _results; | ||
private _watchedProperties; | ||
constructor(target: TEntity, params?: AutomaticDirtyWatcherParams<TEntity>); | ||
checkDirty(): boolean; | ||
checkDirty(propertyName: PropertyName<TEntity>): boolean; | ||
getDirtyProperties(): Iterable<PropertyName<TEntity>>; | ||
reset(): void; | ||
private shouldWatchProperty; | ||
} | ||
export declare function attachAutomaticDirtyWatcher<TEntity>(target: TEntity): AutomaticDirtyWatcher<TEntity>; | ||
export declare function attachAutomaticDirtyWatcher<TEntity>(target: TEntity, isVisible: boolean): AutomaticDirtyWatcher<TEntity>; | ||
export declare function attachAutomaticDirtyWatcher<TEntity>(target: TEntity, params: AutomaticDirtyWatcherParams<TEntity>): AutomaticDirtyWatcher<TEntity>; |
"use strict"; | ||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { | ||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; | ||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); | ||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; | ||
return c > 3 && r && Object.defineProperty(target, key, r), r; | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
var __metadata = (this && this.__metadata) || function (k, v) { | ||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); | ||
var __values = (this && this.__values) || function(o) { | ||
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; | ||
if (m) return m.call(o); | ||
if (o && typeof o.length === "number") return { | ||
next: function () { | ||
if (o && i >= o.length) o = void 0; | ||
return { value: o && o[i++], done: !o }; | ||
} | ||
}; | ||
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.attachAutomaticDirtyWatcher = void 0; | ||
var helpers_1 = require("@frui.ts/helpers"); | ||
var mobx_1 = require("mobx"); | ||
var AutomaticDirtyWatcher = (function () { | ||
function AutomaticDirtyWatcher(target, isDirtyFlagVisible, config) { | ||
this.target = target; | ||
this.config = config; | ||
this.isDirtyFlagVisible = isDirtyFlagVisible; | ||
this.reset(); | ||
var dirtyWatcherBase_1 = __importDefault(require("./dirtyWatcherBase")); | ||
var utils_1 = require("./utils"); | ||
var AutomaticDirtyWatcher = (function (_super) { | ||
__extends(AutomaticDirtyWatcher, _super); | ||
function AutomaticDirtyWatcher(target, params) { | ||
var _this = _super.call(this, params === null || params === void 0 ? void 0 : params.isVisible) || this; | ||
_this.target = target; | ||
_this._watchedProperties = []; | ||
if (typeof params === "object") { | ||
_this._includedProperties = params.includedProperties; | ||
_this._excludedProperties = params.excludedProperties; | ||
} | ||
_this.reset(); | ||
return _this; | ||
} | ||
Object.defineProperty(AutomaticDirtyWatcher.prototype, "isDirty", { | ||
get: function () { | ||
var _this = this; | ||
return this.checkedProperties.some(function (prop) { return !!mobx_1.get(_this.dirtyProperties, prop); }); | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
AutomaticDirtyWatcher.prototype.checkDirty = function (propertyName) { | ||
var e_1, _a; | ||
if (!this.isEnabled) { | ||
return false; | ||
} | ||
if (propertyName) { | ||
return !!this._results[propertyName]; | ||
} | ||
else { | ||
try { | ||
for (var _b = __values(this._watchedProperties), _c = _b.next(); !_c.done; _c = _b.next()) { | ||
var propertyName_1 = _c.value; | ||
if (this._results[propertyName_1]) { | ||
return true; | ||
} | ||
} | ||
} | ||
catch (e_1_1) { e_1 = { error: e_1_1 }; } | ||
finally { | ||
try { | ||
if (_c && !_c.done && (_a = _b.return)) _a.call(_b); | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
} | ||
return false; | ||
} | ||
}; | ||
AutomaticDirtyWatcher.prototype.getDirtyProperties = function () { | ||
var _a, _b, propertyName, e_2_1; | ||
var e_2, _c; | ||
return __generator(this, function (_d) { | ||
switch (_d.label) { | ||
case 0: | ||
if (!this.isEnabled) { | ||
return [2]; | ||
} | ||
_d.label = 1; | ||
case 1: | ||
_d.trys.push([1, 6, 7, 8]); | ||
_a = __values(this._watchedProperties), _b = _a.next(); | ||
_d.label = 2; | ||
case 2: | ||
if (!!_b.done) return [3, 5]; | ||
propertyName = _b.value; | ||
if (!this._results[propertyName]) return [3, 4]; | ||
return [4, propertyName]; | ||
case 3: | ||
_d.sent(); | ||
_d.label = 4; | ||
case 4: | ||
_b = _a.next(); | ||
return [3, 2]; | ||
case 5: return [3, 8]; | ||
case 6: | ||
e_2_1 = _d.sent(); | ||
e_2 = { error: e_2_1 }; | ||
return [3, 8]; | ||
case 7: | ||
try { | ||
if (_b && !_b.done && (_c = _a.return)) _c.call(_a); | ||
} | ||
finally { if (e_2) throw e_2.error; } | ||
return [7]; | ||
case 8: return [2]; | ||
} | ||
}); | ||
}; | ||
AutomaticDirtyWatcher.prototype.reset = function () { | ||
this.dirtyProperties = {}; | ||
this.checkedProperties = []; | ||
var target = this.target; | ||
var _loop_1 = function (propertyName) { | ||
var _a; | ||
if (target.hasOwnProperty(propertyName) && this_1.shouldWatchProperty(propertyName)) { | ||
var originalValue_1 = target[propertyName]; | ||
helpers_1.ensureObservableProperty(target, propertyName, originalValue_1); | ||
this_1.checkedProperties.push(propertyName); | ||
mobx_1.extendObservable(this_1.dirtyProperties, (_a = {}, | ||
Object.defineProperty(_a, propertyName, { | ||
var e_3, _a; | ||
var resultsObject = {}; | ||
this._watchedProperties.length = 0; | ||
var _loop_1 = function (name_1) { | ||
var propertyName = name_1; | ||
if ((!this_1._includedProperties || this_1._includedProperties.includes(propertyName)) && | ||
(!this_1._excludedProperties || !this_1._excludedProperties.includes(propertyName))) { | ||
this_1._watchedProperties.push(propertyName); | ||
var entity_1 = this_1.target; | ||
var originalValue_1 = mobx_1.get(entity_1, propertyName); | ||
if (mobx_1.isArrayLike(originalValue_1)) { | ||
defineArrayDirtyWatchProperty(resultsObject, originalValue_1, propertyName, entity_1); | ||
} | ||
else if (helpers_1.isSet(originalValue_1)) { | ||
defineSetDirtyCheckProperty(resultsObject, originalValue_1, propertyName, entity_1); | ||
} | ||
else { | ||
Object.defineProperty(resultsObject, propertyName, { | ||
get: function () { | ||
return mobx_1.get(target, propertyName) !== originalValue_1; | ||
var currentValue = mobx_1.get(entity_1, propertyName); | ||
return originalValue_1 !== currentValue; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}), | ||
_a)); | ||
}); | ||
} | ||
} | ||
}; | ||
var this_1 = this; | ||
for (var propertyName in target) { | ||
_loop_1(propertyName); | ||
try { | ||
for (var _b = __values(Object.keys(this.target)), _c = _b.next(); !_c.done; _c = _b.next()) { | ||
var name_1 = _c.value; | ||
_loop_1(name_1); | ||
} | ||
} | ||
}; | ||
AutomaticDirtyWatcher.prototype.shouldWatchProperty = function (propertyName) { | ||
var _a, _b; | ||
if ((_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.exclude) === null || _b === void 0 ? void 0 : _b.includes(propertyName)) { | ||
return false; | ||
catch (e_3_1) { e_3 = { error: e_3_1 }; } | ||
finally { | ||
try { | ||
if (_c && !_c.done && (_a = _b.return)) _a.call(_b); | ||
} | ||
finally { if (e_3) throw e_3.error; } | ||
} | ||
return true; | ||
this._results = mobx_1.observable(resultsObject); | ||
}; | ||
__decorate([ | ||
mobx_1.observable, | ||
__metadata("design:type", Boolean) | ||
], AutomaticDirtyWatcher.prototype, "isDirtyFlagVisible", void 0); | ||
__decorate([ | ||
mobx_1.observable, | ||
__metadata("design:type", Object) | ||
], AutomaticDirtyWatcher.prototype, "dirtyProperties", void 0); | ||
__decorate([ | ||
mobx_1.computed, | ||
__metadata("design:type", Object), | ||
__metadata("design:paramtypes", []) | ||
], AutomaticDirtyWatcher.prototype, "isDirty", null); | ||
__decorate([ | ||
mobx_1.action, | ||
__metadata("design:type", Function), | ||
__metadata("design:paramtypes", []), | ||
__metadata("design:returntype", void 0) | ||
], AutomaticDirtyWatcher.prototype, "reset", null); | ||
return AutomaticDirtyWatcher; | ||
}()); | ||
}(dirtyWatcherBase_1.default)); | ||
exports.default = AutomaticDirtyWatcher; | ||
function defineArrayDirtyWatchProperty(resultsObject, originalValue, propertyName, entity) { | ||
var arraySnapshot = originalValue.slice(); | ||
Object.defineProperty(resultsObject, propertyName, { | ||
get: function () { | ||
var currentValue = mobx_1.get(entity, propertyName); | ||
return (!currentValue || | ||
currentValue.length !== arraySnapshot.length || | ||
arraySnapshot.some(function (originalItem, index) { return originalItem !== currentValue[index]; })); | ||
}, | ||
}); | ||
} | ||
function defineSetDirtyCheckProperty(resultsObject, originalValue, propertyName, entity) { | ||
var setSnapshot = new Set(originalValue); | ||
Object.defineProperty(resultsObject, propertyName, { | ||
get: function () { | ||
var e_4, _a; | ||
var currentValue = mobx_1.get(entity, propertyName); | ||
if (!currentValue || currentValue.size !== setSnapshot.size) { | ||
return true; | ||
} | ||
try { | ||
for (var _b = __values(setSnapshot.values()), _c = _b.next(); !_c.done; _c = _b.next()) { | ||
var item = _c.value; | ||
if (!currentValue.has(item)) { | ||
return true; | ||
} | ||
} | ||
} | ||
catch (e_4_1) { e_4 = { error: e_4_1 }; } | ||
finally { | ||
try { | ||
if (_c && !_c.done && (_a = _b.return)) _a.call(_b); | ||
} | ||
finally { if (e_4) throw e_4.error; } | ||
} | ||
return false; | ||
}, | ||
}); | ||
} | ||
function attachAutomaticDirtyWatcher(target, params) { | ||
var automaticDirtyWatcher = new AutomaticDirtyWatcher(target, params); | ||
utils_1.attachDirtyWatcher(target, automaticDirtyWatcher); | ||
return automaticDirtyWatcher; | ||
} | ||
exports.attachAutomaticDirtyWatcher = attachAutomaticDirtyWatcher; | ||
//# sourceMappingURL=automaticDirtyWatcher.js.map |
@@ -1,4 +0,5 @@ | ||
export { default as AutomaticDirtyWatcher } from "./automaticDirtyWatcher"; | ||
export * from "./helpers"; | ||
export { default as ManualDirtyWatcher, hasManualDirtyWatcher, setDirty } from "./manualDirtyWatcher"; | ||
export { default as AutomaticDirtyWatcher, attachAutomaticDirtyWatcher } from "./automaticDirtyWatcher"; | ||
export { default as Configuration } from "./configuration"; | ||
export { default as ManualDirtyWatcher } from "./manualDirtyWatcher"; | ||
export * from "./types"; | ||
export * from "./utils"; |
"use strict"; | ||
function __export(m) { | ||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; | ||
} | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ManualDirtyWatcher = exports.Configuration = exports.attachAutomaticDirtyWatcher = exports.AutomaticDirtyWatcher = void 0; | ||
var automaticDirtyWatcher_1 = require("./automaticDirtyWatcher"); | ||
exports.AutomaticDirtyWatcher = automaticDirtyWatcher_1.default; | ||
__export(require("./helpers")); | ||
Object.defineProperty(exports, "AutomaticDirtyWatcher", { enumerable: true, get: function () { return __importDefault(automaticDirtyWatcher_1).default; } }); | ||
Object.defineProperty(exports, "attachAutomaticDirtyWatcher", { enumerable: true, get: function () { return automaticDirtyWatcher_1.attachAutomaticDirtyWatcher; } }); | ||
var configuration_1 = require("./configuration"); | ||
Object.defineProperty(exports, "Configuration", { enumerable: true, get: function () { return __importDefault(configuration_1).default; } }); | ||
var manualDirtyWatcher_1 = require("./manualDirtyWatcher"); | ||
exports.ManualDirtyWatcher = manualDirtyWatcher_1.default; | ||
exports.hasManualDirtyWatcher = manualDirtyWatcher_1.hasManualDirtyWatcher; | ||
exports.setDirty = manualDirtyWatcher_1.setDirty; | ||
Object.defineProperty(exports, "ManualDirtyWatcher", { enumerable: true, get: function () { return __importDefault(manualDirtyWatcher_1).default; } }); | ||
__exportStar(require("./types"), exports); | ||
__exportStar(require("./utils"), exports); | ||
//# sourceMappingURL=index.js.map |
import { PropertyName } from "@frui.ts/helpers"; | ||
import { DirtyPropertiesList, IHasManualDirtyWatcher, IManualDirtyWatcher } from "./types"; | ||
export default class ManualDirtyWatcher<TTarget> implements IManualDirtyWatcher<TTarget> { | ||
isDirtyFlagVisible: boolean; | ||
dirtyProperties: DirtyPropertiesList<TTarget>; | ||
constructor(isDirtyFlagVisible: boolean); | ||
import DirtyWatcherBase from "./dirtyWatcherBase"; | ||
export default class ManualDirtyWatcher<TEntity = any> extends DirtyWatcherBase<TEntity> { | ||
protected _dirtyProperties: import("mobx").ObservableSet<PropertyName<TEntity>>; | ||
checkDirty(): boolean; | ||
checkDirty(propertyName: PropertyName<TEntity>): boolean; | ||
getDirtyProperties(): Iterable<PropertyName<TEntity>>; | ||
setDirty(propertyName: PropertyName<TEntity>, isDirty?: boolean): void; | ||
reset(): void; | ||
setDirty(propertyName: PropertyName<TTarget>, isDirty?: boolean): void; | ||
get isDirty(): boolean; | ||
} | ||
export declare function hasManualDirtyWatcher<TTarget>(target: any): target is IHasManualDirtyWatcher<TTarget>; | ||
export declare function setDirty<TTarget>(target: TTarget, propertyName: PropertyName<TTarget>, isDirty?: boolean): void; |
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { | ||
@@ -8,2 +33,9 @@ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; | ||
}; | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
var __metadata = (this && this.__metadata) || function (k, v) { | ||
@@ -14,63 +46,56 @@ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); | ||
var mobx_1 = require("mobx"); | ||
var ManualDirtyWatcher = (function () { | ||
function ManualDirtyWatcher(isDirtyFlagVisible) { | ||
this.dirtyProperties = {}; | ||
this.isDirtyFlagVisible = isDirtyFlagVisible; | ||
var dirtyWatcherBase_1 = __importStar(require("./dirtyWatcherBase")); | ||
var ManualDirtyWatcher = (function (_super) { | ||
__extends(ManualDirtyWatcher, _super); | ||
function ManualDirtyWatcher() { | ||
var _this = _super !== null && _super.apply(this, arguments) || this; | ||
_this._dirtyProperties = mobx_1.observable.set(); | ||
return _this; | ||
} | ||
ManualDirtyWatcher.prototype.reset = function () { | ||
var _this = this; | ||
mobx_1.keys(this.dirtyProperties).forEach(function (prop) { return mobx_1.remove(_this.dirtyProperties, prop); }); | ||
ManualDirtyWatcher.prototype.checkDirty = function (propertyName) { | ||
if (!this.isEnabled) { | ||
return false; | ||
} | ||
if (propertyName) { | ||
return this._dirtyProperties.has(propertyName); | ||
} | ||
else { | ||
return this._dirtyProperties.size > 0; | ||
} | ||
}; | ||
ManualDirtyWatcher.prototype.getDirtyProperties = function () { | ||
if (this.isEnabled) { | ||
return this._dirtyProperties; | ||
} | ||
else { | ||
return dirtyWatcherBase_1.emptyResults; | ||
} | ||
}; | ||
ManualDirtyWatcher.prototype.setDirty = function (propertyName, isDirty) { | ||
if (isDirty === void 0) { isDirty = true; } | ||
mobx_1.set(this.dirtyProperties, propertyName, isDirty); | ||
if (isDirty) { | ||
this._dirtyProperties.add(propertyName); | ||
} | ||
else { | ||
this._dirtyProperties.delete(propertyName); | ||
} | ||
}; | ||
Object.defineProperty(ManualDirtyWatcher.prototype, "isDirty", { | ||
get: function () { | ||
return mobx_1.values(this.dirtyProperties).some(function (x) { return !!x; }); | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
ManualDirtyWatcher.prototype.reset = function () { | ||
this._dirtyProperties.clear(); | ||
}; | ||
__decorate([ | ||
mobx_1.observable, | ||
__metadata("design:type", Boolean) | ||
], ManualDirtyWatcher.prototype, "isDirtyFlagVisible", void 0); | ||
__decorate([ | ||
mobx_1.observable, | ||
__metadata("design:type", Object) | ||
], ManualDirtyWatcher.prototype, "dirtyProperties", void 0); | ||
__decorate([ | ||
mobx_1.action, | ||
__metadata("design:type", Function), | ||
__metadata("design:paramtypes", []), | ||
__metadata("design:paramtypes", [String, Object]), | ||
__metadata("design:returntype", void 0) | ||
], ManualDirtyWatcher.prototype, "reset", null); | ||
], ManualDirtyWatcher.prototype, "setDirty", null); | ||
__decorate([ | ||
mobx_1.action, | ||
__metadata("design:type", Function), | ||
__metadata("design:paramtypes", [String, Object]), | ||
__metadata("design:paramtypes", []), | ||
__metadata("design:returntype", void 0) | ||
], ManualDirtyWatcher.prototype, "setDirty", null); | ||
__decorate([ | ||
mobx_1.computed, | ||
__metadata("design:type", Object), | ||
__metadata("design:paramtypes", []) | ||
], ManualDirtyWatcher.prototype, "isDirty", null); | ||
], ManualDirtyWatcher.prototype, "reset", null); | ||
return ManualDirtyWatcher; | ||
}()); | ||
}(dirtyWatcherBase_1.default)); | ||
exports.default = ManualDirtyWatcher; | ||
function hasManualDirtyWatcher(target) { | ||
return (!!target && | ||
target.__dirtycheck !== undefined && | ||
typeof target.__dirtycheck.setDirty === "function"); | ||
} | ||
exports.hasManualDirtyWatcher = hasManualDirtyWatcher; | ||
function setDirty(target, propertyName, isDirty) { | ||
if (isDirty === void 0) { isDirty = true; } | ||
if (hasManualDirtyWatcher(target)) { | ||
target.__dirtycheck.setDirty(propertyName, isDirty); | ||
} | ||
} | ||
exports.setDirty = setDirty; | ||
//# sourceMappingURL=manualDirtyWatcher.js.map |
@@ -1,17 +0,13 @@ | ||
import { PropertyName } from "@frui.ts/helpers"; | ||
export declare type DirtyPropertiesList<TTarget> = Partial<Record<PropertyName<TTarget>, boolean>>; | ||
export interface IDirtyWatcher<TTarget> { | ||
isDirty: boolean; | ||
isDirtyFlagVisible: boolean; | ||
dirtyProperties: Readonly<DirtyPropertiesList<TTarget>>; | ||
import type { PropertyName } from "@frui.ts/helpers"; | ||
export interface EntityDirtyWatcher<TEntity> { | ||
isEnabled: boolean; | ||
isVisible: boolean; | ||
readonly isDirty: boolean; | ||
checkDirty(): boolean; | ||
checkDirty(propertyName: PropertyName<TEntity>): boolean; | ||
checkDirtyVisible(): boolean; | ||
checkDirtyVisible(propertyName: PropertyName<TEntity>): boolean; | ||
getDirtyProperties(): Iterable<PropertyName<TEntity>>; | ||
getDirtyVisibleProperties(): Iterable<PropertyName<TEntity>>; | ||
reset(): void; | ||
} | ||
export interface IManualDirtyWatcher<TTarget> extends IDirtyWatcher<TTarget> { | ||
setDirty(propertyName: PropertyName<TTarget>, isDirty?: boolean): void; | ||
} | ||
export interface IHasDirtyWatcher<TTarget> { | ||
__dirtycheck: IDirtyWatcher<TTarget>; | ||
} | ||
export interface IHasManualDirtyWatcher<TTarget> extends IHasDirtyWatcher<TTarget> { | ||
__dirtycheck: IManualDirtyWatcher<TTarget>; | ||
} |
@@ -6,3 +6,3 @@ { | ||
}, | ||
"version": "0.17.0-generator.2", | ||
"version": "1.0.0-alpha.1", | ||
"description": "Observable dirty checking", | ||
@@ -39,3 +39,3 @@ "keywords": [ | ||
"dependencies": { | ||
"@frui.ts/helpers": "^0.17.0-generator.2" | ||
"@frui.ts/helpers": "^1.0.0-alpha.1" | ||
}, | ||
@@ -45,3 +45,3 @@ "peerDependencies": { | ||
}, | ||
"gitHead": "826d4eeca379d5d758641e928e810b4ac5ee90c2" | ||
"gitHead": "debcc8b7993b1b0708853dddb9d29dc2a5727477" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
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
40964
23
512
2
0
1
+ Added@frui.ts/helpers@1.0.0-rc.4(transitive)
+ Addedmobx@6.13.5(transitive)
- Removed@frui.ts/helpers@0.17.5(transitive)