
Product
Introducing Socket Firewall Enterprise: Flexible, Configurable Protection for Modern Package Ecosystems
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.


This project is still experimental, so feedback from component authors would be greatly appreciated!
recompose had a great influence. It is great library that provide excellent way to lift state into functional wrappers, perform the most common React patterns, optimize rendering performance. Also it is possible to store common functions separately and share them between components. And as the result - component's source code become much more easier.
recompose - React utility belt for function components and higher-order components. Think of it like lodash for React.
Provide easier way to develop and manage component's features and inject them into the components.
Detailed information at feature api documentation
Feature = function(props): newProps
Feature.propTypes = {}
Feature.defaultProps = {}
Detailed information at feature api documentation. This useful when need to work with lifecycle methods.
Feature = {
props: function(props): newProps,
hoc: function(Component: React.Component): function(props): React.Component
}
Feature.propTypes = {}
Feature.defaultProps = {}
Detailed information at forgekit api documentation
In general it looks like props middleware. But each feature also can implement a higher order component (usually for lifecycle methods).
import forgekit from 'forgekit';
forge(...features)(Component, displayName, bindProps)
ForgedButton propTypes and defaultProps are merged from all features and origin component. Additional explanation at forgekit-comopnents#little-explanation
ForgedButton.propTypes = {
...Button.propTypes,
...Feature1.propTypes,
...Feature2.propTypes
}
ForgedButton.defaultProps = {
...Button.defaultProps,
...Feature1.defaultProps,
...Feature2.defaultProps
}
So if you use React Sotrybook with storybook-addon-ifno - it will show components props and default props correctly.
For example there is a <Button/> component with custom (high-level) props:
More details about custom (high-level) and native (low-level) props at feature documentation
Let's find relations between custom (high-level) and native (low-level) props
const alertFeature = ({
alert,
style,
...props
}) => {
const alertStyles = alert ? {
color: 'red'
} : {};
return {
...props,
style: {
...(style || {}),
...alertStyles
}
}
};
alertFeature.propTypes = {
alert: PropTypes.bool
}
<Icon/> to the children.const iconFeature = ({
icon,
iconPosition,
children,
...props
}) => {
return {
...props,
children: [
iconPosition == 'left' ? renderIcon(icon) : null,
children,
iconPosition == 'right' ? renderIcon(icon) : null,
]
}
}
iconFeature.propTypes = {
icon: PropTypes.string,
iconPosition: PropTypes.oneOf(['left', 'right']),
}
For example it is not possible to implement clickOutside feature if there is not access to lifecycle methods. To implement this feature:
This is possible with forgekit. Just define Feature as object:
class ClickOutside extends React.Component {
componentDidMount() {}
componentWillUnmount() {}
render() {
return this.props.children;
}
}
const Feature = {
hoc: Component => {
return ({
onClickOutside,
...props
}) =>
return (
<ClickOutside onClickOutside={onClickOutside}>
<Component {...props} />
</ClickOutside>
);
}
}
}
There are features that does not relate to certain component. They could be added into any component.
import forgekit from 'forgekit';
import Button from 'components/button';
import Layout from 'components/layout';
import clickOutside from 'features/click-outside';
import highliteFlags from 'features/highlite-flags';
import loaderOverlay from 'features/loader-overlay';
export const AppButton = forgekit(clickOutside, highliteFlags)(Button);
export const AppLayout = forgekit(clickOutside, loaderOverlay)(Layout);
There is one common feature - clickOutside.
Forged components <AppButton/> and <AppLayout/> accepts onClickOutside prop. But onClickOutsided is not duplicated at <Button/> and <Layout/> propTypes. It is automatically added with clickOutside feature.
Look at any open source components library - each component has a lot of features and there are a lot of propTypes. For example component <Button/> has features:
A lot of more. And it is not possible to use only icon feature. All features implementations will be included to application build.
Forgekit allows to import only used features.
import forgekit from 'forgekit';
import Button from 'components/button';
import icon from 'button/features/icon';
import ripple from 'button/features/ripple';
export default forgekit(icon, ripple)(Button);
All needed features could be imported from separated modules. This is very helpful when you want to share your component features with another team, another application or just push them to Github and make them open source. Also this provide good way to keep your code cleaner: just create new module and develop new functionality instead of patching existing modules. And same with refactoring - just remove imports if need to clean some old or unused features. This is much easier than remove large number of lines from components code and then make sure that all other features work correctly.
Each feature could be customized. Very similar with Redux middleware customization.
import fogekit from 'forgekit';
import icon from 'features/icon';
import highliteFlags from 'features/highlite-flags';
const Button = (children, ...props) => <button {...props}>{children}</button>;
const customHighliting = highliteFlags({
alert: {
color: 'white',
fontWeight: 'bold'
background: 'red'
}
});
export default forge(icon, customHighliting)(Button);
If there is any open source component's library that was built with Forgekit - it is simple to contribute because developers does not need to understand its whole structure and work with all library. Just develop feature function with tests and push it. Or even push to own repository.
Example: change <Dropdown/> configuration to declarative style instead of passing all via props.
It is very easy to add or remove this feature. Do not need to change components code.
npm install --save forgekit
I will contribute to Forgekit components library:
Create Forgekit react storybook plugin. Main goal - manage features and themes
Forgekit is still in the early stages and even still be an experimental project. Your are welcome to submit issue or PR if you have suggestions! Or write me on twitter @tuchk4.
:tada:
FAQs

We found that forgekit demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.

Security News
Open source dashboard CNAPulse tracks CVE Numbering Authorities’ publishing activity, highlighting trends and transparency across the CVE ecosystem.

Product
Detect malware, unsafe data flows, and license issues in GitHub Actions with Socket’s new workflow scanning support.