3 ms·
A couple of questions: >Do not use Backbone models I use Backbone models for ajax since it makes decisions such as PUT vs POST and model.save() looks cleaner
by pramodliv1 11y ago
A couple of questions:
>Do not use Backbone models
I use Backbone models for ajax since it makes decisions such as PUT vs POST and model.save() looks cleaner than $.ajax. Also, Backbone collections provide a declarative way to handle sorting and duplicate models. But these models are internal to the Store and not exposed to the views. I'm still a React newbie. Is this a valid reason to continue using Backbone?
2. It seems as though Khan Academy do not use React for SVG elements in their interactive exercises. For example, https://www.khanacademy.org/math/geometry/transformations/hs-geo-reflections/e/defining-reflections https://www.khanacademy.org/math/geometry/transformations/hs... Do you plan to migrate SVG to React?
- gravity13 11y agoI would argue that's fair. Somebody might come along and suggest you GraphQL all the things, but the flux-flavors mostly tend to be focused more on the use of state in applications and less so across the wire. And Backbone's collection/model is pretty good at that. I can see argument against adding heft to your app, though - if that's something you're worried about. There's the ampersand library which tries to be more modular while reflecting the good parts of Backbone, but it seems to be going a bit quiet.
- seivan 11y agoHmm, that's not a bad idea actually. So you never expose your models at all to your components? Apart from dirty-check for POST/PUT and uniqueness/sorting what other benefits could Backbone models have? How do you expose your models to the view, I would guess you just serialise into regular objects?
- pramodliv1 11y ago>> So you never expose your models at all to your components? Yes, I don't expose models to the components. I'm trying this on a side project. We are still using plain Backbone in production. So, I don't have experience with large scale React apps. >> What other benefits could Backbone models have? It also features like validation and other stuff like nested models built by the community. >> How do you expose your models to the view, I would guess you just serialise into regular objects? Yes!
- dustingetz 11y agoIts a good and common question. Backbone can handle rectangular models okay. When you get into more complicated UI states, or if you have two different views backed by the same ui state like here [1], backbone models totally fall apart - backbone model is designed for list-of-records where the list can change or a record can change, it can't elegantly handle other shapes, like nested records, or list-of-lists, or tree-like (recursive comments), whatever arbitrary shape most naturally models the domain. Backbone models are also mutable which means lots of model change listeners (callback soup) - check out the flame charts here [2] to get an intuition for what callback soup does to your code and how react fixes it. [1] http://wingspan.github.io/wingspan-forms/examples/faceted-search/ http://wingspan.github.io/wingspan-forms/examples/faceted-se... (json blob is the ui state) [2] http://swannodette.github.io/2013/12/17/the-future-of-javascript-mvcs/ http://swannodette.github.io/2013/12/17/the-future-of-javasc...
- ariabuckles 11y ago1. If you're not passing the backbone models to React components, this sounds fine. backbone models as props ends up being really painful because of how mutable they are, and when we tried to manage that with mixins, it was buggy and caused problems (note: I'm not familiar with the actual mixin we used there and whether there was a better way to do it). Since most flux implementations are pretty stateful/mutable themselves, using mutable backbone models there, so long as you copy data out to pass to react views, seems safe. Though I'm excited long-term about the immutable flux implementations (https://github.com/rackt/redux https://github.com/rackt/redux) 2. We had a library originally written by Ben Alpert (now core react team) that handles all of our interactive svgs [1]. Since KA has a lot of legacy code there, and there hasn't been an immediate benefit to porting it (which would take a pretty significant time investment, on the [very roughly] order of a couple dev-months), this is still mutable jQuery/raphael code. There have been a lot of talks of eventually porting this to react, but the immediate need for it hasn't been there yet. However, I did write a React wrapper around much of this code which is used by newer interactive widgets [2]. [1]: https://github.com/Khan/khan-exercises/blob/master/utils/graphie.js https://github.com/Khan/khan-exercises/blob/master/utils/gra... [2]: https://github.com/Khan/perseus/blob/master/src/components/graphie.jsx https://github.com/Khan/perseus/blob/master/src/components/g...
- pramodliv1 11y agoThanks! I did not about Redux and the React wrapper.