Skip to content

Instantly share code, notes, and snippets.

@Craga89
Last active August 29, 2015 14:25
Show Gist options
  • Select an option

  • Save Craga89/add43ae8b5f245b29ec7 to your computer and use it in GitHub Desktop.

Select an option

Save Craga89/add43ae8b5f245b29ec7 to your computer and use it in GitHub Desktop.
Durandal + Webpack: Part 2 - Composition
// Locates the view, realizes it, binds it to the parent binding context and composes it into the DOM node on which the binding is declared.
data-bind="compose: 'myView.html'"
// Uses RequireJS to get the shell module, locates the view conventionally, binds it and injects it into the DOM node on which the binding is declared.
data-bind="compose: 'shell'"
// Evaluates the binding to obtain the result of someProperty. If it is a string, assume it's a view, otherwise assume it's a viewmodel, and follow the steps above
data-bind="compose: someProperty"
var jQuery = require('jquery');
var viewEngine = require('durandal/viewEngine');
var ViewModel = {
getView: function() {
var view = require('./view');
return viewEngine.processMarkup(view);
}
};
function cb(err?: Error, module: Object|Function)
system.acquire = function(moduleId: String) {}
<!-- Composes and binds the View HTML stored in the `myView` property into this view -->
<div data-bind="compose: myView"></div>
<!-- Composes the ViewModel stored in the `myViewModel` property into this view -->
<div data-bind="compose: myView"></div>
viewLocator.locateView = function(
viewOrUrlOrId: String|DOMElement,
area?: String,
elementsToSearch?: DOMElement[]
) {}
var jQuery = require('jquery');
var viewEngine = require('durandal/viewEngine');
var ViewModel = {
myView: require('./myView.html'),
myViewModel: require('./myViewModel'),
getView: function() {
var view = require('./view');
return viewEngine.processMarkup(view);
}
};
module.exports = ViewModel;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment