Skip to content

Commit 833de89

Browse files
Merge pull request #65 from marsimeau/fix-default-state-reactivity
Fix default state reactivity
2 parents 8a6b91d + 16601a4 commit 833de89

File tree

10 files changed

+87
-85
lines changed

10 files changed

+87
-85
lines changed

src/auth-module/mutations.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,20 @@ export default function makeAuthMutations (feathers) {
2727
state.errorOnAuthenticate = Object.assign({}, error)
2828
},
2929
clearAuthenticateError (state) {
30-
state.errorOnAuthenticate = undefined
30+
state.errorOnAuthenticate = null
3131
},
3232
setLogoutError (state, error) {
3333
state.errorOnLogout = Object.assign({}, error)
3434
},
3535
clearLogoutError (state) {
36-
state.errorOnLogout = undefined
36+
state.errorOnLogout = null
3737
},
3838

3939
logout (state) {
40-
state.payload = undefined
41-
state.accessToken = undefined
40+
state.payload = null
41+
state.accessToken = null
4242
if (state.user) {
43-
state.user = undefined
43+
state.user = null
4444
}
4545
}
4646
}

src/auth-module/state.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
export default function setupAuthState ({ userService }) {
22
const state = {
3-
accessToken: undefined, // The JWT
4-
payload: undefined, // The JWT payload
3+
accessToken: null, // The JWT
4+
payload: null, // The JWT payload
55

66
isAuthenticatePending: false,
77
isLogoutPending: false,
88

9-
errorOnAuthenticate: undefined,
10-
errorOnLogout: undefined
9+
errorOnAuthenticate: null,
10+
errorOnLogout: null,
11+
user: null
1112
}
1213
// If a userService string was passed, add a user attribute
1314
if (userService) {
14-
Object.assign(state, { userService, user: undefined })
15+
Object.assign(state, { userService })
1516
}
1617
return state
1718
}

src/service-module/mutations.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ export default function makeServiceMutations (servicePath) {
6060
state.keyedById = keyedById
6161

6262
if (currentId === idToBeRemoved) {
63-
state.currentId = undefined
64-
state.copy = undefined
63+
state.currentId = null
64+
state.copy = null
6565
}
6666
},
6767

@@ -100,15 +100,15 @@ export default function makeServiceMutations (servicePath) {
100100
state.keyedById = keyedById
101101

102102
if (currentId && mapOfIdsToRemove[currentId]) {
103-
state.currentId = undefined
104-
state.copy = undefined
103+
state.currentId = null
104+
state.copy = null
105105
}
106106
},
107107

108108
clearAll (state) {
109109
state.ids = []
110-
state.currentId = undefined
111-
state.copy = undefined
110+
state.currentId = null
111+
state.copy = null
112112
state.keyedById = {}
113113
},
114114

@@ -143,8 +143,8 @@ export default function makeServiceMutations (servicePath) {
143143
},
144144

145145
clearCurrent (state) {
146-
state.currentId = undefined
147-
state.copy = undefined
146+
state.currentId = null
147+
state.copy = null
148148
},
149149

150150
// Deep assigns current to copy
@@ -211,37 +211,37 @@ export default function makeServiceMutations (servicePath) {
211211
state.errorOnFind = Object.assign({}, serializeError(payload))
212212
},
213213
clearFindError (state) {
214-
state.errorOnFind = undefined
214+
state.errorOnFind = null
215215
},
216216
setGetError (state, payload) {
217217
state.errorOnGet = Object.assign({}, serializeError(payload))
218218
},
219219
clearGetError (state) {
220-
state.errorOnGet = undefined
220+
state.errorOnGet = null
221221
},
222222
setCreateError (state, payload) {
223223
state.errorOnCreate = Object.assign({}, serializeError(payload))
224224
},
225225
clearCreateError (state) {
226-
state.errorOnCreate = undefined
226+
state.errorOnCreate = null
227227
},
228228
setUpdateError (state, payload) {
229229
state.errorOnUpdate = Object.assign({}, serializeError(payload))
230230
},
231231
clearUpdateError (state) {
232-
state.errorOnUpdate = undefined
232+
state.errorOnUpdate = null
233233
},
234234
setPatchError (state, payload) {
235235
state.errorOnPatch = Object.assign({}, serializeError(payload))
236236
},
237237
clearPatchError (state) {
238-
state.errorOnPatch = undefined
238+
state.errorOnPatch = null
239239
},
240240
setRemoveError (state, payload) {
241241
state.errorOnRemove = Object.assign({}, serializeError(payload))
242242
},
243243
clearRemoveError (state) {
244-
state.errorOnRemove = undefined
244+
state.errorOnRemove = null
245245
}
246246
}
247247
}

