Skip to content

Commit

Permalink
Upgraded packages and added a unmount fix
Browse files Browse the repository at this point in the history
  • Loading branch information
techbech committed Jan 14, 2021
1 parent 4fd82ff commit 87bc310
Show file tree
Hide file tree
Showing 10 changed files with 3,388 additions and 3,050 deletions.
14 changes: 13 additions & 1 deletion dist/index.js

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

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

14 changes: 13 additions & 1 deletion dist/index.modern.js

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

2 changes: 1 addition & 1 deletion dist/index.modern.js.map

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions dist/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { Dispatch, SetStateAction } from "react";
import { Dispatcher } from "./dispatcher";
export declare type SessionValueType = {} | null | undefined;
export declare type SessionGenericData = {
[key: string]: SessionValueType;
};
export declare type SessionDispatchFunc = Dispatch<SetStateAction<any>>;
export declare type SessionDispatchFunc = (value: any) => void;
export declare type SessionContextKey = string;
export declare type SessionOnChange<DataType extends SessionGenericData> = (data: DataType) => void;
export declare type SessionGenericContext<DataType extends SessionGenericData = SessionGenericData> = {
Expand Down
2,848 changes: 1,496 additions & 1,352 deletions example/yarn.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@peteck/react-context-session",
"version": "1.0.7",
"version": "1.0.8",
"description": "Arbitrary session data with support for multiple contexts",
"author": "Peteck",
"license": "MIT",
Expand Down
3 changes: 1 addition & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Dispatch, SetStateAction } from "react";
import { Dispatcher } from "./dispatcher";

export type SessionValueType = {} | null | undefined;
export type SessionGenericData = { [key: string]: SessionValueType };
export type SessionDispatchFunc = Dispatch<SetStateAction<any>>;
export type SessionDispatchFunc = (value: any) => void;
export type SessionContextKey = string;
export type SessionOnChange<DataType extends SessionGenericData> = (
data: DataType,
Expand Down
13 changes: 9 additions & 4 deletions src/use-session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,19 @@ export function useSessionBase<
}

useEffect(() => {
let didUnmount = false;

for (let i = 0; i < k.length; i++) {
context.dispatcher.register(
k[i] as string,
states[k[i] as string][1],
);
context.dispatcher.register(k[i] as string, (value) => {
if (!didUnmount) {
states[k[i] as string][1](value);
}
});
}

return () => {
didUnmount = true;

for (let i = 0; i < k.length; i++) {
context.dispatcher.unregister(
k[i] as string,
Expand Down
3,537 changes: 1,852 additions & 1,685 deletions yarn.lock

Large diffs are not rendered by default.

0 comments on commit 87bc310

Please sign in to comment.