subview
v0.2.4
Published
A hierarchical view framework.
Downloads
5
Readme
Subview.js – Views done right!
Subview.js is a minimalistic hierarchical view framework designed to be highly modular, highly extensible and very efficient for applications containing thousands of views. The last point makes subview an excellent choice for complex user interfaces that are redrawn often such as word processors, messengers and other single-page web-apps. Subview is not and will never be a complete MVC framework but rather a View/Controller module designed to be used in conjunction with a Data Model.
Features:
- Extensible Views
- Hierarchically Scoped Events
- Elegant Templating with Your Favorite Engine (Handlebars, Underscore, EJS or Jade)
- Efficient View Management Through Object Pools
- Self-Contained and Compatible Any Other Framework
- 3.4KB gzipped & 8.9KB minified
Installation
npm install subview
Basic Usage
subview('main', {
/*** Life-Cycle Methods ***/
once: function() {
//Runs the first time a subview is created then never again.
},
init: function() {
//Stuff to be done when initializing a subview via the .spawn method
},
clean: function() {
//Runs when a subview is removed to clean and prepare it to be reused
},
/*** Templating ***/
template: Handlebars.compile(myTemplate),
subviews: { //Subviews that will be available in the template
name: SomeSubview
},
data: { //Data available in the template (may also be a function)
key: "value"
},
/*** Extensions ***/
myExtension: myExtension({
}),
/*** My API ***/
// ... Some API Functions
});
A simple example is available here.
Philosophy
Duties:
- Render the application
- Execute functions that define UI logic
- ~~Store application state~~ Moved to the State Extension.
- ~~Provide event bindings for application state change~~ Provide Event Bindings for inner-app communication.
- Manage View Object pools
Tenets:
- App interfaces should be organized into a hierarchical sub-view structure.
- This hierarchy should be defined only in the current state of the DOM. i.e. a subview is defined as a view that is a child of view's wrapper DOM element.
- These views should all inherit a set of basic methods and properties.
- Views should support event broadcasting.
- Event listeners should be directional. i.e. listen to children, parents, siblings or global.
- Views should be recycled automatically using an Object Pool.
- Templating should be supported in such a way that it can be done both server side & client side.
- Given a DOM element, you should be able to get it's corresponding view.
- No magical re-rendering of templates or DOM changes. This is essential for high-performance apps where the developer wants to control every single DOM render.
- Views should be able to be extended while preserving critical functionality of their parent class.
Development
To build: grunt build
To watch: grunt watch
To test: grunt test
Contributing
Contributions are always welcome! Please list bugs, issues and feature requests here.