Giter VIP home page Giter VIP logo

Comments (7)

ZiadJ avatar ZiadJ commented on June 19, 2024

I've modified the sample code to include yours but couldn't get any error. Here it is:
http://plnkr.co/edit/pyaadTBIzBwxdfVQa3s2?p=preview

And here's the test code:

ko.watch(vm.name, { depth: -1 }, function (parents, child, item) {
    alert(child());
}, this);

from knockoutjs-reactor.

Trapulo avatar Trapulo commented on June 19, 2024

The only difference I see is that I tried to setup ko.watch from code INSIDE the vm itself. Can be this the problem?

from knockoutjs-reactor.

ZiadJ avatar ZiadJ commented on June 19, 2024

@Trapulo Ok I've set up ko.watch "inside the vm" here:
http://plnkr.co/edit/g9YvhLKHzDjE8WQGFbe5?p=preview
Am I missing anything else? Not sure I got you right.

from knockoutjs-reactor.

Trapulo avatar Trapulo commented on June 19, 2024

your
// Log changes in the view model.
ko.watch(vm, {...
is outside of
var vm = {...

Basically I tried to have a watcher activated inside the vm (in "constructor", or in an event handler).
However, because my project is quite complex and also I'm using typescript as js source, I've implemented a more fine and custom tuned solution using koLite as sample. I'll try again to insert your library when I will need the undo feature.

Thanks for your assistance.

from knockoutjs-reactor.

ZiadJ avatar ZiadJ commented on June 19, 2024

Glad you found your way out. So that explains the term "TypeError" in your error message. That might be because ko.watch uses optional and dynamically typed arguments which is confusing the TypeScript compiler.

The workaround then is to define an interface for ko.watch that takes in all the parameter types separately like overrides in static languages. That's just my 2 cents though. I haven't had a chance to try TypeScript myself but I'm looking forward to it.

You're welcome.

from knockoutjs-reactor.

Trapulo avatar Trapulo commented on June 19, 2024

Sorry for late reply.

Strange, because the compiler didn't report any error.
However I will notify result of future tests. Thanks for your assistance, I appreciate it.

from knockoutjs-reactor.

ZiadJ avatar ZiadJ commented on June 19, 2024

Ok I'm looking forward to that. It would be great if you could reproduce the error by modifying the sample code I sent you earlier.

But now that I'm reconsidering your issue I'm realizing that this error is thrown when calling an object like a function(with parentheses) but it isn't a function. So it might have nothing to do with TypeScript in itself. In your case it means options is somehow being called like a function but I have no idea how. If the error message is not helping you locate it then you might consider setting up a few break points and stepping through the code until the error occurs. Also make sure your target object is fully generated when you're setting up the watcher because altering the target structure later on can confuse it. You can always try setting the mutable option to true to get around it but it only works when the changes occur within an observable. You might also try setting hideWrappedValues to true so as to prevent child() from being called just in case it's not a function as assumed inside my code where it is called.

from knockoutjs-reactor.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.