The example is a bit contrived, but hopefully you see the problem? Especially consider if there are a couple more layers between App and whatever leaf component is rendering something,
266 karma · joined September 12, 2011
https://ianobermiller.com
The example is a bit contrived, but hopefully you see the problem? Especially consider if there are a couple more layers between App and whatever leaf component is rendering something,
As you say, the models live in stores, so building on my other comment, you would have an ArticleStore that is responsible for providing access to and caching all of the Article objects. As a rule, if you want to mutate data, you do so by calling an action (ArticleActions.update, for example). See my other comment for how the update flow works: https://news.ycombinator.com/item?id=7721381
If you want to fetch data, you go to the store (ArticleStore.getByID, or ArticleStore.query). The ArticleStore will then call into the ArticleDAO (data access abstraction) to fetch data asynchronously, and when it returns the ArticleStore incorporates the data into its cache and "informs", which is basically a pub-sub push (the views/components subscribe to the stores they want to get data from).
1) User clicks a button to favorite an object, lets say an Article 2) View (component) listens for the click handler and calls ArticleActions.favorite(articleID) 3) ArticleActions.favorite fires a preliminary ARTICLE_UPDATE action, for any stores that want to update optimistically 4) ArticleActions.favorite calls into the ArticleDAO (the data access abstraction) via ArticleDAO.update, a function that takes an ID, some updates, and two callbacks, success and error. 5) In the success callback, ArticleActions.favorites fires off ARTICLE_UPDATE_COMPLETED, along with the updated article object 6) In the error callback, ArticleAction.favorites fires off ARTICLE_UPDATE_FAILED, along with the error 7) Stores listen for the COMPLETED and FAILED actions to know when to update their data, including stores that show error notices
As you can see,the action layer itself should not really be accepting callbacks/returning promises. It might be easier, however, if the DAO layer returned promises, and this is something we have talked about migrating to.
1. All data should be kept in stores. You may have some local component state, but it shouldn't be anything you want to persist if the component is unmounted. We have tried using state several times, and always go back to keeping it in singleton stores. It also works better with the action-dispatcher pattern.
2. Now all your data is in stores, but how do you get it into the specific component that needs it? We started with large top level components which pull all the data needed for their children, and pass it down through props. This leads to a lot of cruft and irrelevant code in the intermediate components. What we settled on, for the most part, is components declaring and fetching the data they need themselves, except for some small, more generic components. Since most of our data is fetched asynchronously and cached, we've created mixins that make it easy to declare which data your component needs, and hook the fetching and listening for updates into the lifecycle methods (componentWillMount, etc).
3. Actions don't have callbacks, as they are by design fire-and-forget. So if you need to be notified when some item has finished being created, for example, you need to listen for the follow up action that the CREATE action fires (yeah, actions firing actions, a bit ugly). Even then, how do you know that CREATE_COMPLETED action correlates to the CREATE that you fired, and not another? Well, actions also come with a payload, so what we ended up doing was passing a context object into the payload and plumbing it all the way down into the CREATE_COMPLETED and CREATE_FAILED actions. Being really strict about actions is a major reason why Flux has scaled well for us.
Edit: updated link, forgot to save
Edit: for more info, React takes care of reusing DOM elements, and also uses event delegation by default.
Edit: for comparision, here is a version without the optimization: http://jsfiddle.net/ianobermiller/QT9Tx/1/
Edit: sounds like this is what reddit does. Props to them!
"jQuery Core has more lines of fixes and patches for WebKit than any other browser." [1]
[1] http://blog.methvin.com/2013/02/tragedy-of-webkit-commons.ht...
http://blogs.msdn.com/b/ericlippert/archive/2007/06/06/fyi-c...
This is an old article, but I believe it still applies to the latest iteration of the language.
Couple bugs: 1) Chrome on Win8 consistently gives me the Network Error dialog when trying to upload 2) Was able to get it working fine on IE10, but sometimes the background still shows up in the preview, even though it is erased correctly in the download. http://i.imgur.com/fSB4n4r.jpg
Which photo management tools do you use? I currently have around 45k photos (~200GB) and Picasa is sometimes just too slow. I am planning to get a DSLR soon, so total size is going to be expanding rapidly. What kind of tools would you suggest? I am on Windows mainly, so Mac-only is not an option. Thanks!
That’s why today we are also announcing a commitment to match Amazon Web Services prices for commodity services such as compute, storage and bandwidth. This starts with reducing our GA prices on Virtual Machines and Cloud Services by 21-33%. Regardless of how you choose to buy Windows Azure, you’ll get the benefit of this price reduction. As our operations GM Steven Martin said, “If you had concerns that Windows Azure was more expensive, we’re putting those concerns to rest today.”
It would be great if there was a simple calculator on the pricing page, to give a really quick and rough estimate for how much we'd be paying, especially considering the volume discounts and prepay. E.g. 30 large Azure instances for one year. By my calculations that would work out to ~$2300/mo when prepaying for a year (ouch!).
Guess not :( Any ideas?