Open sebas5384 opened 9 years ago
Suggested architecture:
file: [path-to-your-extension]/my-extension/my-extension.js
/**
* Hook reactComponent();
*/
hooking.reactComponents = function (components, callback) {
var newComponents = {};
newComponents['RowLayout'] = {
defaultProps: {
row: {
name: "Best row, ever!"
}
}
};
// OR
newComponents['RowLayout'] = {
mixin: 'react/mixins/RowLayout',
component: 'react/components/RowLayout'
};
callback(null, newComponents);
};
file: [path-to-your-extension]/react/components/Layout.jsx
var React = require('react');
var lodash = require('lodash');
// Here's the magic.
var { LayoutMixin } = require('choko/default/extensions/react/mixins');
var { RowLayout } = require('choko/default/extensions/react/components');
// We want to override the Layout component.
var Layout = React.createClass({
// Here's the inheritance.
mixins: [LayoutMixin],
// Look ma!! I'm overriding.
render: function () {
return (
<div className="Layout">
{lodash.map(this.state.layout.rows, row =>
<RowLayout row={row} />
)}
</div>
);
}
});
module.exports = Layout;
I don't know for sure how we are gonna load the right components in the client side, but! we can come up with something.
@recidive and @jardix22 I would love to get your feedback about this before starting to develop this.
@sebas5384 while I haven't read through the changes and have no real experience with React.js I know this is good stuff.
This is how I see components being useful in Choko:
Maybe I'm missing the point, but in the long run I see admins clicking a contextual button for editing a template directly on the page and those would be a requirement.
React is in tha hood, WIP at the react branch.