Fix Knockout binding non-Observable notice

This commit is contained in:
the-djmaze 2024-10-23 00:52:01 +02:00
parent 3a589e240c
commit bce9758338
3 changed files with 3 additions and 3 deletions

View file

@ -1450,7 +1450,7 @@ ko.expressionRewriting = (() => {
// it is !== existing value on that writable observable
writeValueToProperty: (element, property, allBindings, key, value, checkIfDifferent) => {
if (!property || !ko.isObservable(property)) {
console.error(`"${key}" should be observable in ${element.outerHTML.replace(/>.+/,'>')}`);
console.log(`"${key}" should contain observable in ${element.outerHTML.replace(/>.+/,'>')}`);
// ko.dataFor(element).key = value;
allBindings.get('$data')[key] = value;
} else if (ko.isWriteableObservable(property) && (!checkIfDifferent || property.peek() !== value)) {

View file

@ -28,7 +28,7 @@ null,d.G=0,b.T()&&b.Ea();else{var e=[];c.g.K(d.v,(g,l)=>e[l.fa]=g);e.forEach((g,
c.o);c.isComputed=a=>"function"==typeof a&&a[N]===K[N];c.xb=a=>{if("function"===typeof a)return c.o(a,{pure:!0});a={...a,pure:!0};return c.o(a)};c.C={M:a=>{switch(a.nodeName){case "OPTION":return!0===a.__ko__hasDomDataOptionValue__?c.g.l.get(a,c.i.options.Wa):a.value;case "SELECT":return 0<=a.selectedIndex?c.C.M(a.options[a.selectedIndex]):void 0;default:return a.value}},Fa:(a,b)=>{switch(a.nodeName){case "OPTION":"string"===typeof b?(c.g.l.set(a,c.i.options.Wa,void 0),delete a.__ko__hasDomDataOptionValue__,
a.value=b):(c.g.l.set(a,c.i.options.Wa,b),a.__ko__hasDomDataOptionValue__=!0,a.value="number"===typeof b?b:"");break;case "SELECT":for(var d=-1,e=""===(b??""),g=a.options.length,l;g--;)if(l=c.C.M(a.options[g]),l==b||""===l&&e){d=g;break}if(0<=d||e&&1<a.size)a.selectedIndex=d;break;default:a.value=b??""}}};c.la=(()=>{var a=RegExp("\"(?:\\\\.|[^\"])*\"|'(?:\\\\.|[^'])*'|`(?:\\\\.|[^`])*`|/\\*(?:[^*]|\\*+[^*/])*\\*+/|//.*\n|/(?:\\\\.|[^/])+/w*|[^\\s:,/][^,\"'`{}()/:[\\]]*[^\\s,\"'`{}()/:[\\]]|[^\\s]",
"g"),b=/[\])"'A-Za-z0-9_$]+$/,d={"in":1,"return":1,"typeof":1};return{Yb:e=>{e=c.g.Bb(e);123===e.charCodeAt(0)&&(e=e.slice(1,-1));e+="\n,";var g=[],l=e.match(a),f=[],h=0;if(1<l.length){for(var k=0,m;m=l[k++];){var p=m.charCodeAt(0);if(44===p){if(0>=h){n&&f.length&&g.push("'"+n+"':()=>("+f.join("")+")");var n=h=0;f=[];continue}}else if(58===p){if(!h&&!n&&1===f.length){n=f.pop();continue}}else if(47===p&&1<m.length&&(47===m.charCodeAt(1)||42===m.charCodeAt(1)))continue;else 47===p&&k&&1<m.length?(p=
l[k-1].match(b))&&!d[p[0]]&&(e=e.slice(e.indexOf(m)+1),l=e.match(a),k=-1,m="/"):40===p||123===p||91===p?++h:41===p||125===p||93===p?--h:n||f.length||34!==p&&39!==p||(m=m.slice(1,-1));f.push(m)}if(0<h)throw Error("Unbalanced parentheses, braces, or brackets");}g.push("'$data':()=>$data");return g.join(",")},cc:(e,g)=>-1<e.findIndex(l=>l.key==g),Ga:(e,g,l,f,h,k)=>{g&&c.W(g)?!c.vb(g)||k&&g.L()===h||g(h):(console.error(`"${f}" should be observable in ${e.outerHTML.replace(/>.+/,">")}`),l.get("$data")[f]=
l[k-1].match(b))&&!d[p[0]]&&(e=e.slice(e.indexOf(m)+1),l=e.match(a),k=-1,m="/"):40===p||123===p||91===p?++h:41===p||125===p||93===p?--h:n||f.length||34!==p&&39!==p||(m=m.slice(1,-1));f.push(m)}if(0<h)throw Error("Unbalanced parentheses, braces, or brackets");}g.push("'$data':()=>$data");return g.join(",")},cc:(e,g)=>-1<e.findIndex(l=>l.key==g),Ga:(e,g,l,f,h,k)=>{g&&c.W(g)?!c.vb(g)||k&&g.L()===h||g(h):(console.log(`"${f}" should contain observable in ${e.outerHTML.replace(/>.+/,">")}`),l.get("$data")[f]=
h)}}})();(()=>{function a(f){return 8==f.nodeType&&e.test(f.nodeValue)}function b(f){return 8==f.nodeType&&g.test(f.nodeValue)}function d(f,h){for(var k=f,m=1,p=[];k=k.nextSibling;){if(b(k)&&(c.g.l.set(k,l,!0),!--m))return p;p.push(k);a(k)&&++m}if(!h)throw Error("Cannot find closing comment tag to match: "+f.nodeValue);return null}var e=/^\s*ko(?:\s+([\s\S]+))?\s*$/,g=/^\s*\/ko\s*$/,l="__ko_matchedEndComment__";c.m={aa:{},childNodes:f=>a(f)?d(f):f.childNodes,ja:f=>{a(f)?(f=d(f))&&[...f].forEach(h=>
c.removeNode(h)):c.g.Qa(f)},pa:(f,h)=>{a(f)?(c.m.ja(f),f.after(...h)):c.g.pa(f,h)},prepend:(f,h)=>{a(f)?f.nextSibling.before(h):f.prepend(h)},Ub:(f,h,k)=>{k?k.after(h):c.m.prepend(f,h)},firstChild:f=>{if(a(f))return f=f.nextSibling,!f||b(f)?null:f;let h=f.firstChild;if(h&&b(h))throw Error("Found invalid end comment, as the first child of "+f);return h},nextSibling:f=>{if(a(f)){var h=d(f,void 0);f=h?(h.length?h[h.length-1]:f).nextSibling:null}if((h=f.nextSibling)&&b(h)){if(b(h)&&!c.g.l.get(h,l))throw Error("Found end comment without a matching opening comment, as child of "+
f);return null}return h},Qb:a,ac:f=>(f=f.nodeValue.match(e))?f[1]:null}})();const S=new Map;c.ob=new class{Xb(a){switch(a.nodeType){case 1:return null!=a.getAttribute("data-bind");case 8:return c.m.Qb(a)}return!1}Ob(a,b){a:{switch(a.nodeType){case 1:a=a.getAttribute("data-bind");break a;case 8:a=c.m.ac(a);break a}a=null}if(a)try{let e=S.get(a);if(!e){var d="$context = new Proxy( $context, { has: () => true, get: (target, key) => target[key] || target['$data'][key] } );with($context){return{"+

View file

@ -134,7 +134,7 @@ ko.expressionRewriting = (() => {
// it is !== existing value on that writable observable
writeValueToProperty: (element, property, allBindings, key, value, checkIfDifferent) => {
if (!property || !ko.isObservable(property)) {
console.error(`"${key}" should be observable in ${element.outerHTML.replace(/>.+/,'>')}`);
console.log(`"${key}" should contain observable in ${element.outerHTML.replace(/>.+/,'>')}`);
// ko.dataFor(element).key = value;
allBindings.get('$data')[key] = value;
} else if (ko.isWriteableObservable(property) && (!checkIfDifferent || property.peek() !== value)) {