- Backbone.js Patterns and Best Practices
- Swarnendu De
- 381字
- 2021-07-19 18:28:21
Chapter 2. Working with Views
Backbone view works as the presentation layer of an application. In simple terms, you can define it as an abstract layer for your HTML element. It doesn't contain any HTML markup of its own, but it contains the logic to present your model's data with the help of JavaScript templates.
If you go through the annotated source of Backbone view, you will find that Backbone.View
is a small class with very few methods, including an empty initialize()
method and an almost empty render()
method, which are in general meant to be overridden by any custom view class. In this chapter, we will investigate some common problems and the solutions to these problems with respect to the Backbone views that developers face mostly while developing real-world Backbone.js applications.
The basic issues with Backbone are associated with view rendering or updating and maintaining multiple views within an application. We will analyze the following topics based on complexity:
- Basic usage of views: We will learn the basic concepts of Backbone view, its properties, functions, and event-handling.
- Updating a view partially: We will learn how to update only a part of a view without the need for re-rendering the complete view.
- Nested views: As the complexity of an application layout increases, we feel the need to maintain a hierarchy of multiple views. Nested views or subviews simplify event-handling and layout management to a great extent. We will explore the following topics:
- When we need to use subviews
- How to initialize and render nested views
- How to avoid DOM reflow in the case of a large collection of nested views and a complex view DOM structure
- How to clean up resources (child views, events) when you delete a parent view
- Templates: Templates are an essential part of Backbone and are used in combination with views to create reusable copies of HTML markup. We will discuss the following topics:
- The different options for storing and loading template files
- The advantages of template precompilation and storing precompiled templates on the client side
- The usage of template helper functions
- Marionette views: We can reduce the view boilerplate code using the custom view extensions of the Marionette library.
- Layout manager: We can simplify the complex layout architecture using the Backbone layout manager plugin.
- GAE編程指南
- 零基礎學Visual C++第3版
- Android應用程序開發與典型案例
- Mastering RabbitMQ
- 軟件界面交互設計基礎
- Python網絡爬蟲從入門到實踐(第2版)
- Full-Stack Vue.js 2 and Laravel 5
- Android Native Development Kit Cookbook
- Python Web數據分析可視化:基于Django框架的開發實戰
- 全棧自動化測試實戰:基于TestNG、HttpClient、Selenium和Appium
- 深入分布式緩存:從原理到實踐
- 開源項目成功之道
- Hacking Android
- 嵌入式Linux C語言程序設計基礎教程
- Get Your Hands Dirty on Clean Architecture