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

@frui.ts/dirtycheck

Package Overview
Dependencies
Maintainers
5
Versions
78
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@frui.ts/dirtycheck - npm Package Compare versions

Comparing version 1.0.0-alpha.13 to 1.0.0-alpha.14

dist/configuration.d.ts

30

dist/automaticDirtyWatcher.d.ts

@@ -1,16 +0,22 @@

import { PropertyName } from "@frui.ts/helpers";
import { DirtyPropertiesList, IDirtyWatcher } from "./types";
export interface DirtyWatchConfig<TTarget> {
exclude?: PropertyName<TTarget>[];
import type { PropertyName } from "@frui.ts/helpers";
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>;

229

dist/automaticDirtyWatcher.js
"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 __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
var helpers_1 = require("@frui.ts/helpers");
var mobx_1 = require("mobx");
var AutomaticDirtyWatcher = (function () {
function AutomaticDirtyWatcher(target, isDirtyFlagVisible, config) {
exports.attachAutomaticDirtyWatcher = void 0;
const helpers_1 = require("@frui.ts/helpers");
const mobx_1 = require("mobx");
const _1 = require(".");
const dirtyWatcherBase_1 = __importDefault(require("./dirtyWatcherBase"));
const utils_1 = require("./utils");
class AutomaticDirtyWatcher extends dirtyWatcherBase_1.default {
constructor(target, params) {
super(params === null || params === void 0 ? void 0 : params.isVisible);
this.target = target;
this.config = config;
this.isDirtyFlagVisible = isDirtyFlagVisible;
this._watchedProperties = [];
if (typeof params === "object") {
this._includedProperties = params.includedProperties;
this._excludedProperties = params.excludedProperties;
}
this.reset();
}
Object.defineProperty(AutomaticDirtyWatcher.prototype, "isDirty", {
get: function () {
var _this = this;
return this.checkedProperties.some(function (prop) { return !!mobx_1.get(_this.dirtyProperties, prop); });
checkDirty(propertyName) {
if (!this.isEnabled) {
return false;
}
if (propertyName) {
return !!this._results[propertyName];
}
else {
for (const propertyName of this._watchedProperties) {
if (this._results[propertyName]) {
return true;
}
}
return false;
}
}
*getDirtyProperties() {
if (!this.isEnabled) {
return;
}
for (const propertyName of this._watchedProperties) {
if (this._results[propertyName]) {
yield propertyName;
}
}
}
reset() {
const resultsObject = {};
this._watchedProperties.length = 0;
for (const name of Object.keys(this.target)) {
const propertyName = name;
if ((!this._includedProperties || this._includedProperties.includes(propertyName)) &&
(!this._excludedProperties || !this._excludedProperties.includes(propertyName))) {
this._watchedProperties.push(propertyName);
const entity = this.target;
const originalValue = (0, mobx_1.get)(entity, propertyName);
if ((0, mobx_1.isArrayLike)(originalValue)) {
defineArrayDirtyWatchProperty(resultsObject, originalValue, propertyName, entity);
}
else if ((0, helpers_1.isSet)(originalValue)) {
defineSetDirtyCheckProperty(resultsObject, originalValue, propertyName, entity);
}
else if ((0, helpers_1.isMap)(originalValue)) {
defineMapDirtyCheckProperty(resultsObject, originalValue, propertyName, entity);
}
else if (typeof originalValue === "object") {
defineObjectDirtyWatchProperty(resultsObject, originalValue, propertyName, entity);
}
else {
Object.defineProperty(resultsObject, propertyName, {
get: () => {
const currentValue = (0, mobx_1.get)(entity, propertyName);
return originalValue !== currentValue;
},
});
}
}
}
this._results = (0, mobx_1.observable)(resultsObject);
}
}
exports.default = AutomaticDirtyWatcher;
function defineArrayDirtyWatchProperty(resultsObject, originalValue, propertyName, entity) {
const arraySnapshot = originalValue.slice();
const hasNestedDirtyWatcher = !!(0, _1.getDirtyWatcher)(arraySnapshot[0]);
if (hasNestedDirtyWatcher) {
Object.defineProperty(resultsObject, propertyName, {
get: () => {
const currentValue = (0, mobx_1.get)(entity, propertyName);
return (!currentValue ||
currentValue.length !== arraySnapshot.length ||
arraySnapshot.some((originalItem, index) => { var _a; return originalItem !== currentValue[index] || ((_a = (0, _1.getDirtyWatcher)(originalItem)) === null || _a === void 0 ? void 0 : _a.isDirty) === true; }));
},
});
}
else {
Object.defineProperty(resultsObject, propertyName, {
get: () => {
const currentValue = (0, mobx_1.get)(entity, propertyName);
return (!currentValue ||
currentValue.length !== arraySnapshot.length ||
arraySnapshot.some((originalItem, index) => originalItem !== currentValue[index]));
},
});
}
}
function defineSetDirtyCheckProperty(resultsObject, originalValue, propertyName, entity) {
const setSnapshot = new Set(originalValue);
Object.defineProperty(resultsObject, propertyName, {
get: () => {
var _a;
const currentValue = (0, mobx_1.get)(entity, propertyName);
if (!currentValue || currentValue.size !== setSnapshot.size) {
return true;
}
for (const item of setSnapshot.values()) {
if (!currentValue.has(item) || ((_a = (0, _1.getDirtyWatcher)(item)) === null || _a === void 0 ? void 0 : _a.isDirty)) {
return true;
}
}
return false;
},
enumerable: true,
configurable: true
});
AutomaticDirtyWatcher.prototype.reset = function () {
this.dirtyProperties = {};
this.checkedProperties = [];
var target = this.target;
var _loop_1 = function (propertyName) {
}
function defineMapDirtyCheckProperty(resultsObject, originalValue, propertyName, entity) {
const setSnapshot = new Map(originalValue);
Object.defineProperty(resultsObject, propertyName, {
get: () => {
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, {
get: function () {
return mobx_1.get(target, propertyName) !== originalValue_1;
},
enumerable: true,
configurable: true
}),
_a));
const currentValue = (0, mobx_1.get)(entity, propertyName);
if (!currentValue || currentValue.size !== setSnapshot.size) {
return true;
}
};
var this_1 = this;
for (var propertyName in target) {
_loop_1(propertyName);
}
};
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)) {
for (const [key, item] of setSnapshot.entries()) {
const currentItem = currentValue.get(key);
if (item !== currentItem || ((_a = (0, _1.getDirtyWatcher)(item)) === null || _a === void 0 ? void 0 : _a.isDirty)) {
return true;
}
}
return false;
}
return true;
};
__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;
}());
exports.default = AutomaticDirtyWatcher;
},
});
}
function defineObjectDirtyWatchProperty(resultsObject, originalValue, propertyName, entity) {
const hasNestedDirtyWatcher = (0, _1.getDirtyWatcher)(originalValue);
if (hasNestedDirtyWatcher) {
Object.defineProperty(resultsObject, propertyName, {
get: () => { var _a; return ((_a = (0, _1.getDirtyWatcher)((0, mobx_1.get)(entity, propertyName))) === null || _a === void 0 ? void 0 : _a.isDirty) === true; },
});
}
else {
Object.defineProperty(resultsObject, propertyName, {
get: () => {
const currentValue = (0, mobx_1.get)(entity, propertyName);
return originalValue !== currentValue;
},
});
}
}
function attachAutomaticDirtyWatcher(target, params) {
const paramsObject = typeof params === "boolean" ? { isVisible: params } : params;
const automaticDirtyWatcher = new AutomaticDirtyWatcher(target, paramsObject);
(0, 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 __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 +20,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) {

@@ -13,64 +32,53 @@ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);

Object.defineProperty(exports, "__esModule", { value: true });
var mobx_1 = require("mobx");
var ManualDirtyWatcher = (function () {
function ManualDirtyWatcher(isDirtyFlagVisible) {
this.dirtyProperties = {};
this.isDirtyFlagVisible = isDirtyFlagVisible;
const mobx_1 = require("mobx");
const dirtyWatcherBase_1 = __importStar(require("./dirtyWatcherBase"));
class ManualDirtyWatcher extends dirtyWatcherBase_1.default {
constructor() {
super(...arguments);
this._dirtyProperties = mobx_1.observable.set();
}
ManualDirtyWatcher.prototype.reset = function () {
var _this = this;
mobx_1.keys(this.dirtyProperties).forEach(function (prop) { return mobx_1.remove(_this.dirtyProperties, prop); });
};
ManualDirtyWatcher.prototype.setDirty = function (propertyName, isDirty) {
if (isDirty === void 0) { isDirty = true; }
mobx_1.set(this.dirtyProperties, propertyName, isDirty);
};
Object.defineProperty(ManualDirtyWatcher.prototype, "isDirty", {
get: function () {
return mobx_1.values(this.dirtyProperties).some(function (x) { return !!x; });
},
enumerable: true,
configurable: true
});
__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:returntype", void 0)
], ManualDirtyWatcher.prototype, "reset", null);
__decorate([
mobx_1.action,
__metadata("design:type", Function),
__metadata("design:paramtypes", [String, Object]),
__metadata("design:returntype", void 0)
], ManualDirtyWatcher.prototype, "setDirty", null);
__decorate([
mobx_1.computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], ManualDirtyWatcher.prototype, "isDirty", null);
return ManualDirtyWatcher;
}());
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);
checkDirty(propertyName) {
if (!this.isEnabled) {
return false;
}
if (propertyName) {
return this._dirtyProperties.has(propertyName);
}
else {
return this._dirtyProperties.size > 0;
}
}
getDirtyProperties() {
if (this.isEnabled) {
return this._dirtyProperties;
}
else {
return dirtyWatcherBase_1.emptyResults;
}
}
setDirty(propertyName, isDirty = true) {
if (isDirty) {
this._dirtyProperties.add(propertyName);
}
else {
this._dirtyProperties.delete(propertyName);
}
}
reset() {
this._dirtyProperties.clear();
}
}
exports.setDirty = setDirty;
__decorate([
mobx_1.action,
__metadata("design:type", Function),
__metadata("design:paramtypes", [String, Object]),
__metadata("design:returntype", void 0)
], ManualDirtyWatcher.prototype, "setDirty", null);
__decorate([
mobx_1.action,
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", void 0)
], ManualDirtyWatcher.prototype, "reset", null);
exports.default = ManualDirtyWatcher;
//# 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": "1.0.0-alpha.13",
"version": "1.0.0-alpha.14",
"description": "Observable dirty checking",

@@ -39,3 +39,3 @@ "keywords": [

"dependencies": {
"@frui.ts/helpers": "^1.0.0-alpha.13"
"@frui.ts/helpers": "^1.0.0-alpha.14"
},

@@ -45,3 +45,3 @@ "peerDependencies": {

},
"gitHead": "5454d007244bb9cdd28be5207a9f125f04a9ac43"
"gitHead": "ea59f02314805efcededd8a9b75b62b0e656cd4e"
}

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

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