Skip to content

Instantly share code, notes, and snippets.

@bsandhu
Last active November 13, 2016 22:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bsandhu/62fd74612a0a4444eeffe8e6e5b91bfa to your computer and use it in GitHub Desktop.
Save bsandhu/62fd74612a0a4444eeffe8e6e5b91bfa to your computer and use it in GitHub Desktop.
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