@thzero/library_client_vue3_store_pinia 0.17.3 → 0.17.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +6 -6
- package/store/index.js +27 -10
- package/store/user/index.js +27 -12
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thzero/library_client_vue3_store_pinia",
|
|
3
|
-
"version": "0.17.
|
|
3
|
+
"version": "0.17.5",
|
|
4
4
|
"version_major": 0,
|
|
5
5
|
"version_minor": 17,
|
|
6
|
-
"version_patch":
|
|
7
|
-
"version_date": "
|
|
6
|
+
"version_patch": 5,
|
|
7
|
+
"version_date": "03/12/2023",
|
|
8
8
|
"description": "An opinionated library for vue3 with pinia store for the library_client_vue3 using the https://prazdevs.github.io/pinia-plugin-persistedstate library.",
|
|
9
9
|
"author": "thZero",
|
|
10
10
|
"license": "MIT",
|
|
@@ -23,9 +23,9 @@
|
|
|
23
23
|
"@thzero/library_client": "^0.17",
|
|
24
24
|
"@thzero/library_client_vue3": "^0.17",
|
|
25
25
|
"@thzero/library_common": "^0.17",
|
|
26
|
-
"pinia": "^2.0.
|
|
27
|
-
"pinia-plugin-persistedstate": "^3.0
|
|
28
|
-
"pinia-plugin-persistedstate-2": "^2.0.
|
|
26
|
+
"pinia": "^2.0.33",
|
|
27
|
+
"pinia-plugin-persistedstate": "^3.1.0",
|
|
28
|
+
"pinia-plugin-persistedstate-2": "^2.0.14",
|
|
29
29
|
"vue": "^3.2.47"
|
|
30
30
|
}
|
|
31
31
|
}
|
package/store/index.js
CHANGED
|
@@ -27,7 +27,7 @@ class BaseStore {
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
setup() {
|
|
30
|
-
const logger = LibraryClientUtility.$injector.getService(LibraryClientConstants.InjectorKeys.SERVICE_LOGGER);
|
|
30
|
+
// const logger = LibraryClientUtility.$injector.getService(LibraryClientConstants.InjectorKeys.SERVICE_LOGGER);
|
|
31
31
|
|
|
32
32
|
const initialStoreConfig = this._initStoreConfigBase();
|
|
33
33
|
const appStoreConfig = this._initStoreConfig();
|
|
@@ -44,10 +44,10 @@ class BaseStore {
|
|
|
44
44
|
func: {
|
|
45
45
|
install(app, options) {
|
|
46
46
|
const storeConfig = options.storeConfig;
|
|
47
|
-
|
|
47
|
+
|
|
48
48
|
options.actionGetters = storeConfig.getters;
|
|
49
49
|
options.actionDispatcher = storeConfig.dispatcher;
|
|
50
|
-
if (!options.actionDispatcher)
|
|
50
|
+
if (!options.actionDispatcher)
|
|
51
51
|
options.actionDispatcher = {};
|
|
52
52
|
|
|
53
53
|
const pluginPersistType = options.pluginPersistType();
|
|
@@ -57,20 +57,29 @@ class BaseStore {
|
|
|
57
57
|
options.pluginPersistSetup(pluginPersistType, storeConfig, options.pluginPersistConfig[pluginPersistType], options.pluginPersistSetupOverride, {
|
|
58
58
|
additionalPaths: additionalPaths
|
|
59
59
|
});
|
|
60
|
-
|
|
60
|
+
|
|
61
61
|
// if (storeConfig.pluginPersistPaths && storeConfig.pluginPersistPaths[pluginPersistType])
|
|
62
62
|
// storeConfig[pluginPersistType].paths = [ ...storeConfig[pluginPersistType].paths, ...storeConfig.pluginPersistPaths[pluginPersistType] ];
|
|
63
63
|
delete storeConfig.pluginPersistPaths;
|
|
64
64
|
|
|
65
65
|
const storeFunc = defineStore('main', storeConfig);
|
|
66
66
|
LibraryClientUtility.$store = storeFunc(options.pinia);
|
|
67
|
-
LibraryClientUtility.$store.$logger = options.logger;
|
|
67
|
+
//LibraryClientUtility.$store.$logger = options.logger;
|
|
68
|
+
Object.defineProperty(LibraryClientUtility.$store, '$logger', {
|
|
69
|
+
get() {
|
|
70
|
+
if (!this._logger)
|
|
71
|
+
this._logger = LibraryClientUtility.$injector.getService(LibraryClientConstants.InjectorKeys.SERVICE_LOGGER);
|
|
72
|
+
return this._logger;
|
|
73
|
+
},
|
|
74
|
+
});
|
|
68
75
|
|
|
69
76
|
const storeFuncModules = [];
|
|
70
77
|
// options.addModule('adminNews', adminNews, options.actionDispatcher, pluginPersistType, options.pluginPersistConfig, options.pinia, logger);
|
|
71
78
|
// options.addModule('adminUsers', adminUsers, options.actionDispatcher, pluginPersistType, options.pluginPersistConfig, options.pinia, logger);
|
|
72
|
-
storeFuncModules.push(options.addModule('news', news, options.actionDispatcher, options.actionGetters, storeConfig.persist, pluginPersistType, options.pluginPersistSetup, options.pluginPersistSetupOverride, options.pinia, logger));
|
|
73
|
-
storeFuncModules.push(options.addModule('user', user, options.actionDispatcher, options.actionGetters, storeConfig.persist, pluginPersistType, options.pluginPersistSetup, options.pluginPersistSetupOverride, options.pinia, logger));
|
|
79
|
+
// storeFuncModules.push(options.addModule('news', news, options.actionDispatcher, options.actionGetters, storeConfig.persist, pluginPersistType, options.pluginPersistSetup, options.pluginPersistSetupOverride, options.pinia, logger));
|
|
80
|
+
// storeFuncModules.push(options.addModule('user', user, options.actionDispatcher, options.actionGetters, storeConfig.persist, pluginPersistType, options.pluginPersistSetup, options.pluginPersistSetupOverride, options.pinia, logger));
|
|
81
|
+
storeFuncModules.push(options.addModule('news', news, options.actionDispatcher, options.actionGetters, storeConfig.persist, pluginPersistType, options.pluginPersistSetup, options.pluginPersistSetupOverride, options.pinia));
|
|
82
|
+
storeFuncModules.push(options.addModule('user', user, options.actionDispatcher, options.actionGetters, storeConfig.persist, pluginPersistType, options.pluginPersistSetup, options.pluginPersistSetupOverride, options.pinia));
|
|
74
83
|
|
|
75
84
|
storeFuncModules.push(...options.initModules());
|
|
76
85
|
|
|
@@ -83,7 +92,7 @@ class BaseStore {
|
|
|
83
92
|
actionGetters: this.actionGetters,
|
|
84
93
|
addModule: this._addModule,
|
|
85
94
|
initModules: this._initModules,
|
|
86
|
-
logger: logger,
|
|
95
|
+
// logger: logger,
|
|
87
96
|
pinia: this.pinia,
|
|
88
97
|
pluginPersistConfig: this._initPluginPersistConfig(),
|
|
89
98
|
pluginPersistSetupOverride: this._initPluginPersistConfigSetupOverride,
|
|
@@ -94,7 +103,8 @@ class BaseStore {
|
|
|
94
103
|
};
|
|
95
104
|
}
|
|
96
105
|
|
|
97
|
-
_addModule(key, storeConfig, actionDispatcher, actionGetters, pluginPersistConfig, pluginPersistType, pluginPersistSetup, pluginPersistSetupOverride, pinia, logger) {
|
|
106
|
+
// _addModule(key, storeConfig, actionDispatcher, actionGetters, pluginPersistConfig, pluginPersistType, pluginPersistSetup, pluginPersistSetupOverride, pinia, logger) {
|
|
107
|
+
_addModule(key, storeConfig, actionDispatcher, actionGetters, pluginPersistConfig, pluginPersistType, pluginPersistSetup, pluginPersistSetupOverride, pinia) {
|
|
98
108
|
if (pluginPersistType && pluginPersistSetup && storeConfig.pluginPersistPaths && storeConfig.pluginPersistPaths[pluginPersistType]) {
|
|
99
109
|
pluginPersistConfig = LibraryCommonUtility.cloneDeep(pluginPersistConfig);
|
|
100
110
|
pluginPersistSetup(pluginPersistType, storeConfig, pluginPersistConfig, pluginPersistSetupOverride, {
|
|
@@ -109,7 +119,14 @@ class BaseStore {
|
|
|
109
119
|
delete storeConfig.pluginPersistPaths;
|
|
110
120
|
const storeFunc = defineStore(key, storeConfig);
|
|
111
121
|
LibraryClientUtility.$store[key] = storeFunc(pinia);
|
|
112
|
-
LibraryClientUtility.$store[key].$logger = logger;
|
|
122
|
+
// LibraryClientUtility.$store[key].$logger = logger;
|
|
123
|
+
Object.defineProperty(LibraryClientUtility.$store[key], '$logger', {
|
|
124
|
+
get() {
|
|
125
|
+
if (!this._logger)
|
|
126
|
+
this._logger = LibraryClientUtility.$injector.getService(LibraryClientConstants.InjectorKeys.SERVICE_LOGGER);
|
|
127
|
+
return this._logger;
|
|
128
|
+
},
|
|
129
|
+
});
|
|
113
130
|
return { key: key, storeFunc: storeFunc };
|
|
114
131
|
}
|
|
115
132
|
|
package/store/user/index.js
CHANGED
|
@@ -8,6 +8,7 @@ import Response from '@thzero/library_common/response';
|
|
|
8
8
|
const store = {
|
|
9
9
|
pluginPersistPaths: {
|
|
10
10
|
persist: [
|
|
11
|
+
'settings',
|
|
11
12
|
'user'
|
|
12
13
|
]
|
|
13
14
|
},
|
|
@@ -15,6 +16,7 @@ const store = {
|
|
|
15
16
|
authCompleted: false,
|
|
16
17
|
claims: null,
|
|
17
18
|
isLoggedIn: false,
|
|
19
|
+
settings: {},
|
|
18
20
|
theme: 'defaultTheme',
|
|
19
21
|
token: null,
|
|
20
22
|
tokenResult: null,
|
|
@@ -35,9 +37,17 @@ const store = {
|
|
|
35
37
|
isLoggedIn: false,
|
|
36
38
|
token: null,
|
|
37
39
|
tokenResult: null,
|
|
40
|
+
settings: {},
|
|
38
41
|
user: null
|
|
39
42
|
});
|
|
40
43
|
},
|
|
44
|
+
async setUser(correlationId, user) {
|
|
45
|
+
if (user) {
|
|
46
|
+
this.settings = LibraryClientVueUtility.settings().mergeUser(correlationId, user.settings);
|
|
47
|
+
delete user.settings;
|
|
48
|
+
}
|
|
49
|
+
this.user = user;
|
|
50
|
+
},
|
|
41
51
|
async setUserAuthCompleted(correlationId, authCompleted) {
|
|
42
52
|
this.authCompleted = authCompleted;
|
|
43
53
|
},
|
|
@@ -50,11 +60,21 @@ const store = {
|
|
|
50
60
|
async setUserSettings(correlationId, settings) {
|
|
51
61
|
const service = LibraryClientUtility.$injector.getService(LibraryClientConstants.InjectorKeys.SERVICE_USER);
|
|
52
62
|
settings = LibraryClientVueUtility.settings().mergeUser(correlationId, settings);
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
63
|
+
if (this.isLoggedIn) {
|
|
64
|
+
const response = await service.updateSettings(correlationId, this.user, settings);
|
|
65
|
+
this.$logger.debug('store.user', 'setUserSettings', 'response', response);
|
|
66
|
+
if (Response.hasSucceeded(response) && response.results) {
|
|
67
|
+
// this.settings = response.results.settings;
|
|
68
|
+
// delete response.results.settings;
|
|
69
|
+
// this.user = response.results;
|
|
70
|
+
// response.results = this.settings;
|
|
71
|
+
this.setUser(correlationId, response.results);
|
|
72
|
+
response.results = this.settings;
|
|
73
|
+
}
|
|
74
|
+
return response;
|
|
75
|
+
}
|
|
76
|
+
this.settings = LibraryClientVueUtility.settings().mergeUser(correlationId, settings);
|
|
77
|
+
return Response.success(correlationId, this.settings);
|
|
58
78
|
},
|
|
59
79
|
async setUserTheme(correlationId, isLoggedIn) {
|
|
60
80
|
this.theme = theme;
|
|
@@ -64,11 +84,6 @@ const store = {
|
|
|
64
84
|
tokenResult: null,
|
|
65
85
|
token: tokenResult ? tokenResult.token : null
|
|
66
86
|
});
|
|
67
|
-
},
|
|
68
|
-
async setUser(correlationId, user) {
|
|
69
|
-
if (user)
|
|
70
|
-
user.settings = LibraryClientVueUtility.settings().mergeUser(correlationId, user.settings);
|
|
71
|
-
this.user = user;
|
|
72
87
|
}
|
|
73
88
|
},
|
|
74
89
|
getters: {
|
|
@@ -79,8 +94,8 @@ const store = {
|
|
|
79
94
|
return LibraryClientUtility.$store.theme;
|
|
80
95
|
},
|
|
81
96
|
getUserSettings(correlationId) {
|
|
82
|
-
if (LibraryClientUtility.$store.user.
|
|
83
|
-
return LibraryClientUtility.$store.user.
|
|
97
|
+
if (LibraryClientUtility.$store.user.settings) // TODO: userRef
|
|
98
|
+
return LibraryClientUtility.$store.user.settings;
|
|
84
99
|
|
|
85
100
|
const service = LibraryClientUtility.$injector.getService(LibraryClientConstants.InjectorKeys.SERVICE_USER);
|
|
86
101
|
return service.initializeSettings();
|