TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Google open-sources JsAction, a JavaScript event delegation library

64 pointsby ruidlopesabout 11 years ago

13 comments

scotty79about 11 years ago
So this (with specialized lib, and fairly large unintuitive js code to set whole thing up):<p><pre><code> &lt;div id=&quot;foo&quot; jsaction=&quot;leftNav.clickAction; dblclick:leftNav.doubleClickAction&quot;&gt; </code></pre> is pretty much the same as this:<p><pre><code> &lt;div id=&quot;foo&quot; onclick=&quot;Actions.leftNav.clickAction()&quot; ondblclick=&quot;Actions.leftNav.doubleClickAction()&quot;&gt; </code></pre> without any abusing or manipulating of html and dom and with setup as simple and understandable as this:<p><pre><code> window.Actions = { leftNav: { clickAction: function() { myApp.LeftNav.doSomeSeriousStuff(); }, doubleClickAction: function() { &#x2F;&#x2F; very late loading of implementation require(&quot;LeftNavActions&quot;, function(LeftNavActions) { LeftNavActions.doSomeOtherSeriousStuff(); }) }, &#x2F;&#x2F; if you want add handlers from other places &#x2F;&#x2F; with Actions.leftNav._anotherAction.push() _anotherAction: [], anotherAction: function() { this._anotherAction.forEach(function(a) { a(); }); } } } </code></pre> Actions is a good idea that I remember from Delphi 4. It is just one additional layer of indirection that enables you to attach same behavior for example to menu option and toolbar button.
评论 #7788087 未加载
评论 #7824698 未加载
floatrockabout 11 years ago
The API could use some work. To implement the simplest example, I need to remember patterns like:<p>&gt; eventContract.dispatchTo(goog.bind(dispatcher.dispatch, dispatcher));<p>imho, there&#x27;s a problem if you need to dust off your gang of four book to understand the API. Might as well include an AbstractSingletonProxyFactoryBean.
评论 #7787373 未加载
rabinoabout 11 years ago
I like they are putting this on Github instead of (or on top of) Google Code
评论 #7788135 未加载
评论 #7788136 未加载
riskableabout 11 years ago
This seems pretty complicated and not so simple. Someone else asked, &quot;How is this better than Backbone?&quot; Backbone is (a lot) more than just an event lib. A better question would be, &quot;How is this better than OnOff?&quot; (which is basically the equivalent of the events part of Backbone):<p><a href="https://github.com/LiftoffSoftware/OnOff" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;LiftoffSoftware&#x2F;OnOff</a>
评论 #7788123 未加载
distracteddev90about 11 years ago
Is it just me or is this overly complex for what amounts to declaring an EventEmitter, requiring it where needed, and proxying dom events to that EventEmitter?
scotty79about 11 years ago
Yes. Let&#x27;s reinvent onclick attribute. What&#x27;s with the recent trend of putting logic and visual configuration back into xmllish html clutter where you can&#x27;t see it among the &lt;&#x2F;&gt;=&quot; and meaningless words like div, span, class? Did people forget how much of a good idea was binding stuff to html from far away, from js and css files?<p>Did new programmers evolved some new protein that prevents their eyes from bleeding when they try to find bits of actual meaning in xml files?
评论 #7787098 未加载
评论 #7786921 未加载
wldlyinaccurateabout 11 years ago
Is it just me, or does this not seem &quot;tiny&quot; at all? It seems to require a bunch of Closure modules, and on top of that the source itself is hundreds of lines (albeit with comments).<p>Nitpicking aside, it looks like an interesting approach to decoupling the DOM from your event handlers. Personally I&#x27;m happy sticking with the standard on{event} attributes for really simple stuff.
评论 #7787447 未加载
评论 #7786813 未加载
Raynosabout 11 years ago
This seems similar to a module I wrote called [html-delegator][1].<p>The separation of thing that emits named event and listener is a good idea.<p>I Actually moved away from the HTML attribute DSL and started putting named events in my virtual dom instead (using [mercury][2])<p>The important part of this approach that is not shown in js action is to ensure you emit data structures instead of dom event objects to the listeners.<p><pre><code> [1]: https:&#x2F;&#x2F;github.com&#x2F;Raynos&#x2F;html-delegator&#x2F;blob&#x2F;master&#x2F;README.md [2]: https:&#x2F;&#x2F;github.com&#x2F;Raynos&#x2F;mercury</code></pre>
jgmmoabout 11 years ago
How does this compare with RX.js where they use the Observable setup to work with collections of events? Like that Netflix talk that was up here last week?
underwaterabout 11 years ago
This looks very similar to the concept of &quot;sigils&quot; in Javelin: <a href="https://secure.phabricator.com/book/javelin/article/sigils_metadata/" rel="nofollow">https:&#x2F;&#x2F;secure.phabricator.com&#x2F;book&#x2F;javelin&#x2F;article&#x2F;sigils_m...</a>
mmastracabout 11 years ago
Interesting. This might have come from the Google+ development team, as this and something called &quot;jsmodel&quot; are part of that product. You can see traces of both of these in the DOM of plus.google.com
评论 #7786781 未加载
dudusabout 11 years ago
Seems like this has to be &quot;compiled&quot; with clojure compiler. I&#x27;m not very familiar with this. Can someone provide some rough instructions to actually get the &quot;compiled&quot; library?
评论 #7787516 未加载
评论 #7787981 未加载
mkazizabout 11 years ago
Why is this better than something like backbone, for instance?
评论 #7786940 未加载
评论 #7786934 未加载