@feardread/feature-factory 1.1.7 → 1.1.9
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/dist/bundle.min.js +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/api/{api.js → factory.js} +2 -2
- package/src/factory/factory.js +5 -6
- package/src/index.js +3 -0
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@ import cache from "../cache/cache.js";
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
const
|
|
8
|
+
const InstanceFactory = ( options ) => {
|
|
9
9
|
|
|
10
10
|
const API_BASE_URL = (options.API_BASE_URL)
|
|
11
11
|
? options.API_BASE_URL
|
|
@@ -77,4 +77,4 @@ const API = ( options ) => {
|
|
|
77
77
|
|
|
78
78
|
|
|
79
79
|
|
|
80
|
-
export default
|
|
80
|
+
export default InstanceFactory;
|
package/src/factory/factory.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createSlice, createAsyncThunk } from '@reduxjs/toolkit';
|
|
2
|
-
import
|
|
2
|
+
import InstanceFactory from "../api/factory.js";
|
|
3
3
|
|
|
4
4
|
const StateFactory = (entity, data = null) => ({
|
|
5
5
|
[entity]: data,
|
|
@@ -9,9 +9,8 @@ const StateFactory = (entity, data = null) => ({
|
|
|
9
9
|
});
|
|
10
10
|
|
|
11
11
|
const FeatureFactory = (sliceName, endpoint, options = {}) => {
|
|
12
|
-
const { initialData, service } = options;
|
|
13
12
|
const apiEndpoint = `${sliceName}/${endpoint}`;
|
|
14
|
-
const apiInstance =
|
|
13
|
+
const apiInstance = InstanceFactory({
|
|
15
14
|
API_BASE_URL: 'http://fear.master.com:4000/fear/api',
|
|
16
15
|
JWT_TOKEN: 'fear-x-token'
|
|
17
16
|
});
|
|
@@ -33,7 +32,7 @@ const FeatureFactory = (sliceName, endpoint, options = {}) => {
|
|
|
33
32
|
);
|
|
34
33
|
|
|
35
34
|
const fetchOne = createAsyncThunk(
|
|
36
|
-
`${
|
|
35
|
+
`${sliceName}/one`,
|
|
37
36
|
async (id, { rejectWithValue }) => {
|
|
38
37
|
return await apiInstance.get(`${sliceName}/${id}`)
|
|
39
38
|
.then((response) => {
|
|
@@ -115,14 +114,14 @@ const FeatureFactory = (sliceName, endpoint, options = {}) => {
|
|
|
115
114
|
})
|
|
116
115
|
|
|
117
116
|
return {
|
|
118
|
-
API: API({ API_BASE_URL: 'http://fear.master.com:4000/fear/api' }),
|
|
119
117
|
reducer: slice.reducer,
|
|
120
118
|
actions: slice.actions,
|
|
119
|
+
instance: apiInstance,
|
|
121
120
|
asyncActions: {
|
|
122
121
|
fetch,
|
|
123
122
|
fetchOne,
|
|
124
123
|
search,
|
|
125
|
-
|
|
124
|
+
service: (options.service) ? options.service : null
|
|
126
125
|
},
|
|
127
126
|
|
|
128
127
|
}
|