UNPKG

3.25 kBTypeScriptView Raw
1import React from 'react';
2import { Middleware as ReduxMiddleware, Store as ReduxStore } from 'redux';
3import { buildMiddleware } from './Middleware';
4import { ReducerMap, Store } from './store/async';
5import { TrackingEventPayload, Application, ApiClientConfig } from './types';
6import { Props as HostProps } from './Host';
7/**
8 * The current pathname, search params and hash
9 * @internal
10 * */
11export interface Location {
12 pathname: string;
13 search?: string;
14 hash?: string;
15}
16/**
17 * The method to call when attempting to update the router history
18 * When the return value is a string or `true`, the router update will be blocked
19 * @internal
20 * */
21export interface Prompt {
22 (nextLocation?: Location): string | false | void;
23}
24/**
25 * The interface for the Navigation Context
26 * @public
27 * */
28export interface RouterContext {
29 /** The `handle` or `apiKey` for the current app */
30 appRoot: string;
31 hostname: string;
32 /** The router to be to handle router actions */
33 history: {
34 replace(path: string): void;
35 replace(nextLocation: Location): void;
36 push(path: string): void;
37 push(nextLocation: Location): void;
38 block?(prompt?: boolean | string | Prompt): () => void;
39 };
40 location: Location;
41}
42/**
43 * The interface for the HostProvider
44 * @public
45 * */
46export interface Props extends HostProps {
47 /** Configuration of the app to load */
48 config?: ApiClientConfig;
49 /** Optional handler for when App Bridge actions are dispatched */
50 dispatchClientEventHandler?: (trackingEventPayload: TrackingEventPayload) => void;
51 /** Required to set the initial app state
52 * @remarks feature permissions must be specified using the key `features` which will take effect immediately
53 * other state properties (ex. `loading`, `toast`, etc..) will only be set after the relevant reducer has loaded
54 */
55 initialState: Partial<Store> & Pick<Store, 'features'>;
56 /** Set the middleware to use when creating the Redux store */
57 middleware?: Array<ReturnType<typeof buildMiddleware> | ReduxMiddleware>;
58 /** Set the router to use when a Navigation action results in a route change
59 * @remarks this is required when using host components that handles navigation
60 * for example: MainFrame, ContextualSaveBar and Navigation
61 */
62 router?: RouterContext;
63 /** Enables the Redux dev tools if set to `true` */
64 debug?: boolean;
65}
66/**
67 * The interface for the Host Context that can be
68 * consumed by the Host Provider's child components
69 * @public
70 * */
71export interface HostContext {
72 app: Application;
73 config: ApiClientConfig;
74 addReducer<State>(reducerMap: ReducerMap<State>): void;
75 store: ReduxStore;
76}
77/**
78 * The context provider for the app, config and addReducer method
79 * @public
80 * */
81export declare const HostContext: React.Context<HostContext | null>;
82/**
83 * The context provider for the router.
84 * Keeps track of the current location and
85 * handles history push/replace
86 * @public
87 * */
88export declare const RouterContext: React.Context<RouterContext | null>;
89/**
90 * A component that creates a dynamic Redux store
91 * and renders the Host
92 * @public
93 * */
94export default function HostProvider(props: Props): JSX.Element;