javascript - Durandal TodoMVC - Cannot write a value to a ko.computed -
i'm trying build version of todo app using durandal (including knockout + requirejs) todomvc template. realize todo app doesn't show off features of durandal, i'm on learning path , figured first project.
anyway, in process i've stumbled upon error i'm unable solve (see below).
error("cannot write value ko.computed unless specify 'write' option. if wish read current value, don't pass parameters.")
i've attached image shows these in console.
you can find source code @ https://github.com/robksawyer/durandal-todo. todo viewmodel located @ https://github.com/robksawyer/durandal-todo/blob/master/viewmodels/todos.js.
update: of knockout code borrowed knockout+require todomvc project @ https://github.com/tastejs/todomvc/tree/gh-pages/labs/dependency-examples/knockoutjs_require/
thanks time.
i think you're misreading console.
for example, "allcompleted" property on view model, declared dependent observable (i.e. "computed"):
// writeable computed observable handle marking complete/incomplete self.allcompleted = ko.computed({ // -- trimmed -- });
what you're seeing in console isn't cannot write value
error; it's debug output computed
property - i.e. function definition. reference, here's function definition of dependent observable straight knockout (2.2.1) source:
function dependentobservable() { if (arguments.length > 0) { if (typeof writefunction === "function") { // writing value writefunction.apply(evaluatorfunctiontarget, arguments); } else { throw new error("cannot write value ko.computed unless specify 'write' option. if wish read current value, don't pass parameters."); } return this; // permits chained assignments } else { // reading value if (!_hasbeenevaluated) evaluateimmediate(); ko.dependencydetection.registerdependency(dependentobservable); return _latestvalue; } }
what you're seeing in console minified version of code.
if want see value that's returned property you'd have invoke it.
Comments
Post a Comment