diff --git a/package.json b/package.json old mode 100644 new mode 100755 index 96b063c..9f7f652 --- a/package.json +++ b/package.json @@ -5,9 +5,6 @@ "private": false, "description": "Dont use variable, use smart variable wires !", "main": "wire.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, "repository": { "type": "git", "url": "https://git.saqut.com/saqut/wirejs.git" diff --git a/readme.md b/readme.md old mode 100644 new mode 100755 diff --git a/wire.js b/wire.js old mode 100644 new mode 100755 index 9d598e8..350aaba --- a/wire.js +++ b/wire.js @@ -67,7 +67,35 @@ } é.fingerPrint = Symbol("wire"); é.isWire = n => n?.fp == é.fingerPrint; - é.extract = (e,v) => typeof e=='function'?e(v):e; + é.extract = (e,v) => { + if(typeof e=='function') + { + return é.freeze(e(v)) + }else{ + return é.freeze(e); + } + }; + é.freeze = a => { + if(Object.isFrozen(a)) + { + return a; + } + switch(typeof a) + { + case "object":{ + let k = Object.assign({}, a); + for (const [name, value] of Object.entries(k)) { + if(typeof value == "object") + { + k[name]=é.freeze(value); + } + }; + Object.freeze(k); + return k; + } + default: return a; + }; + }; é.isSame = (a,b) => !é.diff(a,b); é.watch = (fn, assoc) => { for (const wireVar of assoc) @@ -149,17 +177,17 @@ { case "undefined": case "function":{ - return typeof a == typeof b ? é.cDiff.some : é.cDiff.different + return typeof a == typeof b ? cDiff.some : cDiff.different } case "symbol": case "bigint": case "boolean": case "number": case "string":{ - return a === b ? é.cDiff.some : é.cDiff.different; + return a === b ? cDiff.some : cDiff.different; } case "object":{ - return é.cDiff.adiff; + return cDiff.adiff; } }; } @@ -209,7 +237,7 @@ }; const schedule = function(fn){ schedule.jobs.push(fn) - if(!é.schedule.executing) + if(!schedule.executing) { requestAnimationFrame(()=>{ for (const fn of schedule.jobs) { @@ -218,7 +246,8 @@ }catch(e){ console.error(e) } - } + }; + schedule.jobs=[]; }) } };