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
This diff is collapsed.
...@@ -394,23 +394,28 @@ function initFilter() { ...@@ -394,23 +394,28 @@ function initFilter() {
throw new Error("filter feature is enabled but no filter id is defined"); throw new Error("filter feature is enabled but no filter id is defined");
const filterControl = findElementWithIdUpwards(this, filterID); const filterControl = findElementWithIdUpwards(this, filterID);
if (!filterControl) if (!filterControl) {
throw new Error( addAttributeToken(
this,
ATTRIBUTE_ERRORMESSAGE,
"filter feature is enabled but no filter control with id " + "filter feature is enabled but no filter control with id " +
filterID + filterID +
" is found", " is found",
); );
return;
}
this[filterObserverSymbol] = new Observer(() => { this[filterObserverSymbol] = new Observer(() => {
const query = filterControl.getOption("query"); const query = filterControl.getOption("query");
if (query === undefined) { if (query === undefined) {
return; return;
} }
this.setParameters({ query: query }); this.setParameters({ query: query });
this.fetch() this.fetch()
.then((response) => { .then((response) => {
if (!(response instanceof 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) { if (response?.ok === true) {
......
...@@ -22,6 +22,7 @@ import { ...@@ -22,6 +22,7 @@ import {
} from "../../dom/customelement.mjs"; } from "../../dom/customelement.mjs";
import { datasourceLinkedElementSymbol } from "../datatable/util.mjs"; import { datasourceLinkedElementSymbol } from "../datatable/util.mjs";
import { FormStyleSheet } from "./stylesheet/form.mjs"; import { FormStyleSheet } from "./stylesheet/form.mjs";
import { addAttributeToken } from "../../dom/attributes.mjs";
export { Form }; export { Form };
...@@ -54,7 +55,6 @@ const debounceBindSymbol = Symbol("debounceBind"); ...@@ -54,7 +55,6 @@ const debounceBindSymbol = Symbol("debounceBind");
*/ */
class Form extends DataSet { class Form extends DataSet {
/** /**
*
* @property {Object} templates Template definitions * @property {Object} templates Template definitions
* @property {string} templates.main Main template * @property {string} templates.main Main template
* @property {Object} classes Class definitions * @property {Object} classes Class definitions
...@@ -199,7 +199,9 @@ function initEventHandler() { ...@@ -199,7 +199,9 @@ function initEventHandler() {
this[debounceWriteBackSymbol] = new DeadMansSwitch(200, () => { this[debounceWriteBackSymbol] = new DeadMansSwitch(200, () => {
setTimeout(() => { setTimeout(() => {
this.write(); this.write().catch((e) => {
addAttributeToken(this, "error", e.message || `${e}`);
});
}, 0); }, 0);
}); });
}); });
......
...@@ -12,7 +12,12 @@ ...@@ -12,7 +12,12 @@
* SPDX-License-Identifier: AGPL-3.0 * SPDX-License-Identifier: AGPL-3.0
*/ */
export { internalSymbol, internalStateSymbol, instanceSymbol }; export {
internalSymbol,
internalStateSymbol,
instanceSymbol,
proxyInstanceMarker,
};
/** /**
* @private * @private
...@@ -35,3 +40,11 @@ const internalStateSymbol = Symbol.for("@schukai/monster/state"); ...@@ -35,3 +40,11 @@ const internalStateSymbol = Symbol.for("@schukai/monster/state");
* @type {symbol} * @type {symbol}
*/ */
const instanceSymbol = Symbol.for("@schukai/monster/instance"); 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 { ...@@ -610,9 +610,13 @@ class CustomElement extends HTMLElement {
nodeList = elements; nodeList = elements;
} }
try {
this[updateCloneDataSymbol] = clone( this[updateCloneDataSymbol] = clone(
this[internalSymbol].getRealSubject()["options"], this[internalSymbol].getRealSubject()["options"],
); );
} catch (e) {
addAttributeToken(this, ATTRIBUTE_ERRORMESSAGE, e?.messages || `${e}`);
}
const cfg = {}; const cfg = {};
if (this.getOption("eventProcessing") === true) { if (this.getOption("eventProcessing") === true) {
......
...@@ -307,7 +307,11 @@ function getControlEventHandler() { ...@@ -307,7 +307,11 @@ function getControlEventHandler() {
} }
queueMicrotask(() => { queueMicrotask(() => {
try {
retrieveAndSetValue.call(this, element); 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 * Node module: @schukai/monster
* *
* This source code is licensed under the GNU Affero General Public License version 3 (AGPLv3). * This source code is licensed under the GNU Affero General Public License version 3 (AGPLv3).
......
...@@ -12,6 +12,8 @@ ...@@ -12,6 +12,8 @@
* SPDX-License-Identifier: AGPL-3.0 * SPDX-License-Identifier: AGPL-3.0
*/ */
import { proxyInstanceMarker } from "../constants.mjs";
export { export {
isIterable, isIterable,
isPrimitive, isPrimitive,
...@@ -23,8 +25,19 @@ export { ...@@ -23,8 +25,19 @@ export {
isArray, isArray,
isFunction, isFunction,
isInteger, 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. * With this function you can check if a value is iterable.
* *
......
...@@ -18,7 +18,7 @@ import { Observer } from "./observer.mjs"; ...@@ -18,7 +18,7 @@ import { Observer } from "./observer.mjs";
import { ObserverList } from "./observerlist.mjs"; import { ObserverList } from "./observerlist.mjs";
import { validateObject } from "./validate.mjs"; import { validateObject } from "./validate.mjs";
import { extend } from "../data/extend.mjs"; import { extend } from "../data/extend.mjs";
import { instanceSymbol } from "../constants.mjs"; import { instanceSymbol, proxyInstanceMarker } from "../constants.mjs";
import { clone } from "../util/clone.mjs"; import { clone } from "../util/clone.mjs";
export { ProxyObserver }; export { ProxyObserver };
...@@ -74,7 +74,7 @@ class ProxyObserver extends Base { ...@@ -74,7 +74,7 @@ class ProxyObserver extends Base {
/** /**
* @since 1.24.0 * @since 1.24.0
* @param {Object} obj * @param {Object} obj
* @return {Monster.Types.ProxyObserver} * @return {ProxyObserver}
*/ */
setSubject(obj) { setSubject(obj) {
let i; let i;
...@@ -152,6 +152,11 @@ function getHandler() { ...@@ -152,6 +152,11 @@ function getHandler() {
const handler = { const handler = {
// https://262.ecma-international.org/9.0/#sec-proxy-object-internal-methods-and-internal-slots-get-p-receiver // https://262.ecma-international.org/9.0/#sec-proxy-object-internal-methods-and-internal-slots-get-p-receiver
get: function (target, key, 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); const value = Reflect.get(target, key, receiver);
if (typeof key === "symbol") { if (typeof key === "symbol") {
......
...@@ -13,7 +13,13 @@ ...@@ -13,7 +13,13 @@
*/ */
import { getGlobal } from "../types/global.mjs"; 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 { typeOf } from "../types/typeof.mjs";
import { validateObject } from "../types/validate.mjs"; import { validateObject } from "../types/validate.mjs";
...@@ -71,8 +77,7 @@ function clone(obj) { ...@@ -71,8 +77,7 @@ function clone(obj) {
/** Do not clone DOM nodes */ /** Do not clone DOM nodes */
if (typeof Element !== "undefined" && obj instanceof Element) return obj; if (typeof Element !== "undefined" && obj instanceof Element) return obj;
if (typeof HTMLDocument !== "undefined" && obj instanceof HTMLDocument) if (typeof Document !== "undefined" && obj instanceof Document) return obj;
return obj;
if ( if (
typeof DocumentFragment !== "undefined" && typeof DocumentFragment !== "undefined" &&
obj instanceof DocumentFragment obj instanceof DocumentFragment
...@@ -81,21 +86,11 @@ function clone(obj) { ...@@ -81,21 +86,11 @@ function clone(obj) {
/** Do not clone global objects */ /** Do not clone global objects */
if (obj === getGlobal()) return obj; if (obj === getGlobal()) return obj;
if (typeof globalContext !== "undefined" && obj === globalContext)
return obj;
if (typeof window !== "undefined" && obj === window) return obj; if (typeof window !== "undefined" && obj === window) return obj;
if (typeof document !== "undefined" && obj === document) return obj; if (typeof document !== "undefined" && obj === document) return obj;
if (typeof navigator !== "undefined" && obj === navigator) return obj; if (typeof navigator !== "undefined" && obj === navigator) return obj;
if (typeof JSON !== "undefined" && obj === JSON) return obj; if (typeof JSON !== "undefined" && obj === JSON) return obj;
if (isProxy(obj)) return obj; // Handle Proxy-Object
// 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) {}
return cloneObject(obj); return cloneObject(obj);
} }
......
...@@ -22,6 +22,24 @@ describe('Pathfinder', function () { ...@@ -22,6 +22,24 @@ describe('Pathfinder', function () {
return r; 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 () { describe('with Wildcard and Iterations', function () {
let pf, obj; let pf, obj;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment