Skip to content
Snippets Groups Projects
Verified Commit 5f991d6f authored by Volker Schukai's avatar Volker Schukai :alien:
Browse files

fix: repair some small issues #274

parent 044d9d09
No related branches found
No related tags found
No related merge requests found
......@@ -3,4 +3,4 @@
commit = "512869a9a1e73b1da728accea668feeaf73ff513";
name = "Monster";
mnemonic = "monster";
}
\ No newline at end of file
}
This diff is collapsed.
......@@ -394,23 +394,28 @@ function initFilter() {
throw new Error("filter feature is enabled but no filter id is defined");
const filterControl = findElementWithIdUpwards(this, filterID);
if (!filterControl)
throw new Error(
if (!filterControl) {
addAttributeToken(
this,
ATTRIBUTE_ERRORMESSAGE,
"filter feature is enabled but no filter control with id " +
filterID +
" is found",
);
return;
}
this[filterObserverSymbol] = new Observer(() => {
const query = filterControl.getOption("query");
if (query === undefined) {
return;
}
this.setParameters({ query: query });
this.fetch()
.then((response) => {
if (!(response instanceof Response)) {
throw new Error("Response is not an instance of Response");
return Promise.reject(new Error("response is not a Response object"));
}
if (response?.ok === true) {
......
......@@ -22,6 +22,7 @@ import {
} from "../../dom/customelement.mjs";
import { datasourceLinkedElementSymbol } from "../datatable/util.mjs";
import { FormStyleSheet } from "./stylesheet/form.mjs";
import { addAttributeToken } from "../../dom/attributes.mjs";
export { Form };
......@@ -54,7 +55,6 @@ const debounceBindSymbol = Symbol("debounceBind");
*/
class Form extends DataSet {
/**
*
* @property {Object} templates Template definitions
* @property {string} templates.main Main template
* @property {Object} classes Class definitions
......@@ -199,7 +199,9 @@ function initEventHandler() {
this[debounceWriteBackSymbol] = new DeadMansSwitch(200, () => {
setTimeout(() => {
this.write();
this.write().catch((e) => {
addAttributeToken(this, "error", e.message || `${e}`);
});
}, 0);
});
});
......
......@@ -12,7 +12,12 @@
* SPDX-License-Identifier: AGPL-3.0
*/
export { internalSymbol, internalStateSymbol, instanceSymbol };
export {
internalSymbol,
internalStateSymbol,
instanceSymbol,
proxyInstanceMarker,
};
/**
* @private
......@@ -35,3 +40,11 @@ const internalStateSymbol = Symbol.for("@schukai/monster/state");
* @type {symbol}
*/
const instanceSymbol = Symbol.for("@schukai/monster/instance");
/**
* @private
* @type {symbol}
*/
const proxyInstanceMarker = Symbol.for(
"@schukai/monster/proxy-instance-marker",
);
......@@ -610,9 +610,13 @@ class CustomElement extends HTMLElement {
nodeList = elements;
}
this[updateCloneDataSymbol] = clone(
this[internalSymbol].getRealSubject()["options"],
);
try {
this[updateCloneDataSymbol] = clone(
this[internalSymbol].getRealSubject()["options"],
);
} catch (e) {
addAttributeToken(this, ATTRIBUTE_ERRORMESSAGE, e?.messages || `${e}`);
}
const cfg = {};
if (this.getOption("eventProcessing") === true) {
......
......@@ -307,7 +307,11 @@ function getControlEventHandler() {
}
queueMicrotask(() => {
retrieveAndSetValue.call(this, element);
try {
retrieveAndSetValue.call(this, element);
} catch (e) {
addAttributeToken(element, ATTRIBUTE_ERRORMESSAGE, e.message || `${e}`);
}
});
};
......
/**
* Copyright © schukai GmbH and all contributing authors, 2024. All rights reserved.
* Copyright © schukai GmbH and all contributing authors, 2025. All rights reserved.
* Node module: @schukai/monster
*
* This source code is licensed under the GNU Affero General Public License version 3 (AGPLv3).
......
......@@ -12,6 +12,8 @@
* SPDX-License-Identifier: AGPL-3.0
*/
import { proxyInstanceMarker } from "../constants.mjs";
export {
isIterable,
isPrimitive,
......@@ -23,8 +25,19 @@ export {
isArray,
isFunction,
isInteger,
isProxy,
};
/**
* Checks whether the value passed is a Proxy.
*
* @param {*} value
* @returns {boolean}
*/
function isProxy(value) {
return value?.[proxyInstanceMarker] === proxyInstanceMarker;
}
/**
* With this function you can check if a value is iterable.
*
......
......@@ -18,7 +18,7 @@ import { Observer } from "./observer.mjs";
import { ObserverList } from "./observerlist.mjs";
import { validateObject } from "./validate.mjs";
import { extend } from "../data/extend.mjs";
import { instanceSymbol } from "../constants.mjs";
import { instanceSymbol, proxyInstanceMarker } from "../constants.mjs";
import { clone } from "../util/clone.mjs";
export { ProxyObserver };
......@@ -74,7 +74,7 @@ class ProxyObserver extends Base {
/**
* @since 1.24.0
* @param {Object} obj
* @return {Monster.Types.ProxyObserver}
* @return {ProxyObserver}
*/
setSubject(obj) {
let i;
......@@ -152,6 +152,11 @@ function getHandler() {
const handler = {
// https://262.ecma-international.org/9.0/#sec-proxy-object-internal-methods-and-internal-slots-get-p-receiver
get: function (target, key, receiver) {
// this is an internal hack to identify proxy
if (key === proxyInstanceMarker) {
return proxyInstanceMarker;
}
const value = Reflect.get(target, key, receiver);
if (typeof key === "symbol") {
......
......@@ -13,7 +13,13 @@
*/
import { getGlobal } from "../types/global.mjs";
import { isArray, isFunction, isObject, isPrimitive } from "../types/is.mjs";
import {
isArray,
isFunction,
isObject,
isPrimitive,
isProxy,
} from "../types/is.mjs";
import { typeOf } from "../types/typeof.mjs";
import { validateObject } from "../types/validate.mjs";
......@@ -71,8 +77,7 @@ function clone(obj) {
/** Do not clone DOM nodes */
if (typeof Element !== "undefined" && obj instanceof Element) return obj;
if (typeof HTMLDocument !== "undefined" && obj instanceof HTMLDocument)
return obj;
if (typeof Document !== "undefined" && obj instanceof Document) return obj;
if (
typeof DocumentFragment !== "undefined" &&
obj instanceof DocumentFragment
......@@ -81,21 +86,11 @@ function clone(obj) {
/** Do not clone global objects */
if (obj === getGlobal()) return obj;
if (typeof globalContext !== "undefined" && obj === globalContext)
return obj;
if (typeof window !== "undefined" && obj === window) return obj;
if (typeof document !== "undefined" && obj === document) return obj;
if (typeof navigator !== "undefined" && obj === navigator) return obj;
if (typeof JSON !== "undefined" && obj === JSON) return obj;
// Handle Proxy-Object
try {
// try/catch because possible: TypeError: Function has non-object prototype 'undefined' in instanceof check
if (obj instanceof Proxy) {
return obj;
}
} catch (e) {}
if (isProxy(obj)) return obj; // Handle Proxy-Object
return cloneObject(obj);
}
......
......@@ -22,6 +22,24 @@ describe('Pathfinder', function () {
return r;
}
describe("value is not an integer issue #274", function () {
it("should not be fail with", function () {
const pf = new Pathfinder({
data: {}
});
try {
pf.setVia("data.age", 10);
} catch (e) {
expect(e).to.be.null;
}
expect(pf.getVia("data.age")).to.be.equal(10);
});
});
describe('with Wildcard and Iterations', function () {
let pf, obj;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment