mirror of
https://github.com/jupyterhub/jupyterhub.git
synced 2025-10-19 07:53:00 +00:00
vendor tiny subset of unmaintained recompose
the functions we use haven't changed in almost 10 years, and are only a few lines we should probably lose them eventually, but easier to vendor them first
This commit is contained in:
35
jsx/src/util/_recompose.js
Normal file
35
jsx/src/util/_recompose.js
Normal file
@@ -0,0 +1,35 @@
|
||||
// extracted tiny subset we use from react-recompose
|
||||
// we probably don't need these at all,
|
||||
// but vendor before refactoring
|
||||
|
||||
// https://github.com/acdlite/recompose
|
||||
// License: MIT
|
||||
// Copyright (c) 2015-2018 Andrew Clark
|
||||
|
||||
import { createElement } from "react";
|
||||
|
||||
function createFactory(type) {
|
||||
return createElement.bind(null, type);
|
||||
}
|
||||
|
||||
export const compose = (...funcs) =>
|
||||
funcs.reduce(
|
||||
(a, b) =>
|
||||
(...args) =>
|
||||
a(b(...args)),
|
||||
(arg) => arg,
|
||||
);
|
||||
|
||||
const mapProps = (propsMapper) => (BaseComponent) => {
|
||||
const factory = createFactory(BaseComponent);
|
||||
const MapProps = (props) => factory(propsMapper(props));
|
||||
return MapProps;
|
||||
};
|
||||
|
||||
export const withProps = (input) => {
|
||||
const hoc = mapProps((props) => ({
|
||||
...props,
|
||||
...(typeof input === "function" ? input(props) : input),
|
||||
}));
|
||||
return hoc;
|
||||
};
|
Reference in New Issue
Block a user