Skip to content
This repository was archived by the owner on Aug 9, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/strange-experts-invite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@keyval/react': major
'@keyval/core': major
---

Updated to effector 23
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"dependencies": {
"@typescript-eslint/eslint-plugin": "^5.57.1",
"@typescript-eslint/parser": "^5.57.1",
"effector": "^22.3.0",
"effector-react": "^22.1.5",
"effector": "^23.2.0",
"effector-react": "^23.2.0",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"version": "0.1.0",
"type": "commonjs",
"peerDependencies": {
"effector": "^22.5.0"
"effector": "^23.2.0"
}
}
4 changes: 2 additions & 2 deletions packages/core/src/createSelection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
combine,
createStore,
createEvent,
Event,
EventCallable,
sample,
split,
} from 'effector';
Expand Down Expand Up @@ -31,7 +31,7 @@ export function createSwitch<

const port = createConsumerPort();
const $currentCase = createStore(initialCase);
const caseApi = {} as { [K in ShapeCase]: Event<void> };
const caseApi = {} as { [K in ShapeCase]: EventCallable<void> };
const selectionActivation = createEvent<ShapeCase>();

forIn(cases, (selection, field) => {
Expand Down
26 changes: 13 additions & 13 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
import type { Event, Store } from 'effector';
import type { EventCallable, Store } from 'effector';

export type PossibleKey = string | number;

export type ListApi<Item, Key extends PossibleKey> = {
setItemField<Path extends keyof Item>(
path: Path
): Event<{ key: Key; value: Item[Path] }>;
removeItemsByField(match: keyof Item): Event<void>;
setAll<Path extends keyof Item>(match: Path): Event<Item[Path]>;
): EventCallable<{ key: Key; value: Item[Path] }>;
removeItemsByField(match: keyof Item): EventCallable<void>;
setAll<Path extends keyof Item>(match: Path): EventCallable<Item[Path]>;
mapItem(
fn: (value: Item, payload: undefined) => Partial<Item>
): Event<{ key: Key }>;
): EventCallable<{ key: Key }>;
mapItem<T>(
fn: (value: Item, payload: T) => Partial<Item>
): Event<{ key: Key; value: T }>;
removeItem(): Event<{ key: Key }>;
): EventCallable<{ key: Key; value: T }>;
removeItem(): EventCallable<{ key: Key }>;
removeItem<ChildField extends keyof Item>(config: {
removeChilds: {
childField: ChildField;
selection?: Selection<Item, Key>;
};
}): Event<{ key: Key }>;
addItem<Params>(config: { fn: (params: Params) => Item }): Event<Params>;
}): EventCallable<{ key: Key }>;
addItem<Params>(config: { fn: (params: Params) => Item }): EventCallable<Params>;
addItemTree<Input, RawInput = Input>(config: {
normalize?: (input: RawInput) => Input;
convertInput: (item: Input, childOf: Key | null) => Item;
getChilds: (item: Input) => RawInput | RawInput[] | null | undefined;
}): Event<RawInput[] | RawInput>;
}): EventCallable<RawInput[] | RawInput>;
config: {
getItem: (store: Record<Key, Item>, key: Key | [Key]) => Item; // TOOD: | undefined
};
Expand All @@ -52,7 +52,7 @@ export type ListApi<Item, Key extends PossibleKey> = {
}>;
};

type Events<T extends { [key: string]: any }> = { [K in keyof T]: Event<T[K]> };
type Events<T extends { [key: string]: any }> = { [K in keyof T]: EventCallable<T[K]> };
type Stores<T extends { [key: string]: any }> = { [K in keyof T]: Store<T[K]> };
export type SelectionItem<S> = S extends Selection<infer Item, any>
? Item
Expand Down Expand Up @@ -83,7 +83,7 @@ export type ConsumerPort = {
export interface SwitchSelection<
Shape extends Record<string, Selection<any, any>>
> extends Selection<SelectionItem<Shape[keyof Shape]>, any> {
api: { [K in keyof Shape]: Event<void> };
api: { [K in keyof Shape]: EventCallable<void> };
cases: Shape;
state: Stores<{
items: Record<any, SelectionItem<Shape[keyof Shape]>>;
Expand All @@ -99,7 +99,7 @@ export type ItemApi<
> = {
kv: ListApi<Item, Key>;
api: {
[K in keyof ItemTriggers]: Event<{ key: Key; value: ItemTriggers[K] }>;
[K in keyof ItemTriggers]: EventCallable<{ key: Key; value: ItemTriggers[K] }>;
};
};

Expand Down
2 changes: 1 addition & 1 deletion packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"version": "0.1.0",
"type": "commonjs",
"peerDependencies": {
"effector": "^22.5.0"
"effector": "^23.2.0"
}
}
1 change: 1 addition & 0 deletions packages/react/src/impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export const useItem = <
) => {
const actualId =
id !== undefined ? id : useContext(ItemsContext).get(itemOrKv);
// @ts-expect-error TODO: Replace with real kv check
const state = useItemState(actualId, itemOrKv);
// @ts-expect-error TODO: Replace with real kv check
const api = itemOrKv.kv ? useItemApi(actualId, itemOrKv) : {};
Expand Down
77 changes: 25 additions & 52 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.