TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Knockout v3.0.0 released

158 点作者 johnny_reilly超过 11 年前

21 条评论

jcutrell超过 11 年前
Knockout certainly doesn&#x27;t get as much attention as it should. For those of you reading this comment feed to find out if you should try Knockout, I&#x27;d recommend trying it. It is fairly simple to pick up in a weekend, especially with their interactive tutorials: <a href="http://learn.knockoutjs.com/" rel="nofollow">http:&#x2F;&#x2F;learn.knockoutjs.com&#x2F;</a><p>Looks like this version makes what I believe to be Knockout&#x27;s biggest strength (the data binding) that much stronger.
评论 #6611554 未加载
krosaen超过 11 年前
One thing I love about knockout is how focused it is at doing one thing really well without forcing a full blown single page application. It makes it easier to sprinkle in the data-bound rich interactive UI to the pieces of your page that need it and leave the rest as normal server side rendered content.<p>One key area of performance where js rendered UI helps a lot is in customizing an otherwise uniformly served (and cached) page. 95% of the page is uniform to everybody, so render that server side and cache the heck out of it (varnish or whatever). Then, bind the pieces of the UI after page load and customize them based on the user - their login status, their location, etc. We use this approach at food52.com and food52.com&#x2F;provisions.
评论 #6612087 未加载
api超过 11 年前
A great and unfairly ignored framework. I love it for its simplicity and speed. Do everything with HTML and CSS and use Knockout to bind that to your data, and then just use this for AJAX and other utilities:<p><a href="http://minifiedjs.com" rel="nofollow">http:&#x2F;&#x2F;minifiedjs.com</a><p>Now you have a full stack in like 50k.
评论 #6611786 未加载
notdonspaulding超过 11 年前
Maybe I&#x27;m just starting to get old, but the &quot;we take backwards compatibility very seriously&quot; line has become a lot more attractive to me in recent years.
scrabble超过 11 年前
I love Knockout. This is awesome news.<p>The thing I really like about Knockout is that I don&#x27;t find the complexity to ramp up as much as it does in Angular. It&#x27;s also super easy to just insert it into any page and use just the functionality I need. It&#x27;s also got great performance when it comes to 2 way binding.
评论 #6611718 未加载
评论 #6611571 未加载
themightykevdog超过 11 年前
In addition to the love being given here, I&#x27;d like to throw in that if you are updating an existing web app, nothing beats KO. You can add it incrementally to a page without turning your whole app upside down.
评论 #6612505 未加载
benmorris超过 11 年前
I&#x27;m a big fan of knockout. Learned it about a year ago and it has saved me from writing a lot of code. I can&#x27;t see going back to the old way at this point. It doesn&#x27;t try to be everything, but what it does, it does well. For SPA I use Durandal, knockout runs the declarative binding so you can get up and going with a full blown SPA pretty quickly.
评论 #6612148 未加载
EdgarVerona超过 11 年前
Having worked with Knockout on a fairly large project, I personally liked it as a normally server-side developer - however, it got mixed reviews from our purely frontend developers.<p>For me, there are several things I like about Knockout as someone who&#x27;s not a primarily frontend developer:<p>1) Obviousness of purpose. The thing I hate the most about frontend development is the lack of visibility into what is actually bound to an object. When I run into UI code that&#x27;s not using some kind of framework like Knockout, inevitably the UI interactions are typically performed with jQuery bindings, and often they aren&#x27;t terribly straightforward to find for anyone who didn&#x27;t initially develop it (&quot;what, you bound a mouseover action to everything that fits &#x27;.mouseoverable &gt; li &gt; ul &gt; li &gt; .mousey&#x27;?&quot;)<p>2) Clearly defined interaction models. I like creating and populating the ViewModel, and thus having a very clear place in the Javascript where I know the business logic and data for the frontend are going to live. When I create the ViewModel as its own Javascript object, I can define the full contract of what data the application needs and what operations can be done against it in a manner that I can quickly locate and fix up later.<p>3) Syncing of frontend state with data state. (of course, this is an obvious benefit, but...) I love that, once I&#x27;ve defined these obvious bindings, I can then focus more on my model and less on what is bound to that model. It gives me the ability to separate out my concerns, at least more than a scattering of one-off jQuery bindings would.<p>Knockout provides an obviousness of binding not only because all interactions between the UI, the user, and the model are supposed to happen through these bindings, but because the bindings are supposed to live on the element being interacted with&#x2F;displayed itself. This made a huge difference for me, as someone who likes to see an obvious relationship between the view and the underlying logic that&#x27;s modifying or creating that view. The concept of observable properties also felt natural to me, and I didn&#x27;t mind taking the time to make rich ViewModel objects that had methods attached to them representing actions, and &quot;ko.computed&quot;s when I had more complex scenarios in which I wanted to watch for (or perform) an update.<p>However, our frontend guys hated it, and I can understand why they feel that way (though I disagree with them on many of these points, and would like to win them over). For them:<p>1) &quot;We&#x27;re moving backwards.&quot; It&#x27;s a dramatically different approach that feels counterintuitive - in fact, for frontend developers who&#x27;ve been told their entire career to never put event handlers on the attributes of an element itself, it feels like a step backward evolutionarily. It feels, to them, like you might as well be going back to &quot;onclick=&#x27;&#x27;&quot; bindings.<p>2) &quot;More upfront work.&quot; It&#x27;s a more upfront work to create and maintain solid and coherent ViewModel objects, particularly when Knockout provides the tempting - but often fragile - alternative of calling &quot;ko.mapping.fromJSON&quot; or &quot;ko.mapping.fromJS&quot; that will essentially make a dumb ViewModel for you, but will also make everything observable and won&#x27;t give you any of the benefits of creating your own ViewModel with reasonable business logic, computeds, etc... This not only ends up making the bindings feel messy as they start performing complex logic directly in the binding where a computed or method would do, but it reinforces that bad &quot;onclick=&quot; binding feeling that they hate.<p>3) &quot;We have to surrender control of the DOM.&quot; The real killer for them is that, once the DOM is being managed by Knockout, you essentially have to give your control of the DOM over to Knockout. If you start fiddling with DOM elements with your own custom jQuery handlers instead of through custom (or built in) bindings, Knockout is going to inevitably run over your changes in unexpected ways as it itself modifies the DOM. Asking the frontend developers to make custom bindings is, unfortunately, asking for more work (and less intuitive work) than just making a jQuery binding, and thus it presents itself as a lot of additional code.<p>4) &quot;The path for mixing &#x27;common&#x27; ViewModels with &#x27;page specific&#x27; ViewModels is not clear.&quot; This is one I still struggle with in trying to help find a clear path for them. Let&#x27;s say that a page loads with a bunch of sections that are common to every page, and there are also page specific data and operations that need to be loaded. Knockout only lets you bind one ViewModel object to a given set of DOM elements at a time, which makes this difficult. My gut is that, if we were to create these ViewModel objects in such a way that a common &quot;binding&quot; Javascript block of code - run after all ViewModel objects for the page were both created and combined into a single over-arching object - existed, then they could all live together. This solution is fragile, however - that means every binding would need to be bound to some object off of that single ViewModel object, which could be prone to breakage as these models change. Essentially, bindings (or DOM elements with appropriate &quot;with:&quot; bindings to scope out what part of that larger ViewModel you cared about) would have to be created with this larger overall ViewModel in mind. The proposals don&#x27;t sound great when I talk to people about them, and I can understand their hesitation. (if any of you have good alternatives, I&#x27;d love to hear them)<p>5) &quot;We dislike having &#x27;logic bindings&#x27; or &#x27;placeholder bindings&#x27;.&quot; Frequently, the data for the ViewModel isn&#x27;t actually loaded yet by the time you need to bind. The way of preventing the bindings that require that data from breaking is to have boundary bindings wrapping them, such as checking if the object is loaded or the data you want isn&#x27;t null... but now you&#x27;ve got essentially boundary checks sitting in the DOM. They dislike those - understandably - and they dislike &quot;with&quot; bindings as well. It all feels like fluff that they shouldn&#x27;t have to worry about, and that crowds up the view. This is another one for which I don&#x27;t have a good response or alternative.<p>Anyways, Knockout definitely has both good and bad elements to it. I encourage everyone to give it a try. You may love it - as I do - despite its flaws, or you may hate it! But give it a shot, it may be a handy tool for you.
评论 #6612949 未加载
评论 #6611919 未加载
评论 #6611960 未加载
评论 #6622145 未加载
评论 #6611835 未加载
ww520超过 11 年前
I like Knockout, and have used it in several production systems. It has been a tremendous help in getting rich interactive UI on web apps.<p>Having said that, the mistake I made early was to use ko.mapping.fromJSON and fromJS to blindly generate the view model, which turns every field into an observable. It was very easy to get going and get it working fast, but I ran into performance problem later on with hundreds or thousands records. The advice to take the time to build your own view model and decide which field needs to be observable and which field can stay plain old Javascript object is very sensible.
Bahamut超过 11 年前
As someone who uses AngularJS pretty hardcore, can anyone give me a good high level summary about Knockout or point me in the right direction?
评论 #6612603 未加载
评论 #6611774 未加载
Nekorosu超过 11 年前
I&#x27;ve used this framework to build an html5 video player. I really liked how easy it was to move from jQuery based prototype to fully &quot;knocked out&quot; version.<p>The other thing I adore is a lack of magic. This means more code but this also means I can understand what&#x27;s going on after a long break from the project.
shaydoc超过 11 年前
Its simple, elegant and extendable. Been using it for 2 years, and see no reason to change. This is my SPA setup<p><a href="http://anexiledderryman.com/post/50565922110/javascript-single-page-application-architectural" rel="nofollow">http:&#x2F;&#x2F;anexiledderryman.com&#x2F;post&#x2F;50565922110&#x2F;javascript-sing...</a>
评论 #6612672 未加载
wldlyinaccurate超过 11 年前
I couldn&#x27;t find a full changelog, but GitHub&#x27;s compare system makes generating a changelog fairly trivial: <a href="https://github.com/knockout/knockout/compare/v2.3.0...v3.0.0" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;knockout&#x2F;knockout&#x2F;compare&#x2F;v2.3.0...v3.0.0</a>
评论 #6611362 未加载
dugmartin超过 11 年前
I did a fairly large Knockout app a couple of years ago and while the MVVM pattern worked pretty well after a while the interactions between all the bindings on the page crossed my cognitive threshold (and also ran slowly on mobile browsers).<p>I haven&#x27;t done a single page app again until a few weeks ago when I started playing with a side project. After looking at the options now available I settled on backbone + bacon.js (baconbone?). Once I got my head around functional reactive programming using the bacon.js eventstreams and properties vastly simplified my frontend code. At least for me changing the representation of the frontend from a static state to one of a stream of changes where the state is an intrinsic value of the event stream clicked. YMMV.
deckiedan超过 11 年前
I&#x27;ve been using knockout.js for a while on some flask (python) projects, most of the time I&#x27;ve been doing simple server-side logic for stuff, and HTML based views. Then for more complex UI interactions, using knockout. It works very well.<p>It doesn&#x27;t force any kinds of rigid conventions on the code, which is good if you&#x27;re adding it to a already existent project.<p>It is kind of fiddly having multiple layers of observables<p>ListOfPeople -&gt; ListOfDetails<p>where both sets of lists are updated in real time to the server in JSON, but overall I found it remarkable easy to get into.
aymeric超过 11 年前
After struggling with finding a good way to structure my knockout.js SPA <a href="http://weekplan.net" rel="nofollow">http:&#x2F;&#x2F;weekplan.net</a>, I finally found something I am happy with, inspired by the angular.js framework.<p>Beware, if you are thinking of using Knockout.js for a mobile friendly app, the binding &#x2F; events can easily slow down your app.
评论 #6611792 未加载
rekoros超过 11 年前
We (kato.im) found Knockout to be a remarkable framework.<p>We evaluated a number of options and found Knockout to deliver the fewest number surprises.<p>Knockout&#x27;s primitives make it possible to design elegant solutions to problems that frequently seem to result in unmaintainable code.<p>Kudos to the Knockout team!
skilesare超过 11 年前
I use knockout + backbone router to build most of my apps. It is a great framework without a ton of the infrastructure overhead of angular. I wouldn&#x27;t use it to build a component library I was trying to sell, but for my clients it works really well.
jlu超过 11 年前
Might worth having a look at backbone.rocks too, does a lot on top of backbone for what knockouts has to offer.<p><a href="https://github.com/devmatters/backbone.rocks" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;devmatters&#x2F;backbone.rocks</a>
aforty超过 11 年前
Great framework but are those all the changes in 3.0.0?
评论 #6611129 未加载
petrohi超过 11 年前
Great framework! Imho best at having powerful yet non-leaky and clear abstractions. We use it to build kato.im web app.