@thzero/library_client_vue3_store_pinia 0.16.12 → 0.16.13

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/README.md CHANGED
@@ -4,6 +4,17 @@
4
4
 
5
5
  # library_client_vue3_store_pinia
6
6
 
7
- An opinionated library for vue3 with pinia store for the library_client_vue3 using the [https://prazdevs.github.io/pinia-plugin-persistedstate](https://prazdevs.github.io/pinia-plugin-persistedstate) library.
7
+ An opinionated library for vue3 with [Pinia](https://github.com/vuejs/pinia) store for the library_client_vue3 using the [pinia-plugin-persistedstate](https://prazdevs.github.io/pinia-plugin-persistedstate) or [pinia-plugin-persistedstate-2](https://github.com/iendeavor/pinia-plugin-persistedstate-2) library.
8
+
9
+ ## Installation
8
10
 
9
11
  [![NPM](https://nodei.co/npm/@thzero/library_common.png?compact=true)](https://npmjs.org/package/@thzero/library_client_vue3_store_pinia)
12
+
13
+ ### Requirements
14
+
15
+ #### NodeJs
16
+
17
+ Requires
18
+ * [library_common](https://npmjs.org/package/@thzero/library_common)
19
+ * [library_client](https://npmjs.org/package/@thzero/library_client)
20
+ * [library_client_vue3](https://npmjs.org/package/@thzero/library_client_vue3)
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@thzero/library_client_vue3_store_pinia",
3
- "version": "0.16.12",
3
+ "version": "0.16.13",
4
4
  "version_major": 0,
5
5
  "version_minor": 16,
6
- "version_patch": 12,
6
+ "version_patch": 13,
7
7
  "version_date": "11/25/2022",
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",
@@ -25,6 +25,7 @@
25
25
  "@thzero/library_common": "^0.16",
26
26
  "pinia": "^2.0.26",
27
27
  "pinia-plugin-persistedstate": "^2.4.0",
28
+ "pinia-plugin-persistedstate-2": "^2.0.3",
28
29
  "vue": "^3.2.45"
29
30
  }
30
31
  }
File without changes
File without changes
File without changes
package/store/index.js ADDED
@@ -0,0 +1,145 @@
1
+ import { createPinia, defineStore } from 'pinia';
2
+ import piniaPluginPersistedState from 'pinia-plugin-persistedstate';
3
+ import { createPersistedStatePlugin } from 'pinia-plugin-persistedstate-2';
4
+
5
+ import LibraryConstants from '@thzero/library_client/constants';
6
+
7
+ import GlobalUtility from '@thzero/library_client/utility/global';
8
+
9
+ import NotImplementedError from '@thzero/library_common/errors/notImplemented';
10
+
11
+ // import adminNews from './admin/news/pinia';
12
+ // import adminUsers from './admin/users/pinia';
13
+
14
+ import news from './news';
15
+ import user from './user';
16
+
17
+ class BaseStore {
18
+ async initialize() {
19
+ this.pinia = createPinia();
20
+
21
+ this._initPluginPersist();
22
+
23
+ return this.pinia;
24
+ }
25
+
26
+ setup() {
27
+ const logger = GlobalUtility.$injector.getService(LibraryConstants.InjectorKeys.SERVICE_LOGGER);
28
+ return {
29
+ func: {
30
+ install(app, options) {
31
+ const storeConfig = options.storeConfig;
32
+
33
+ options.actionDispatcher = storeConfig.dispatcher;
34
+ if (!options.actionDispatcher)
35
+ options.actionDispatcher = {};
36
+
37
+ if (options.pluginPersistSetup && options.pluginPersistType && options.pluginPersistConfig && options.pluginPersistConfig['root'])
38
+ options.pluginPersistSetup(options.pluginPersistType(), storeConfig, options.pluginPersistConfig['root'], options.pluginPersistSetupOverride);
39
+
40
+ const storeFunc = defineStore('main', storeConfig);
41
+ GlobalUtility.$store = storeFunc(options.pinia);
42
+ GlobalUtility.$store.$logger = options.logger;
43
+
44
+ // options.addModule('adminNews', adminNews, options.actionDispatcher, options.pluginPersistType(), options.pluginPersistConfig, options.pinia, logger);
45
+ // options.addModule('adminUsers', adminUsers, options.actionDispatcher, options.pluginPersistType(), options.pluginPersistConfig, options.pinia, logger);
46
+ options.addModule('news', news, options.actionDispatcher, options.pluginPersistType(), options.pluginPersistSetup, options.pluginPersistConfig, options.pluginPersistSetupOverride, options.pinia, logger);
47
+ options.addModule('user', user, options.actionDispatcher, options.pluginPersistType(), options.pluginPersistSetup, options.pluginPersistConfig, options.pluginPersistSetupOverride, options.pinia, logger);
48
+ options.initModules();
49
+ GlobalUtility.$store.dispatcher = options.actionDispatcher;
50
+ }
51
+ },
52
+ options: {
53
+ actionDispatcher: this.actionDispatcher,
54
+ addModule: this._addModule,
55
+ initModules: this._initModules,
56
+ logger: logger,
57
+ pinia: this.pinia,
58
+ pluginPersistConfig: this._initPluginPersistConfig(),
59
+ pluginPersistSetupOverride: this._initPluginPersistConfigSetupOverride,
60
+ pluginPersistSetup: this._initPluginPersistConfigSetup,
61
+ pluginPersistType: this._initPluginPersistType,
62
+ storeConfig: this._init()
63
+ }
64
+ };
65
+ }
66
+
67
+ _addModule(key, storeConfig, actionDispatcher, pluginPersistType, pluginPersistSetup, pluginPersistConfig, pluginPersistSetupOverride, pinia, logger) {
68
+ if (pluginPersistType && pluginPersistSetup && pluginPersistConfig && pluginPersistConfig[key])
69
+ pluginPersistSetup(pluginPersistType, storeConfig, pluginPersistConfig['root'], pluginPersistSetupOverride);
70
+ actionDispatcher[key] = storeConfig.dispatcher;
71
+ delete storeConfig.dispatcher;
72
+ const storeFunc = defineStore(key, storeConfig);
73
+ GlobalUtility.$store[key] = storeFunc(pinia);
74
+ GlobalUtility.$store[key].$logger = logger;
75
+ }
76
+
77
+ _init() {
78
+ throw new NotImplementedError();
79
+ }
80
+
81
+ _initModules() {
82
+ throw new NotImplementedError();
83
+ }
84
+
85
+ _initPluginPersist() {
86
+ if (this._initPluginPersistType() === BaseStore.PersistanceTypePersist) {
87
+ this.pinia.use(piniaPluginPersistedState);
88
+ return;
89
+ }
90
+ if (this._initPluginPersistType() === BaseStore.PersistanceTypePersist2) {
91
+ const installPersistedStatePlugin = createPersistedStatePlugin();
92
+ this.pinia.use((context) => installPersistedStatePlugin(context));
93
+ return;
94
+ }
95
+ if (this._initPluginPersistType() === BaseStore.PersistanceTypeOverride) {
96
+ const override = this._initPluginPersistOverride();
97
+ if (override) {
98
+ override(this.pinia);
99
+ return;
100
+ }
101
+ }
102
+
103
+ throw Error('Unknown persistance engine for Pinia store.');
104
+ }
105
+
106
+ _initPluginPersistConfig() {
107
+ return null;
108
+ }
109
+
110
+ _initPluginPersistOverride() {
111
+ return null;
112
+ }
113
+
114
+ _initPluginPersistType() {
115
+ return BaseStore.PersistanceTypePersist;
116
+ }
117
+
118
+ _initPluginPersistConfigSetup(type, storeConfig, persistConfig, override) {
119
+ if (type === BaseStore.PersistanceTypePersist) {
120
+ storeConfig.persist = persistConfig;
121
+ return;
122
+ }
123
+ if (type === BaseStore.PersistanceTypePersist2) {
124
+ storeConfig.persistedState = persistConfig;
125
+ return;
126
+ }
127
+ if (type === BaseStore.PersistanceTypeOverride) {
128
+ if (override) {
129
+ override(storeConfig, persistConfig);
130
+ return;
131
+ }
132
+ }
133
+
134
+ throw Error('Unknown persistance engine for Pinia store.');
135
+ }
136
+
137
+ _initPluginPersistConfigSetupOverride(storeConfig, persistConfig) {
138
+ }
139
+
140
+ static PersistanceTypeOverride = 'override';
141
+ static PersistanceTypePersist = 'persist';
142
+ static PersistanceTypePersist2 = 'persist2';
143
+ }
144
+
145
+ export default BaseStore;
File without changes
File without changes
package/store/pinia.js DELETED
@@ -1,89 +0,0 @@
1
- import { createPinia, defineStore } from 'pinia';
2
- import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'
3
-
4
- import LibraryConstants from '@thzero/library_client/constants';
5
-
6
- import GlobalUtility from '@thzero/library_client/utility/global';
7
-
8
- import NotImplementedError from '@thzero/library_common/errors/notImplemented';
9
-
10
- // import adminNews from './admin/news/pinia';
11
- // import adminUsers from './admin/users/pinia';
12
-
13
- import news from './news/pinia';
14
- import user from './user/pinia';
15
-
16
- class BaseStore {
17
- async initialize() {
18
- this.pinia = createPinia();
19
-
20
- const pluginPersist = this._initPluginPersist();
21
- if (pluginPersist) {
22
- this.pinia.use(piniaPluginPersistedstate);
23
- }
24
-
25
- return this.pinia;
26
- }
27
-
28
- setup() {
29
- const logger = GlobalUtility.$injector.getService(LibraryConstants.InjectorKeys.SERVICE_LOGGER);
30
- return {
31
- func: {
32
- install(app, options) {
33
- const storeConfig = options.storeConfig;
34
-
35
- options.actionDispatcher = storeConfig.dispatcher;
36
- if (!options.actionDispatcher)
37
- options.actionDispatcher = {};
38
-
39
- if (options.pluginPersist && options.pluginPersist['root'])
40
- storeConfig.persist = options.pluginPersist['root'];
41
-
42
- const storeFunc = defineStore('main', storeConfig);
43
- GlobalUtility.$store = storeFunc(options.pinia);
44
- GlobalUtility.$store.$logger = options.logger;
45
-
46
- // options.addModule('adminNews', adminNews, options.actionDispatcher, options.pluginPersist, options.pinia, logger);
47
- // options.addModule('adminUsers', adminUsers, options.actionDispatcher, options.pluginPersist, options.pinia, logger);
48
- options.addModule('news', news, options.actionDispatcher, options.pluginPersist, options.pinia, logger);
49
- options.addModule('user', user, options.actionDispatcher, options.pluginPersist, options.pinia, logger);
50
- options.initModules();
51
- GlobalUtility.$store.dispatcher = options.actionDispatcher;
52
- }
53
- },
54
- options: {
55
- actionDispatcher: this.actionDispatcher,
56
- addModule: this._addModule,
57
- initModules: this._initModules,
58
- logger: logger,
59
- pinia: this.pinia,
60
- pluginPersist: this._initPluginPersist(),
61
- storeConfig: this._init()
62
- }
63
- };
64
- }
65
-
66
- _addModule(key, storeConfig, actionDispatcher, pluginPersist, pinia, logger) {
67
- if (pluginPersist && pluginPersist[key])
68
- storeConfig.persist = pluginPersist[key];
69
- actionDispatcher[key] = storeConfig.dispatcher;
70
- delete storeConfig.dispatcher;
71
- const storeFunc = defineStore(key, storeConfig);
72
- GlobalUtility.$store[key] = storeFunc(pinia);
73
- GlobalUtility.$store[key].$logger = logger;
74
- }
75
-
76
- _init() {
77
- throw new NotImplementedError();
78
- }
79
-
80
- _initModules() {
81
- throw new NotImplementedError();
82
- }
83
-
84
- _initPluginPersist() {
85
- return null;
86
- }
87
- }
88
-
89
- export default BaseStore;