Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Register Knockout React components together
define(['log',
'knockout',
'modules/loans/ironBank/components/myReactComponent',
'modules/loans/commons/utils/knockoutReactBinding'],
function (log,
ko,
_myReactComponent) {
'use strict';
function ComponentsRegistry() {
log.info('Init component registry');
this.init();
}
ComponentsRegistry.prototype.init = function () {
// This component can now be added to the DOM - assuming an existing KO app - like so:
// <my-component></my-component>
ko.components.register('my-component', wrapReactComponentInKO(_myReactComponent.MyComponent));
};
/**
* @See KnockoutReactBinding.js
*/
function wrapReactComponentInKO(reactComponent) {
return {
// By default supply the React component to the template
viewModel: function () {
return {'reactComponent': reactComponent}
},
// By default the component just has the react binding
template: '<div data-bind="react: reactComponent"/>'
}
}
return new ComponentsRegistry();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment