signal-desktop/ts/components/_util.ts

27 lines
683 B
TypeScript
Raw Normal View History

2019-11-19 15:03:00 -08:00
// A separate file so this doesn't get picked up by StyleGuidist over real components
2020-01-17 17:23:19 -05:00
import { Ref } from 'react';
import { isFunction } from 'lodash';
2020-03-23 17:09:12 -04:00
import memoizee from 'memoizee';
2020-01-17 17:23:19 -05:00
2019-11-19 15:03:00 -08:00
export function cleanId(id: string): string {
return id.replace(/[^\u0020-\u007e\u00a0-\u00ff]/g, '_');
}
2020-01-17 17:23:19 -05:00
2020-03-23 17:09:12 -04:00
export const createRefMerger = () =>
memoizee(
<T>(...refs: Array<Ref<T>>) => {
return (t: T) => {
refs.forEach(r => {
if (isFunction(r)) {
r(t);
} else if (r) {
// @ts-ignore: React's typings for ref objects is annoying
r.current = t;
}
});
};
},
{ length: false, max: 1 }
);