Comments (5)
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.
Closing this as I trust it's closed, but we can always re-open if there's more to discuss here.
from tko.
@danieldickison I think this scratches an itch a few people will have. 😀
from tko.
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.
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)
- Deprecate unused npm packages HOT 2
- Convert legacy documentation
- Replace hard-coded parser unicode identifier detection with RegExp HOT 3
- optionsText with a lambda value fails to resolve the function argument HOT 2
- Incorrect tree with multiple 'or' operators in parser HOT 1
- Unable to load from an ES module HOT 1
- TypeError: Cannot set properties of undefined (setting 'ko') HOT 1
- Re-enable tests on builds/knockout HOT 2
- `options.bindingGlobals` can't be changed at runtime
- Revamp www.tko.io
- Fix typing of the Observable<boolean> HOT 5
- Change mappingHelpers `objectLookup` from an O(n) array to O(1) Map
- Fix the build / exports in package.json
- Build @tko/build.reference into the `tko` package
- Server side render SSR support
- How to build and import TKO-beta as a bundled library. HOT 3
- [beta1.3] ESM support HOT 3
- Writable computed out of sync
- If you have multiple || (ORs), you need parentheses, otherwise it fails silently HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tko.