@feardread/feature-factory 1.1.9 → 2.0.0

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@feardread/feature-factory",
3
- "version": "1.1.9",
3
+ "version": "2.0.0",
4
4
  "main": "dist/index.js",
5
5
  "scripts": {
6
6
  "build": "rollup -c",
@@ -10,7 +10,7 @@ const StateFactory = (entity, data = null) => ({
10
10
 
11
11
  const FeatureFactory = (sliceName, endpoint, options = {}) => {
12
12
  const apiEndpoint = `${sliceName}/${endpoint}`;
13
- const apiInstance = InstanceFactory({
13
+ const API = InstanceFactory({
14
14
  API_BASE_URL: 'http://fear.master.com:4000/fear/api',
15
15
  JWT_TOKEN: 'fear-x-token'
16
16
  });
@@ -18,7 +18,7 @@ const FeatureFactory = (sliceName, endpoint, options = {}) => {
18
18
  const fetch = createAsyncThunk(
19
19
  apiEndpoint,
20
20
  async (_, { rejectWithValue }) => {
21
- return await apiInstance.get(apiEndpoint)
21
+ return await API.get(apiEndpoint)
22
22
  .then((response) => {
23
23
  if (response.data && response.data.success) {
24
24
  return response.data.result;
@@ -34,7 +34,7 @@ const FeatureFactory = (sliceName, endpoint, options = {}) => {
34
34
  const fetchOne = createAsyncThunk(
35
35
  `${sliceName}/one`,
36
36
  async (id, { rejectWithValue }) => {
37
- return await apiInstance.get(`${sliceName}/${id}`)
37
+ return await API.get(`${sliceName}/${id}`)
38
38
  .then((response) => {
39
39
  if (response.data && response.data.success) {
40
40
  return response.data.result;
@@ -49,7 +49,7 @@ const FeatureFactory = (sliceName, endpoint, options = {}) => {
49
49
  const search = createAsyncThunk(
50
50
  `${sliceName}/search`,
51
51
  async (query, { rejectWithValue }) => {
52
- return await apiInstance.get(`${sliceName}/search?${query}`)
52
+ return await API.get(`${sliceName}/search?${query}`)
53
53
  .then((response) => {
54
54
  if (response.data && response.data.success) {
55
55
  return response.data.result;
@@ -63,7 +63,7 @@ const FeatureFactory = (sliceName, endpoint, options = {}) => {
63
63
 
64
64
  const slice = createSlice({
65
65
  sliceName,
66
- initialState: StateFactory(sliceName, initialData),
66
+ initialState: StateFactory(sliceName, options.initialState || {}),
67
67
  reducers: {
68
68
  clearData: (state) => {
69
69
  state[sliceName] = null;
@@ -116,7 +116,7 @@ const FeatureFactory = (sliceName, endpoint, options = {}) => {
116
116
  return {
117
117
  reducer: slice.reducer,
118
118
  actions: slice.actions,
119
- instance: apiInstance,
119
+ instance: API,
120
120
  asyncActions: {
121
121
  fetch,
122
122
  fetchOne,