Skip to content
This repository was archived by the owner on Nov 4, 2024. It is now read-only.

Commit 1b0dd48

Browse files
author
djmaze
committed
KnockoutJS don't throw error when property is not observable
1 parent 3893849 commit 1b0dd48

File tree

3 files changed

+65
-104
lines changed

3 files changed

+65
-104
lines changed

vendors/knockout/build/output/knockout-latest.debug.js

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1362,9 +1362,9 @@ ko.expressionRewriting = (() => {
13621362
divisionLookBehind = /[\])"'A-Za-z0-9_$]+$/,
13631363
keywordRegexLookBehind = {'in':1,'return':1,'typeof':1},
13641364

1365-
parseObjectLiteral = objectLiteralString => {
1365+
preProcessBindings = bindingsStringOrKeyValueArray => {
13661366
// Trim leading and trailing spaces from the string
1367-
var str = ko.utils.stringTrim(objectLiteralString);
1367+
var str = ko.utils.stringTrim(bindingsStringOrKeyValueArray);
13681368

13691369
// Trim braces '{' surrounding the whole object literal
13701370
if (str.charCodeAt(0) === 123) str = str.slice(1, -1);
@@ -1383,9 +1383,10 @@ ko.expressionRewriting = (() => {
13831383
// A comma signals the end of a key/value pair if depth is zero
13841384
if (c === 44) { // ","
13851385
if (depth <= 0) {
1386-
result.push((key && values.length)
1387-
? {key: key, value: values.join('')}
1388-
: {'unknown': key || values.join('')});
1386+
if (key && values.length) {
1387+
// Values are wrapped in a function so that each value can be accessed independently
1388+
result.push("'" + key + "':()=>(" + values.join('') + ")");
1389+
}
13891390
key = depth = 0;
13901391
values = [];
13911392
continue;
@@ -1426,34 +1427,13 @@ ko.expressionRewriting = (() => {
14261427
throw Error("Unbalanced parentheses, braces, or brackets");
14271428
}
14281429
}
1429-
return result;
1430-
},
1431-
1432-
preProcessBindings = (bindingsStringOrKeyValueArray) => {
14331430

1434-
var resultStrings = [],
1435-
// propertyAccessorResultStrings = [],
1436-
keyValueArray = parseObjectLiteral(bindingsStringOrKeyValueArray),
1437-
1438-
processKeyValue = (key, val) => {
1439-
// Values are wrapped in a function so that each value can be accessed independently
1440-
val = 'function(){return ' + val + ' }';
1441-
resultStrings.push("'" + key + "':" + val);
1442-
};
1431+
result.push("'$data':()=>$data");
14431432

1444-
keyValueArray.forEach(keyValue =>
1445-
processKeyValue(keyValue.key || keyValue['unknown'], keyValue.value)
1446-
);
1447-
/*
1448-
if (propertyAccessorResultStrings.length)
1449-
processKeyValue('_ko_property_writers', "{" + propertyAccessorResultStrings.join(",") + " }");
1450-
*/
1451-
return resultStrings.join(",");
1433+
return result.join(",");
14521434
};
14531435

14541436
return {
1455-
parseObjectLiteral: parseObjectLiteral,
1456-
14571437
preProcessBindings: preProcessBindings,
14581438

14591439
keyValueArrayContainsKey: (keyValueArray, key) =>
@@ -1471,8 +1451,9 @@ ko.expressionRewriting = (() => {
14711451
// it is !== existing value on that writable observable
14721452
writeValueToProperty: (element, property, allBindings, key, value, checkIfDifferent) => {
14731453
if (!property || !ko.isObservable(property)) {
1474-
throw Error(`"${key}" must be observable for ${element.outerHTML.replace(/>.+/,'>')}`);
1475-
// allBindings.get('_ko_property_writers')?.[key]?.(value);
1454+
console.error(`"${key}" should be observable in ${element.outerHTML.replace(/>.+/,'>')}`);
1455+
// ko.dataFor(element).key = value;
1456+
allBindings.get('$data')[key] = value;
14761457
} else if (ko.isWriteableObservable(property) && (!checkIfDifferent || property.peek() !== value)) {
14771458
property(value);
14781459
}

0 commit comments

Comments
 (0)