UNPKG

2.6 kBTypeScriptView Raw
1export { default as loadable } from '@loadable/component';
2import { RouteConfig, MatchedRoute } from 'react-router-config';
3export { RouteConfig } from 'react-router-config';
4import * as effector from 'effector';
5import { Event, Domain, Store, Unit } from 'effector';
6import * as history from 'history';
7import * as React from 'react';
8
9interface HistoryChange {
10 pathname: string;
11 hash: string;
12 search: string;
13 action: 'PUSH' | 'POP' | 'REPLACE';
14}
15
16declare function createBrowserApplication(config: {
17 ready: Event<void>;
18 routes: RouteConfig[];
19 domain?: Domain;
20}): {
21 navigation: {
22 history: history.History<unknown>;
23 historyPush: effector.Effect<string, void, Error>;
24 historyPushSearch: effector.Effect<string, void, Error>;
25 historyReplace: effector.Effect<string, void, Error>;
26 historyChanged: Event<HistoryChange>;
27 historyEmitCurrent: Event<void>;
28 $redirectTo: effector.Store<string>;
29 };
30};
31
32interface HatchParams {
33 params: Record<string, string>;
34 query: Record<string, string>;
35}
36/**
37 * Hatch is like a Gate, but just for models
38 */
39interface Hatch {
40 enter: Event<HatchParams>;
41 update: Event<HatchParams>;
42 exit: Event<void>;
43 $opened: Store<boolean>;
44 $params: Store<Record<string, string>>;
45 $query: Store<Record<string, string>>;
46 $props: Store<HatchParams>;
47}
48interface Config {
49 enter: Event<HatchParams>;
50 update: Event<HatchParams>;
51 exit: Event<void>;
52 domain?: Domain;
53}
54/**
55 * Events here is an input signal, history should call them when route enters, updates, and exits.
56 * Stores is derived from this events and holds specific parameters
57 * `$opened` holds current state of page, if user visited page but not left, it is `true`
58 */
59declare function createHatch(config_?: Config | Domain): Hatch;
60declare function withHatch<C extends React.ComponentType>(hatch: Hatch, component: C): C;
61declare function getHatch<T extends React.ComponentType<any>>(component: T): Hatch | undefined;
62declare function lookupHatch<P>(match: MatchedRoute<P>): Hatch | undefined;
63
64declare type KeysOfEffectorApi<API> = {
65 [KEY in keyof API]: API[KEY] extends Unit<any> ? KEY : never;
66}[keyof API];
67declare function contract<Properties extends string, Page extends Record<Properties, unknown>>(config: {
68 page: Page;
69 model: Pick<Page, KeysOfEffectorApi<Page>>;
70}): void;
71
72declare const createPages: (routes: RouteConfig[]) => JSX.Element;
73
74export { Hatch, HatchParams, contract, createBrowserApplication, createHatch, createPages, getHatch, lookupHatch, withHatch };