revert selector back to memo
This commit is contained in:
parent
39da4f696e
commit
a9de0c7817
1 changed files with 7 additions and 9 deletions
|
@ -1,4 +1,4 @@
|
|||
import { Accessor, children, createContext, createEffect, createMemo, createSelector, createSignal, For, ParentComponent, Setter, Show, useContext } from "solid-js";
|
||||
import { Accessor, children, createContext, createEffect, createMemo, createSignal, For, ParentComponent, Setter, Show, useContext } from "solid-js";
|
||||
import { Command, CommandType, noop, useCommands } from "~/features/command";
|
||||
import { AiOutlineClose } from "solid-icons/ai";
|
||||
import css from "./tabs.module.css";
|
||||
|
@ -6,7 +6,7 @@ import css from "./tabs.module.css";
|
|||
type CloseTabCommandType = CommandType<(id: string) => any>;
|
||||
interface TabsContextType {
|
||||
activate(id: string | undefined): void;
|
||||
isActive(id: string): boolean;
|
||||
isActive(id: string): Accessor<boolean>;
|
||||
readonly onClose: Accessor<CloseTabCommandType | undefined>
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,6 @@ const useTabs = () => {
|
|||
|
||||
export const Tabs: ParentComponent<{ class?: string, active?: string, setActive?: Setter<string | undefined>, onClose?: CloseTabCommandType }> = (props) => {
|
||||
const [active, setActive] = createSignal<string | undefined>(props.active);
|
||||
const isActive = createSelector<string | undefined, string>(active, (id, active) => id === active);
|
||||
|
||||
createEffect(() => {
|
||||
props.setActive?.(active());
|
||||
|
@ -35,11 +34,9 @@ export const Tabs: ParentComponent<{ class?: string, active?: string, setActive?
|
|||
setActive(id);
|
||||
},
|
||||
|
||||
isActive,
|
||||
|
||||
// isActive(id: string) {
|
||||
// return createMemo(() => active() === id);
|
||||
// },
|
||||
isActive(id: string) {
|
||||
return createMemo(() => active() === id);
|
||||
},
|
||||
|
||||
onClose: createMemo(() => props.onClose),
|
||||
};
|
||||
|
@ -94,6 +91,7 @@ const _Tabs: ParentComponent<{ class?: string, active: string | undefined, onClo
|
|||
export const Tab: ParentComponent<{ id: string, label: string, closable?: boolean }> = (props) => {
|
||||
const context = useTabs();
|
||||
const resolved = children(() => props.children);
|
||||
const isActive = context.isActive(props.id);
|
||||
|
||||
return <div
|
||||
id={props.id}
|
||||
|
@ -101,7 +99,7 @@ export const Tab: ParentComponent<{ id: string, label: string, closable?: boolea
|
|||
data-tab-label={props.label}
|
||||
data-tab-closable={props.closable}
|
||||
>
|
||||
<Show when={context.isActive(props.id)}>
|
||||
<Show when={isActive()}>
|
||||
<Command.Context for={context.onClose() ?? noop} with={[props.id]}>{resolved()}</Command.Context>
|
||||
</Show>
|
||||
</div>;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue