google / jsaction Goto Github PK
View Code? Open in Web Editor NEWJsAction is a small event delegation library that decouples event binding from the code that can handle the event.
License: Apache License 2.0
JsAction is a small event delegation library that decouples event binding from the code that can handle the event.
License: Apache License 2.0
Hello,
When I try to dispatch an event in this way:
document.querySelector('input').dispatchEvent(new KeyboardEvent('keyup', {key: "a", code: "KeyA", keyCode: 65}))
nothing happens. Why?
How to dispatch browser events on an element?
There is currently no way to try out JsAction without installing/running Closure Compiler. This prevents, or at least discourages, many people from investigating the library.
If there was a way to easily add JsAction via a script tag, it could be used in CodePen/JS Bin/etc examples. For example, I believe JsAction could a great way to implement the Action Creators portion of the Flux architecture (map browser events to semantic events/functions) but I can't easily confirm or share examples with others.
The README says:
JsAction uncouples event handling from actual implementations. Thus one may late load the implementations, while the app is always able to respond to user actions marked up through JsAction.
But what handles responses to user actions before the implementations have loaded? I get that the dispatcher could observe the actions but then what does it do with them?
Hi there,
I'm a researcher studying software evolution. As part of my current research, I'm studying the implications of open-sourcing a proprietary software, for instance, if the project succeed in attracting newcomers. However, I observed that some projects, like jsaction, deleted their software history.
Knowing that software history is indispensable for developers (e.g., developers need to refer to history several times a day), I would like to ask jsaction developers the following four brief questions:
Thanks in advance for your collaboration,
Gustavo Pinto, PhD
http://www.gustavopinto.org
jsaction is a part of the Wiz framework which Google famously uses for most of its consumer web apps.
It seems like Wiz was decided to not be made open source, at the time, so as not to add to the war that was going on between React and Angular. Well, the war has passed and in these quieter times, I think Wiz would prove to be a fresh alternative to these and other JS heavy frameworks by being a more conservative middle ground.
CC: @cramforce
Reproduce: run tests in replay_test.js
Firefox has implemented KeyboardEvent.initKeyboardEvent, but it does not correctly set the keyCode or charCode.
Based on https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent, it looks like the preferred way to create these events is with the KeyboardEvent constructor (both initKeyEvent and initKeyboardEvent are deprecated). The most surprising part of this to me, is that MDN also says Gecko will not implement initKeyboardEvent, but it appears that something has changed.
I can't find any reference to 'jsprops' in the source code.
I hope the warnings will be fixed sooner then the PR for the same issue (2 years delay)
Would be nice to see it in the list at https://github.com/google. Thanks!
One problem with event delegation in general is that it can defeat efforts from the browser to try to guess what elements are activateable. Eg. Chrome has a 'touch adjustment' heuristic which is necessary to get good touch targeting on websites not specifically designed for touch. Without any event handler, :active/:hover effect or other indication that an element is tappable, Chrome will slightly bias taps towards other elements under the contact area of the finger. Safari and IE do something like this too, but details aren't available (and they probably do a better job at avoiding issues than us!).
Here is an example where using jsaction in conjunction with Chrome's touch adjustment behavior triggered confusion / problems.
Perhaps jsaction should do something to continue to give the browser a signal that such elements are really tappable? Eg. Maybe it should register dummy event handlers on the elements? I'm happy to make changes to Blink here if we can agree on some protocol, but it should be based around standard APIs (not library-level conventions). Eg. we don't currently take ARIA role attributes into account in this heuristic, but perhaps we should? Longer term, maybe we should try to standardize an API like Element.supportsActivation which you could explicitly set to true when our heuristics don't guess correctly?
Thoughts?
Example markup:
<div id="timeline" jsnamespace="Timeline">
<div id="tweet" jsnamespace="Tweet" jsaction="viewDetail">
<div>...</div>
<div>...</div>
<div>...</div>
</div>
</div>
Assume that (via data-jsaction-events
attr or programatically) the container for each namespace is the node with the corresponding jsnamespace attr.
My goal:
Define "viewDetail" jsaction in the "Tweet" namespace (because the alternative is to add it to each of the three subnodes)
What happens:
tweet
node.For the Tweet
container, the DOM walk at 2a will quit before it reaches that container so the viewDetail
action will be ignored.
Summary:
jsActions defined in the same node as jsNamespace are ignored.
Notes/Fixes/Workarounds
for (var node = target; node && node != container.parentNode;
document.body
).<div id="timeline" jsnamespace="Timeline">
<div id="tweet" jsnamespace="Tweet">
<div jsaction="viewDetail">...</div>
<div jsaction="viewDetail">...</div>
<div jsaction="viewDetail">...</div>
</div>
</div>
Tweet
container DOM walk still quits before it reaches the jsAction.viewDetail
action to be associated with the Timeline namespace, that fails with the above markup because the qualifying namespace code at 2b will always find the Tweet
namespace attr first (unlike 2a it looks at the container node). We could fix this by prequalifying the jsAction as "Timeline.viewDetail" but this may be more information than we want the child component markup to know. For the Timeline
container, that DOM walk will reach the viewDetail
action. But then 2b kicks in to find the qualifying namespace. Because 2b's DOM walk starts at the jsaction node, it will immediately see the Tweet
jsnamespace attribute and assign it to the action. Given that the container is for Timeline
, assigning the jsAction with the Tweet
namespace is counter-intuitiveQuestions:
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.