@@ -38,7 +38,7 @@ export default class VueWait {
38
38
}
39
39
40
40
init ( Vue , store ) {
41
- if ( nodeIsDebug ( ) && ! install . installed ) {
41
+ if ( nodeIsDebug ( ) && ! install . installed && VueWait . getVueVersion ( Vue ) < 3 ) {
42
42
console . warn (
43
43
`[vue-wait] not installed. Make sure to call \`Vue.use(VueWait)\` before init root instance.`
44
44
) ;
@@ -67,16 +67,25 @@ export default class VueWait {
67
67
store . registerModule ( vuexModuleName , vuexStore ) ;
68
68
}
69
69
70
- this . stateHandler = new Vue ( {
70
+ const config = {
71
71
computed : {
72
72
is : ( ) => waiter => store . getters [ `${ vuexModuleName } /is` ] ( waiter ) ,
73
73
any : ( ) => store . getters [ `${ vuexModuleName } /any` ] ,
74
74
percent : ( ) => waiter =>
75
75
store . getters [ `${ vuexModuleName } /percent` ] ( waiter )
76
76
}
77
- } ) ;
77
+ } ;
78
+
79
+ if ( VueWait . getVueVersion ( Vue ) > 2 ) {
80
+ const { createApp } = require ( 'vue' ) ;
81
+ this . stateHandler = createApp ( config ) . mount (
82
+ document . createElement ( 'div' )
83
+ ) ;
84
+ } else {
85
+ this . stateHandler = new Vue ( config ) ;
86
+ }
78
87
} else {
79
- this . stateHandler = new Vue ( {
88
+ const config = {
80
89
data ( ) {
81
90
return {
82
91
waitingFor : [ ] ,
@@ -106,7 +115,16 @@ export default class VueWait {
106
115
this . progresses = progress ( this . progresses , waiter , current , total ) ;
107
116
}
108
117
}
109
- } ) ;
118
+ } ;
119
+
120
+ if ( VueWait . getVueVersion ( Vue ) > 2 ) {
121
+ const { createApp } = require ( 'vue' ) ;
122
+ this . stateHandler = createApp ( config ) . mount (
123
+ document . createElement ( 'div' )
124
+ ) ;
125
+ } else {
126
+ this . stateHandler = new Vue ( config ) ;
127
+ }
110
128
}
111
129
112
130
this . initialized = true ;
@@ -116,6 +134,10 @@ export default class VueWait {
116
134
return this . stateHandler . any ;
117
135
}
118
136
137
+ static getVueVersion ( app ) {
138
+ return parseFloat ( ( app . version || '' ) . split ( '.' ) [ 0 ] || 0 ) ;
139
+ }
140
+
119
141
is ( waiter ) {
120
142
return this . stateHandler . is ( waiter ) ;
121
143
}
@@ -208,7 +230,34 @@ export function install(Vue) {
208
230
install . installed = true ;
209
231
}
210
232
233
+ function createVueWait ( options ) {
234
+ const Wait = {
235
+ async install ( app ) {
236
+ if ( this . installed && app ) {
237
+ if ( nodeIsDebug ( ) ) {
238
+ console . warn ( '[vue-wait] already installed' ) ;
239
+ }
240
+ return ;
241
+ }
242
+
243
+ const instance = new VueWait ( options ) ;
244
+ instance . init ( app , app . config . globalProperties . $store ) ;
245
+ app . config . globalProperties [ instance . options . accessorName ] = instance ;
246
+
247
+ app . mixin ( {
248
+ beforeCreate ( ) {
249
+ this . __$waitInstance = instance ;
250
+ }
251
+ } ) ;
252
+
253
+ this . installed = true ;
254
+ }
255
+ } ;
256
+
257
+ return Wait ;
258
+ }
259
+
211
260
// Export which are imported to export
212
- export { mapWaitingActions , mapWaitingGetters , waitFor } ;
261
+ export { mapWaitingActions , mapWaitingGetters , waitFor , createVueWait } ;
213
262
214
263
VueWait . install = install ;
0 commit comments