-
Notifications
You must be signed in to change notification settings - Fork 685
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into tommy/lighthouse-render-time
- Loading branch information
Showing
57 changed files
with
1,150 additions
and
241 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { extraArgument } from '../store/middleware/thunk'; | ||
|
||
const attachClientToStore = apolloClient => { | ||
Object.assign(extraArgument, { apolloClient }); | ||
}; | ||
|
||
export default attachClientToStore; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import BrowserPersistence from '../../util/simplePersistence'; | ||
import userActions, { signOut } from '../actions/user'; | ||
|
||
const timeouts = new Map(); | ||
const intervals = new Map(); | ||
const storage = new BrowserPersistence(); | ||
const SET_TOKEN = userActions.setToken.toString(); | ||
const CLEAR_TOKEN = userActions.clearToken.toString(); | ||
const GET_DETAILS = userActions.getDetails.request.toString(); | ||
|
||
const isSigningIn = type => type === SET_TOKEN || type === GET_DETAILS; | ||
const isSigningOut = type => type === CLEAR_TOKEN; | ||
|
||
/** | ||
* This function adheres to Redux's middleware pattern. | ||
* | ||
* @param {Store} store The store to augment. | ||
* @returns {Function} | ||
*/ | ||
const scheduleSignOut = store => next => action => { | ||
const { dispatch } = store; | ||
|
||
if (isSigningIn(action.type)) { | ||
// `BrowserPersistence.getItem()` only returns the value | ||
// but we need the full item with timestamp and ttl | ||
const item = storage.getRawItem('signin_token'); | ||
|
||
// exit if there's nothing in storage | ||
if (!item) return next(action); | ||
|
||
const { timeStored, ttl, value } = JSON.parse(item); | ||
const parsedValue = JSON.parse(value); | ||
const preciseTTL = ttl * 1000; | ||
const elapsed = Date.now() - timeStored; | ||
const expiry = Math.max(preciseTTL - elapsed, 0); | ||
|
||
// establish a sign-out routine | ||
const callback = () => { | ||
dispatch(signOut()).then(() => { | ||
timeouts.delete(parsedValue); | ||
intervals.delete(parsedValue); | ||
|
||
// refresh the page, important for checkout | ||
history.go(0); | ||
}); | ||
}; | ||
|
||
// set a timeout that runs once when the token expires | ||
if (!timeouts.has(parsedValue)) { | ||
const timeoutId = setTimeout(callback, expiry); | ||
|
||
timeouts.set(parsedValue, timeoutId); | ||
} | ||
|
||
// then set an interval that runs once per second | ||
// on mobile, the timeout won't fire if the tab is inactive | ||
if (!intervals.has(parsedValue)) { | ||
const intervalId = setInterval(() => { | ||
const hasExpired = Date.now() - timeStored > preciseTTL; | ||
|
||
if (hasExpired) callback(); | ||
}, 1000); | ||
|
||
intervals.set(parsedValue, intervalId); | ||
} | ||
} else if (isSigningOut(action.type)) { | ||
for (const timeoutId of timeouts) { | ||
clearTimeout(timeoutId); | ||
} | ||
|
||
for (const intervalId of intervals) { | ||
clearInterval(intervalId); | ||
} | ||
|
||
timeouts.clear(); | ||
intervals.clear(); | ||
} | ||
|
||
return next(action); | ||
}; | ||
|
||
export default scheduleSignOut; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import thunk from 'redux-thunk'; | ||
|
||
export const extraArgument = {}; | ||
export default thunk.withExtraArgument(extraArgument); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
...egrine/lib/talons/CartPage/ProductListing/__tests__/__snapshots__/useProduct.spec.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`it returns the proper shape 1`] = ` | ||
<i | ||
talonProps={ | ||
Object { | ||
"errorMessage": "", | ||
"handleEditItem": [Function], | ||
"handleRemoveFromCart": [Function], | ||
"handleToggleFavorites": [Function], | ||
"handleUpdateItemQuantity": [Function], | ||
"isEditable": false, | ||
"isFavorite": false, | ||
"product": Object { | ||
"currency": "USD", | ||
"image": "test.webp", | ||
"name": "unit test", | ||
"options": Array [], | ||
"quantity": 7, | ||
"stockStatus": undefined, | ||
"unitPrice": 99, | ||
"urlKey": undefined, | ||
"urlSuffix": undefined, | ||
}, | ||
} | ||
} | ||
/> | ||
`; | ||
|
||
exports[`it returns the proper shape when use variant image is configured 1`] = ` | ||
<i | ||
talonProps={ | ||
Object { | ||
"errorMessage": "", | ||
"handleEditItem": [Function], | ||
"handleRemoveFromCart": [Function], | ||
"handleToggleFavorites": [Function], | ||
"handleUpdateItemQuantity": [Function], | ||
"isEditable": true, | ||
"isFavorite": false, | ||
"product": Object { | ||
"currency": "USD", | ||
"image": "variant1.webp", | ||
"name": "unit test", | ||
"options": Array [ | ||
Object { | ||
"id": 22, | ||
"option_label": "Color", | ||
"value_id": 2, | ||
"value_label": "red", | ||
}, | ||
], | ||
"quantity": 7, | ||
"stockStatus": undefined, | ||
"unitPrice": 99, | ||
"urlKey": undefined, | ||
"urlSuffix": undefined, | ||
}, | ||
} | ||
} | ||
/> | ||
`; |
Oops, something went wrong.