Giter Site home page Giter Site logo

Comments (5)

maskmaster avatar maskmaster commented on June 11, 2024 1

Using a helper-function like

data-bind="click: utils.preventDefault(event => setSomeValue('foo'))"

would be a more terse variant. The exact semantics from knockout could in this case be retained.

Of course, if preventDefault needs to be observable we might need to do it like

data-bind="click: event => { setSomeValue('foo')); return $data.shouldPreventDefault; }"

A third alternative, and in my opinion more semantically correct, is to create your own binding handler "capturedClick" or something like that, where you describe the functionality instead of implementing/open-coding it in the view.

from tko.

brianmhunt avatar brianmhunt commented on June 11, 2024 1

Closing this as I trust it's closed, but we can always re-open if there's more to discuss here.

from tko.

brianmhunt avatar brianmhunt commented on June 11, 2024

@danieldickison I think this scratches an itch a few people will have. 😀

from tko.

tscpp avatar tscpp commented on June 11, 2024

Isn't this what we have a viewModel for? This will put logic into the view which has always been avoided in knockout which has been one of the main reasons to prefer it from any other framework or library.

This will also be very confusing when reusing an even handler method. Will the method depend on the view to preventDefault?

Also, what about stopPropagation() and stopImmediatePropagation()? These functions and preventDefault() is functions, not options.

from tko.

brianmhunt avatar brianmhunt commented on June 11, 2024

I tend to think there are two "correct" solutions here.

1. The best option for a system where you know what you need and have total control is what @maskmaster suggested:

A third alternative, and in my opinion more semantically correct, is to create your own binding handler "capturedClick" or something like that, where you describe the functionality instead of implementing/open-coding it in the view.

No library changes would be needed for this.

2. a preferable option for a "drop-in" pre-built library, when experimenting (e.g. before knowing what works), or behavioural visibility is better in the binding, can be to have a parameterized system...as @tscpp noted:

Also, what about stopPropagation() and stopImmediatePropagation()? These functions and preventDefault() is functions, not options.

in which case stopPropagation and stopImmediatePropagation ought to be parameters in the library as well.

There's nothing stopping folks from using a function e.g. utils.preventDefault but that doesn't require any library changes.

from tko.

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.