@@ -4,32 +4,32 @@ import { MatchedRoute } from 'react-router-config';
44
55import { defaultDomain } from './default-domain' ;
66
7- const HATCH = 'framework /page-hatch ' ;
7+ const ROUTE_PROPERTY = 'bypath /page-route ' ;
88
9- export interface HatchParams {
9+ export interface RouteParams {
1010 params : Record < string , string > ;
1111 query : Record < string , string > ;
1212}
1313
1414/**
15- * Hatch is like a Gate, but just for models
15+ * Route is like a Gate, but just for models
1616 */
17- export interface Hatch {
17+ export interface Route {
1818 // Called by history from withHatch
19- enter : Event < HatchParams > ;
20- update : Event < HatchParams > ;
19+ enter : Event < RouteParams > ;
20+ update : Event < RouteParams > ;
2121 exit : Event < void > ;
2222
2323 $opened : Store < boolean > ;
2424 $params : Store < Record < string , string > > ;
2525 $query : Store < Record < string , string > > ;
2626
27- $props : Store < HatchParams > ;
27+ $props : Store < RouteParams > ;
2828}
2929
3030interface Config {
31- enter : Event < HatchParams > ;
32- update : Event < HatchParams > ;
31+ enter : Event < RouteParams > ;
32+ update : Event < RouteParams > ;
3333 exit : Event < void > ;
3434 domain ?: Domain ;
3535}
@@ -39,7 +39,7 @@ interface Config {
3939 * Stores is derived from this events and holds specific parameters
4040 * `$opened` holds current state of page, if user visited page but not left, it is `true`
4141 */
42- export function createHatch ( config_ : Config | Domain = defaultDomain ) : Hatch {
42+ export function createRoute ( config_ : Config | Domain = defaultDomain ) : Route {
4343 let domain ;
4444 let config : Partial < Config > ;
4545 if ( is . domain ( config_ ) ) {
@@ -57,41 +57,41 @@ export function createHatch(config_: Config | Domain = defaultDomain): Hatch {
5757 const $params = domain . createStore < Record < string , string > > ( { } ) ;
5858 const $query = domain . createStore < Record < string , string > > ( { } ) ;
5959
60- const hatch = {
61- enter : config . enter ?? domain . createEvent < HatchParams > ( ) ,
62- update : config . update ?? domain . createEvent < HatchParams > ( ) ,
60+ const route = {
61+ enter : config . enter ?? domain . createEvent < RouteParams > ( ) ,
62+ update : config . update ?? domain . createEvent < RouteParams > ( ) ,
6363 exit : config . exit ?? domain . createEvent < void > ( ) ,
6464 $opened,
6565 $params,
6666 $query,
6767 $props : combine ( { params : $params , query : $query } ) ,
6868 } ;
6969
70- $params . on ( [ hatch . enter , hatch . update ] , ( _ , { params } ) => params ) ;
71- $query . on ( [ hatch . enter , hatch . update ] , ( _ , { query } ) => query ) ;
70+ $params . on ( [ route . enter , route . update ] , ( _ , { params } ) => params ) ;
71+ $query . on ( [ route . enter , route . update ] , ( _ , { query } ) => query ) ;
7272
73- hatch . $opened . on ( hatch . enter , ( ) => Boolean ( true ) ) . reset ( hatch . exit ) ;
73+ route . $opened . on ( route . enter , ( ) => Boolean ( true ) ) . reset ( route . exit ) ;
7474 // Developer may want to read props when user leaves the page
75- // if $opened store will reset on hatch .exit, data will be deleted
75+ // if $opened store will reset on route .exit, data will be deleted
7676
77- return hatch ;
77+ return route ;
7878}
7979
80- export function withHatch < C extends React . ComponentType > ( hatch : Hatch , component : C ) : C {
80+ export function withRoute < C extends React . ComponentType > ( hatch : Route , component : C ) : C {
8181 // eslint-disable-next-line @typescript-eslint/no-explicit-any
82- ( component as any ) [ HATCH ] = hatch ;
82+ ( component as any ) [ ROUTE_PROPERTY ] = hatch ;
8383 return component ;
8484}
8585
8686// eslint-disable-next-line @typescript-eslint/no-explicit-any
87- export function getHatch < T extends React . ComponentType < any > > ( component : T ) : Hatch | undefined {
87+ export function getRoute < T extends React . ComponentType < any > > ( component : T ) : Route | undefined {
8888 // eslint-disable-next-line @typescript-eslint/no-explicit-any
89- return ( component as any ) [ HATCH ] ;
89+ return ( component as any ) [ ROUTE_PROPERTY ] ;
9090}
9191
92- export function lookupHatch < P > ( match : MatchedRoute < P > ) : Hatch | undefined {
92+ export function lookupRoute < P > ( match : MatchedRoute < P > ) : Route | undefined {
9393 if ( match . route . component ) {
9494 // eslint-disable-next-line @typescript-eslint/no-explicit-any
95- return getHatch ( match . route . component as any ) ;
95+ return getRoute ( match . route . component as any ) ;
9696 }
9797}
0 commit comments