examples/HTML StarterKit/lib/durandal/js/composition.js
function(name, config, initOptionsFactory){
            var key,
                dataKey = 'composition-handler-' + name,
                handler;

            config = config || ko.bindingHandlers[name];
            initOptionsFactory = initOptionsFactory || function(){ return undefined;  };

            handler = ko.bindingHandlers[name] = {
                init: function(element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {
                    if(compositionCount > 0){
                        var data = {
                            trigger:ko.observable(null)
                        };

                        composition.current.complete(function(){
                            if(config.init){
                                config.init(element, valueAccessor, allBindingsAccessor, viewModel, bindingContext);
                            }

                            if(config.update){
                                ko.utils.domData.set(element, dataKey, config);
                                data.trigger('trigger');
                            }
                        });

                        ko.utils.domData.set(element, dataKey, data);
                    }else{
                        ko.utils.domData.set(element, dataKey, config);

                        if(config.init){
                            config.init(element, valueAccessor, allBindingsAccessor, viewModel, bindingContext);
                        }
                    }

                    return initOptionsFactory(element, valueAccessor, allBindingsAccessor, viewModel, bindingContext);
                },
                update: function (element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {
                    var data = ko.utils.domData.get(element, dataKey);

                    if(data.update){
                        return data.update(element, valueAccessor, allBindingsAccessor, viewModel, bindingContext);
                    }

                    if(data.trigger){
                        data.trigger();
                    }
                }
            };

            for (key in config) {
                if (key !== "init" && key !== "update") {
                    handler[key] = config[key];
                }
            }
        }
function(name, config, initOptionsFactory){
            var key,
                dataKey = 'composition-handler-' + name,
                handler;

            config = config || ko.bindingHandlers[name];
            initOptionsFactory = initOptionsFactory || function(){ return undefined;  };

            handler = ko.bindingHandlers[name] = {
                init: function(element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {
                    if(compositionCount > 0){
                        var data = {
                            trigger:ko.observable(null)
                        };

                        composition.current.complete(function(){
                            if(config.init){
                                config.init(element, valueAccessor, allBindingsAccessor, viewModel, bindingContext);
                            }

                            if(config.update){
                                ko.utils.domData.set(element, dataKey, config);
                                data.trigger('trigger');
                            }
                        });

                        ko.utils.domData.set(element, dataKey, data);
                    }else{
                        ko.utils.domData.set(element, dataKey, config);

                        if(config.init){
                            config.init(element, valueAccessor, allBindingsAccessor, viewModel, bindingContext);
                        }
                    }

                    return initOptionsFactory(element, valueAccessor, allBindingsAccessor, viewModel, bindingContext);
                },
                update: function (element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {
                    var data = ko.utils.domData.get(element, dataKey);

                    if(data.update){
                        return data.update(element, valueAccessor, allBindingsAccessor, viewModel, bindingContext);
                    }

                    if(data.trigger){
                        data.trigger();
                    }
                }
            };

            for (key in config) {
                if (key !== "init" && key !== "update") {
                    handler[key] = config[key];
                }
            }
        }
function ( name , config , initOptionsFactory ) { var key , dataKey = 'composition-handler-' + name , handler ; config = config || ko . bindingHandlers [ name ] ; initOptionsFactory = initOptionsFactory || function ( ) { return undefined ; } ; handler = ko . bindingHandlers [ name ] = { init : function ( element , valueAccessor , allBindingsAccessor , viewModel , bindingContext ) { if ( compositionCount > 0 ) { var data = { trigger : ko . observable ( null ) } ; composition . current . complete ( function ( ) { if ( config . init ) { config . init ( element , valueAccessor , allBindingsAccessor , viewModel , bindingContext ) ; } if ( config . update ) { ko . utils . domData . set ( element , dataKey , config ) ; data . trigger ( 'trigger' ) ; } } ) ; ko . utils . domData . set ( element , dataKey , data ) ; } else { ko . utils . domData . set ( element , dataKey , config ) ; if ( config . init ) { config . init ( element , valueAccessor , allBindingsAccessor , viewModel , bindingContext ) ; } } return initOptionsFactory ( element , valueAccessor , allBindingsAccessor , viewModel , bindingContext ) ; } , update : function ( element , valueAccessor , allBindingsAccessor , viewModel , bindingContext ) { var data = ko . utils . domData . get ( element , dataKey ) ; if ( data . update ) { return data . update ( element , valueAccessor , allBindingsAccessor , viewModel , bindingContext ) ; } if ( data . trigger ) { data . trigger ( ) ; } } } ; for ( key in config ) { if ( key !== "init" && key !== "update" ) { handler [ key ] = config [ key ] ; } } }
Registers a binding handler that will be invoked when the current composition transaction is complete.
@method addBindingHandler
@param {string} name The name of the binding handler.
@param {object} [config] The binding handler instance. If none is provided, the name will be used to look up an existing handler which will then be converted to a composition handler.
@param {function} [initOptionsFactory] If the registered binding needs to return options from its init call back to knockout, this function will server as a factory for those options. It will receive the same parameters that the init function does.
Registers a binding handler that will be invoked when the current composition transaction is complete .