Skip to content

Commit

Permalink
Merge pull request #318 from Renumics/refactor/support-typed-lenses
Browse files Browse the repository at this point in the history
refactor: allow lenses with typed values in lens registry
  • Loading branch information
neindochoh authored Oct 27, 2023
2 parents d483207 + fcc7c83 commit 1e67680
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/lenses/SafeHtmlLens.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { Lens } from '../types';
import DOMPurify from 'dompurify';
import Html from '../components/ui/Html';

const SafeHtmlLens: Lens = ({ value }) => {
const safe_html = DOMPurify.sanitize(value as string);
const SafeHtmlLens: Lens<string> = ({ value }) => {
const safe_html = DOMPurify.sanitize(value);

return <Html html={safe_html} />;
};
Expand Down
6 changes: 2 additions & 4 deletions src/lenses/TextLens.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import 'twin.macro';
import { Lens } from '../types';

const TextLens: Lens = ({ value }) => {
const text = value as string;

const TextLens: Lens<string> = ({ value }) => {
return (
<div tw="w-full h-full overflow-y-auto p-1 text-xs whitespace-pre-wrap">
{text}
{value}
</div>
);
};
Expand Down
7 changes: 4 additions & 3 deletions src/stores/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { DataType } from '../datatypes';
import { ALL_LENSES } from '../lenses';
import { ALL_WIDGETS } from '../widgets';

export function isLensCompatible(
view: Lens,
export function isLensCompatible<T>(
view: Lens<T>,
types: DataType[],
canEdit: boolean
): boolean {
Expand Down Expand Up @@ -65,7 +65,8 @@ export function registerWidget(widget: Widget) {
}
ALL_WIDGETS.forEach(registerWidget);

export function registerLens(lens: Lens) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function registerLens(lens: Lens<any>) {
useComponentsStore.setState((state) => {
const lensesByKey = { ...state.lensesByKey, [lens.key]: lens };
return {
Expand Down

0 comments on commit 1e67680

Please sign in to comment.