1

I am upgrading my knockout project to durandal and noticed that some standard knockout bindings are not working as expected.

Knockout does not make any difference between this:

<!-- ko text: someObservable" --><!-- /ko -->

and this:

<!-- ko text: someObservable()" --><!-- /ko -->

Durandal's composition engine does not seem to handle the first case (without parantheses) correctly. I end up with string representation of dependentObservable function instead of it's value:

function dependentObservable() {          if (arguments.length > 0) {              if (typeof writeFunction === "function") {                  // Writing a value                  writeFunction.apply(evaluatorFunctionTarget, arguments);              } else {                  throw new Error("Cannot write a value to a ko.computed unless you specify a 'write' option. If you wish to read the current value, don't pass any parameters.");              }              return this; // Permits chained assignments          } else {              // Reading the value              if (!_hasBeenEvaluated)                  evaluateImmediate();              ko.dependencyDetection.registerDependency(dependentObservable);              return _latestValue;          }      }

Does durandal require parantheses at the end of binding string or is it configurable somehow?

Dziamid
  • 11,225
  • 12
  • 69
  • 104
  • 2
    This should work in general so there is no special setting or config option. However you should make sure that you don't have observables containing other observables. So please check that your `someObservable` contains the actual value and not another observable. – nemesv Aug 24 '14 at 17:01
  • Definitely agree with nemesv here verified this works many times over. – PW Kad Aug 25 '14 at 03:11

1 Answers1

1

The problem was that I included knockout library twice: it was loaded both synchronously and via requirejs. It turns out requirejs will still load script, even if it is already loaded synchronously.

Adding this to main.js solves the problem:

define('knockout', [], function() {
    return ko;
});
Dziamid
  • 11,225
  • 12
  • 69
  • 104