Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Durandal.js - composition vs widget

i want create one div ( basically it will containt listbox) , and i want to use the div in different pages,

which is the best option to use in duarandal.js?

Composition

http://durandaljs.com/documentation/Using-Composition/

Widget

http://durandaljs.com/documentation/Creating-A-Widget/

like image 210
patel Avatar asked Aug 19 '13 14:08

patel


1 Answers

In general, think of using the compose binding as templates, and widgets as user controls

There's not quite enough information in your question for me to offer a suggestion on which is the right choice for you, but I'll provide some comparison for the two below, which should make it easier for you to choose.


Durandal's compose binding can be used to render, or inject, one view as part of another. For example, a menu.html may be defined that can be used to display menu items. This is similar to the concept of a jQuery template, or a "partial view" in ASP.Net MVC. A composed view can either use the parent's view model as its data source, or it can have its own view model.

The compose binding is most useful when you have a view and/or view model that can be used as is in multiple places.

Durandal's widgets, on the other hand, use composition internally, but are designed to abstract the "parts" of the widget so that one widget can be configured differently on each view where it is rendered. A widget can have parts, and these parts can be exposed through the widget interface.

Durandal widgets are most useful when you want to create some functionality that can be used across multiple views, but the implementations may differ.

like image 148
Joseph Gabriel Avatar answered Oct 01 '22 18:10

Joseph Gabriel