akrymski/espresso.js

Large scale app questions

Closed this issue · 1 comments

I am interested in starting a similar project based on components of backbone and react but it looks like this project might be heard in a similar direction but I have a few questions.

  1. There doesn't seem to be a router, did I just miss it? If not what are the plans for one?
  2. There isn't an example of using templates, is it possible? For later applications there is no way all the HTML can be in a single file.
  3. Why not just use react as the rendering engine? they have already addressed many issues of updating the Dom efficiently.
  1. Not all apps require a router. If you need one, there are lots of libs out there, eg: https://github.com/flatiron/director
  2. A view is a DOM node. You don't need templates! You can bind to existing nodes or you can clone an existing node like so: new Controller({ view: 'view-name' }) where view-name is the element ID of the DOM node that is to be reused. I typically have all re-usable views inside a hidden div. You can load HTML from the server at runtime if you really want to, but it's not nearly as efficient as having all the necessary HTML already in the DOM and ready to go (parsed by the browser, efficiently gzipped, etc). For large apps I suggest a build script that concats HTML files and injects them into your index.html
  3. React isn't efficient because it requires diffing the WHOLE dom. Moreover, it requires you to have the whole HTML representation of components in your JavaScript controllers, which this framework specifically tries to avoid. By having HTML separate from code, a designer can easily tweak HTML as you write code. For example, the to-do app index.html renders perfectly fine without including any javascript. That's one of the core features - it lets you go from design to interactive app really quickly. The designer doesn't need to know anything about code, model or templating language syntax - they simply label nodes that require interactivity with [data-ref] in the same way they add class attributes.