src/service-module/state.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ export default function makeDefaultState (servicePath, { idField, autoRemove, pa
22
const state = {
33
ids: [],
44
keyedById: {},
5-
currentId: undefined,
6-
copy: undefined,
5+
currentId: null,
6+
copy: null,
77
idField,
88
servicePath,
99
autoRemove,
@@ -16,12 +16,12 @@ export default function makeDefaultState (servicePath, { idField, autoRemove, pa
1616
isPatchPending: false,
1717
isRemovePending: false,
1818

19-
errorOnFind: undefined,
20-
errorOnGet: undefined,
21-
errorOnCreate: undefined,
22-
errorOnUpdate: undefined,
23-
errorOnPatch: undefined,
24-
errorOnRemove: undefined
19+
errorOnFind: null,
20+
errorOnGet: null,
21+
errorOnCreate: null,
22+
errorOnUpdate: null,
23+
errorOnPatch: null,
24+
errorOnRemove: null
2525
}
2626
return state
2727
}

test/auth-module/actions.test.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,19 @@ describe('Auth Module - Actions', () => {
2323
const authState = store.state.auth
2424
const actions = mapActions('auth', ['authenticate'])
2525

26-
assert(authState.accessToken === undefined)
27-
assert(authState.errorOnAuthenticate === undefined)
28-
assert(authState.errorOnLogout === undefined)
26+
assert(authState.accessToken === null)
27+
assert(authState.errorOnAuthenticate === null)
28+
assert(authState.errorOnLogout === null)
2929
assert(authState.isAuthenticatePending === false)
3030
assert(authState.isLogoutPending === false)
31-
assert(authState.payload === undefined)
31+
assert(authState.payload === null)
3232

3333
const request = {strategy: 'local', email: 'test', password: 'test'}
3434
actions.authenticate.call({$store: store}, request)
3535
.then(response => {
3636
assert(authState.accessToken === response.accessToken)
37-
assert(authState.errorOnAuthenticate === undefined)
38-
assert(authState.errorOnLogout === undefined)
37+
assert(authState.errorOnAuthenticate === null)
38+
assert(authState.errorOnLogout === null)
3939
assert(authState.isAuthenticatePending === false)
4040
assert(authState.isLogoutPending === false)
4141
let expectedPayload = {
@@ -47,12 +47,12 @@ describe('Auth Module - Actions', () => {
4747
})
4848

4949
// Make sure proper state changes occurred before response
50-
assert(authState.accessToken === undefined)
51-
assert(authState.errorOnAuthenticate === undefined)
52-
assert(authState.errorOnLogout === undefined)
50+
assert(authState.accessToken === null)
51+
assert(authState.errorOnAuthenticate === null)
52+
assert(authState.errorOnLogout === null)
5353
assert(authState.isAuthenticatePending === true)
5454
assert(authState.isLogoutPending === false)
55-
assert(authState.payload === undefined)
55+
assert(authState.payload === null)
5656
})
5757

5858
it('Logout', (done) => {
@@ -73,12 +73,12 @@ describe('Auth Module - Actions', () => {
7373
.then(authResponse => {
7474
actions.logout.call({$store: store})
7575
.then(response => {
76-
assert(authState.accessToken === undefined)
77-
assert(authState.errorOnAuthenticate === undefined)
78-
assert(authState.errorOnLogout === undefined)
76+
assert(authState.accessToken === null)
77+
assert(authState.errorOnAuthenticate === null)
78+
assert(authState.errorOnLogout === null)
7979
assert(authState.isAuthenticatePending === false)
8080
assert(authState.isLogoutPending === false)
81-
assert(authState.payload === undefined)
81+
assert(authState.payload === null)
8282
done()
8383
})
8484
})
@@ -101,7 +101,7 @@ describe('Auth Module - Actions', () => {
101101
const authState = store.state.auth
102102
const actions = mapActions('auth', ['authenticate'])
103103

104-
assert(authState.user === undefined)
104+
assert(authState.user === null)
105105

106106
const request = {strategy: 'local', email: 'test', password: 'test'}
107107
actions.authenticate.call({$store: store}, request)

test/auth-module/auth-module.test.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@ describe('Auth Module', () => {
1515
})
1616
const authState = store.state.auth
1717
const expectedAuthState = {
18-
accessToken: undefined,
19-
errorOnAuthenticate: undefined,
20-
errorOnLogout: undefined,
18+
accessToken: null,
19+
errorOnAuthenticate: null,
20+
errorOnLogout: null,
2121
isAuthenticatePending: false,
2222
isLogoutPending: false,
23-
payload: undefined
23+
payload: null,
24+
user: null
2425
}
2526

2627
assert.deepEqual(authState, expectedAuthState, 'has the default state')

test/auth.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ describe('feathers-vuex:auth - Reducer', () => {
8888
isPending: false,
8989
isError: false,
9090
isSignedIn: false,
91-
accessToken: undefined,
91+
accessToken: null,
9292
error: undefined
9393
}
9494
const newState = reducer(state, {})
@@ -108,7 +108,7 @@ describe('feathers-vuex:auth - Reducer', () => {
108108
isPending: true,
109109
isError: false,
110110
isSignedIn: false,
111-
accessToken: undefined,
111+
accessToken: null,
112112
error: undefined
113113
}
114114
const newState = reducer(state, action)
@@ -144,7 +144,7 @@ describe('feathers-vuex:auth - Reducer', () => {
144144
isPending: false,
145145
isError: true,
146146
isSignedIn: false,
147-
accessToken: undefined,
147+
accessToken: null,
148148
error
149149
}
150150
const newState = reducer(state, action)
@@ -160,7 +160,7 @@ describe('feathers-vuex:auth - Reducer', () => {
160160
isPending: false,
161161
isError: false,
162162
isSignedIn: false,
163-
accessToken: undefined,
163+
accessToken: null,
164164
error: undefined
165165
}
166166
const newState = reducer(state, action)

0 commit comments

Comments
 (0)