@pushwoosh/spa-context 1.0.7 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import { SimpleEventEmitter } from './SimpleEventEmitter';
2
2
  import type { SPAContextType } from './types';
3
3
  import { UniversalKeyValueStore } from './UniversalKeyValueStore';
4
+ import { useSession } from './useSession';
4
5
  import { useSPAContext } from './useSPAContext';
5
6
  export type { SPAContextType };
6
- export { useSPAContext, SimpleEventEmitter, UniversalKeyValueStore };
7
+ export { useSPAContext, useSession, SimpleEventEmitter, UniversalKeyValueStore, };
7
8
  export declare const SPAContextProvider: import("react").Provider<SPAContextType | undefined>;
package/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { SPAContext } from './context';
2
2
  import { SimpleEventEmitter } from './SimpleEventEmitter';
3
3
  import { UniversalKeyValueStore } from './UniversalKeyValueStore';
4
+ import { useSession } from './useSession';
4
5
  import { useSPAContext } from './useSPAContext';
5
- export { useSPAContext, SimpleEventEmitter, UniversalKeyValueStore };
6
+ export { useSPAContext, useSession, SimpleEventEmitter, UniversalKeyValueStore };
6
7
  export const SPAContextProvider = SPAContext.Provider;
package/package.json CHANGED
@@ -35,5 +35,5 @@
35
35
  "@pushwoosh/session-store": "^2.5.0",
36
36
  "react": "^16.14.0 || ^18.0.0"
37
37
  },
38
- "version": "1.0.7"
38
+ "version": "1.1.1"
39
39
  }
package/types.d.ts CHANGED
@@ -27,6 +27,7 @@ export type SPAContextType = {
27
27
  readonly helpers: {
28
28
  readonly getApiOrigin: (name: string) => string;
29
29
  readonly getJsonApiUrl: (method: string) => string;
30
+ readonly getCdnOrigin: (path: string) => string;
30
31
  };
31
32
  readonly eventBus: SimpleEventEmitter;
32
33
  readonly environment: Environment;
@@ -0,0 +1,2 @@
1
+ import type { Session } from '@pushwoosh/session-store';
2
+ export declare function useSession(): Session;
package/useSession.js ADDED
@@ -0,0 +1,15 @@
1
+ import { useEffect, useState } from 'react';
2
+ import { useSPAContext } from './useSPAContext';
3
+ export function useSession() {
4
+ const {
5
+ sessionStore
6
+ } = useSPAContext();
7
+ const [session, setSession] = useState(sessionStore.getLastSession());
8
+ useEffect(() => {
9
+ const subscriber = sessionStore.subscribe(setSession);
10
+ return () => {
11
+ subscriber.unsubscribe();
12
+ };
13
+ }, [sessionStore]);
14
+ return session;
15
+ }