@@ -4,7 +4,9 @@ import type { Ref } from 'vue-demi';
44import type { Client , RebornClient } from '../clients' ;
55
66import { ref } from 'vue-demi' ;
7- import { INJECT_KEY , ROOT_STORE_MAP , setMode } from '../const' ;
7+ import { INJECT_KEY , ROOT_STORE_MAP , setRenderMode } from '../const' ;
8+
9+ export type RenderMode = 'SPA' | 'SSR' | 'SSG' ;
810
911export type GetModelInstance = ReturnType < typeof storeFactory > [ 'getModelInstance' ] ;
1012
@@ -16,7 +18,9 @@ export type HydrationStatus = Ref<0 | 1 | 2>;
1618export function storeFactory ( ) {
1719 const modelMap = new Map < ModelInfo < any > [ 'constructor' ] , ModelInfo < any > > ( ) ;
1820
19- function getModelInstance < T > ( constructor : ModelInfo < T > [ 'constructor' ] ) : RebornInstanceType < typeof constructor > | null {
21+ function getModelInstance < T > (
22+ constructor : ModelInfo < T > [ 'constructor' ] ,
23+ ) : RebornInstanceType < typeof constructor > | null {
2024 return modelMap . get ( constructor ) ?. instance ?. model as unknown as RebornInstanceType < typeof constructor > ;
2125 }
2226
@@ -75,7 +79,7 @@ export function createStore() {
7579 }
7680
7781 // 为了适配 vue 不同版本这里只能用 any 了
78- function install ( app : any , ssrMode : boolean = false ) {
82+ function install ( app : any , renderMode : boolean | RenderMode = false ) {
7983 // vue3
8084 if ( app . config && typeof app . config . globalProperties === 'object' ) {
8185 app . config . globalProperties . rebornStore = store ;
@@ -85,7 +89,7 @@ export function createStore() {
8589 store,
8690 rebornClient,
8791 } ) ;
88- // vue2.7
92+ // vue2.7
8993 } else {
9094 app . mixin ( {
9195 provide ( this ) {
@@ -94,7 +98,7 @@ export function createStore() {
9498 [ INJECT_KEY ] : {
9599 store,
96100 rebornClient,
97- }
101+ } ,
98102 } ;
99103 }
100104 } ,
@@ -104,13 +108,13 @@ export function createStore() {
104108 ROOT_STORE_MAP . set ( this , {
105109 store,
106110 rebornClient,
107- } )
111+ } ) ;
108112 }
109- }
113+ } ,
110114 } ) ;
111115 }
112116
113- setMode ( ssrMode ? 'SSR' : 'SPA' ) ;
117+ setRenderMode ( typeof renderMode === 'string' ? renderMode : renderMode ? 'SSR' : 'SPA' ) ;
114118 }
115119
116120 const result = {
0 commit comments