@ordergroove/offers 2.26.2 → 2.26.3-alpha-PR-593-11.14
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/build.js +3 -1
- package/dist/bundle-report.html +174 -103
- package/dist/offers.js +63 -74
- package/dist/offers.js.map +3 -3
- package/examples/cart.js +105 -0
- package/examples/index.html +2 -2
- package/examples/products/cheap-watch.js +183 -0
- package/examples/shopify-cart.html +26 -0
- package/examples/shopify-pdp.html +34 -0
- package/karma.conf.js +2 -1
- package/package.json +4 -4
- package/src/__tests__/offers.spec.js +32 -2
- package/src/components/FrequencyStatus.js +14 -11
- package/src/components/Offer.js +11 -7
- package/src/components/OptinButton.js +1 -1
- package/src/components/OptinSelect.js +2 -2
- package/src/components/OptinToggle.js +2 -2
- package/src/components/OptoutButton.js +1 -1
- package/src/components/Price.js +3 -3
- package/src/components/Select.js +3 -13
- package/src/components/SelectFrequency.js +23 -5
- package/src/components/__tests__/OG.fspec.js +24 -0
- package/src/components/__tests__/Offer.spec.js +4 -4
- package/src/components/__tests__/OptinButton.spec.js +2 -2
- package/src/components/__tests__/OptinToggle.spec.js +2 -2
- package/src/components/__tests__/OptoutButton.spec.js +1 -1
- package/src/components/__tests__/SelectFrequency.fspec.js +1 -0
- package/src/components/__tests__/SelectFrequency.spec.js +1 -1
- package/src/components/__tests__/TestWizard.spec.js +2 -2
- package/src/core/__tests__/actions.spec.js +6 -6
- package/src/core/actions.js +10 -10
- package/src/core/constants.js +2 -0
- package/src/core/reducer.js +15 -14
- package/src/core/resolveProperties.js +2 -7
- package/src/core/selectors.js +1 -1
- package/src/core/store.js +6 -5
- package/src/index.js +44 -206
- package/src/make-api.js +187 -0
- package/src/shopify/__tests__/shopifyReducer.spec.js +477 -0
- package/src/shopify/getProduct.ts +6 -0
- package/src/shopify/guessProductHandle.ts +26 -0
- package/src/shopify/shopifyMiddleware.ts +137 -0
- package/src/shopify/shopifyReducer.js +199 -0
- package/tsconfig.json +35 -0
- package/examples/5starnutrition-main.js +0 -3
- package/examples/single-offer.html +0 -9
- package/src/init-test.js +0 -3
|
@@ -50,10 +50,13 @@ export class SelectFrequency extends withChildOptions(FrequencyStatus) {
|
|
|
50
50
|
|
|
51
51
|
// default frequency comes from redux store first, then default option value, and then finally attribute value.
|
|
52
52
|
get defaultFrequency() {
|
|
53
|
-
|
|
53
|
+
if (this.configDefaultFrequency) {
|
|
54
|
+
return this.configDefaultFrequency;
|
|
55
|
+
}
|
|
54
56
|
if (this.productDefaultFrequency) {
|
|
55
57
|
return this.productDefaultFrequency;
|
|
56
58
|
}
|
|
59
|
+
const { options, isSelected } = this.childOptions;
|
|
57
60
|
if (isSelected) {
|
|
58
61
|
return isSelected;
|
|
59
62
|
}
|
|
@@ -64,6 +67,9 @@ export class SelectFrequency extends withChildOptions(FrequencyStatus) {
|
|
|
64
67
|
}
|
|
65
68
|
|
|
66
69
|
get currentFrequency() {
|
|
70
|
+
if (this.frequency) {
|
|
71
|
+
return this.frequency;
|
|
72
|
+
}
|
|
67
73
|
return this.frequency || this.defaultFrequency;
|
|
68
74
|
}
|
|
69
75
|
|
|
@@ -72,7 +78,20 @@ export class SelectFrequency extends withChildOptions(FrequencyStatus) {
|
|
|
72
78
|
}
|
|
73
79
|
|
|
74
80
|
render() {
|
|
75
|
-
let
|
|
81
|
+
let options;
|
|
82
|
+
|
|
83
|
+
if (this.frequencies?.length) {
|
|
84
|
+
options = this.frequencies.map((value, ix) => ({
|
|
85
|
+
value,
|
|
86
|
+
text:
|
|
87
|
+
this.frequenciesText && ix in this.frequenciesText
|
|
88
|
+
? this.frequenciesText[ix]
|
|
89
|
+
: frequencyText(value, this.defaultFrequency)
|
|
90
|
+
}));
|
|
91
|
+
} else {
|
|
92
|
+
({ options } = this.childOptions);
|
|
93
|
+
}
|
|
94
|
+
|
|
76
95
|
if (!options.length) {
|
|
77
96
|
options = (this.frequencies || []).map(value => ({
|
|
78
97
|
value,
|
|
@@ -82,16 +101,15 @@ export class SelectFrequency extends withChildOptions(FrequencyStatus) {
|
|
|
82
101
|
const defaultFrequency = this.defaultFrequency;
|
|
83
102
|
|
|
84
103
|
options = options.map(({ text, value }) => ({
|
|
85
|
-
text: value === defaultFrequency ? `${text} ${(this.defaultText || '').trim()}
|
|
104
|
+
text: value === defaultFrequency ? `${text} ${(this.defaultText || '').trim()}` : text,
|
|
86
105
|
value
|
|
87
106
|
}));
|
|
88
|
-
|
|
89
107
|
return html`
|
|
90
108
|
<og-select
|
|
91
109
|
.options="${options}"
|
|
92
110
|
.selected="${this.currentFrequency}"
|
|
93
111
|
.onChange="${({ target: { value } }) => {
|
|
94
|
-
this.productChangeFrequency(this.product, value);
|
|
112
|
+
this.productChangeFrequency(this.product, value, this.offer);
|
|
95
113
|
}}"
|
|
96
114
|
></og-select>
|
|
97
115
|
`;
|
|
@@ -8,4 +8,28 @@ describe('og.offers', function() {
|
|
|
8
8
|
it('should define register() method', () => {
|
|
9
9
|
expect(og.offers.register).toEqual(jasmine.any(Function));
|
|
10
10
|
});
|
|
11
|
+
|
|
12
|
+
const api = jasmine.objectContaining({
|
|
13
|
+
store: jasmine.any(Object),
|
|
14
|
+
addOptinChangedCallback: jasmine.any(Function),
|
|
15
|
+
addTemplate: jasmine.any(Function),
|
|
16
|
+
clear: jasmine.any(Function),
|
|
17
|
+
config: jasmine.any(Function),
|
|
18
|
+
disableOptinChangedCallbacks: jasmine.any(Function),
|
|
19
|
+
getOptins: jasmine.any(Function),
|
|
20
|
+
getProductsForPurchasePost: jasmine.any(Function),
|
|
21
|
+
initialize: jasmine.any(Function),
|
|
22
|
+
previewMode: jasmine.any(Function),
|
|
23
|
+
register: jasmine.any(Function),
|
|
24
|
+
resolveSettings: jasmine.any(Function),
|
|
25
|
+
setAuthUrl: jasmine.any(Function),
|
|
26
|
+
setEnvironment: jasmine.any(Function),
|
|
27
|
+
setLocale: jasmine.any(Function),
|
|
28
|
+
setMerchantId: jasmine.any(Function),
|
|
29
|
+
setPublicPath: jasmine.any(Function),
|
|
30
|
+
setTemplates: jasmine.any(Function)
|
|
31
|
+
});
|
|
32
|
+
it('imported ', () => {
|
|
33
|
+
expect(og.offers).toEqual(api);
|
|
34
|
+
});
|
|
11
35
|
});
|
|
@@ -22,7 +22,7 @@ describe('Offer', function() {
|
|
|
22
22
|
expect(this.underTest.fetchOffer).not.toHaveBeenCalledWith();
|
|
23
23
|
this.underTest.setAttribute('product', 'yum product');
|
|
24
24
|
await this.underTest.updateComplete;
|
|
25
|
-
expect(this.underTest.fetchOffer).toHaveBeenCalledWith('yum product');
|
|
25
|
+
expect(this.underTest.fetchOffer).toHaveBeenCalledWith('yum product', 'pdp', this.underTest);
|
|
26
26
|
});
|
|
27
27
|
|
|
28
28
|
it('should not call dispatch given product attribute has not changed', async function() {
|
|
@@ -125,7 +125,7 @@ describe('Offer', function() {
|
|
|
125
125
|
el.location = 'cart';
|
|
126
126
|
el.product = { id: 'yum id' };
|
|
127
127
|
await appendToBody(el);
|
|
128
|
-
expect(el.optinProduct).toHaveBeenCalledWith({ id: 'yum id' }, '1_1');
|
|
128
|
+
expect(el.optinProduct).toHaveBeenCalledWith({ id: 'yum id' }, '1_1', el);
|
|
129
129
|
});
|
|
130
130
|
|
|
131
131
|
it('should not optin by default on location=cart when optin exists', async () => {
|
|
@@ -165,7 +165,7 @@ describe('Offer', function() {
|
|
|
165
165
|
el.product = { id: 'yum id' };
|
|
166
166
|
el.productComponents = ['a', 'b'];
|
|
167
167
|
await appendToBody(el);
|
|
168
|
-
expect(el.optinProduct).toHaveBeenCalledWith({ id: 'yum id', components: ['a', 'b'] }, '1_1');
|
|
168
|
+
expect(el.optinProduct).toHaveBeenCalledWith({ id: 'yum id', components: ['a', 'b'] }, '1_1', el);
|
|
169
169
|
});
|
|
170
170
|
|
|
171
171
|
it('should optin withithout components given offer is autoship eligible, offer does not have product components, and location is cart', async () => {
|
|
@@ -178,7 +178,7 @@ describe('Offer', function() {
|
|
|
178
178
|
el.location = 'cart';
|
|
179
179
|
el.product = { id: 'yum id' };
|
|
180
180
|
await appendToBody(el);
|
|
181
|
-
expect(el.optinProduct).toHaveBeenCalledWith({ id: 'yum id' }, '1_1');
|
|
181
|
+
expect(el.optinProduct).toHaveBeenCalledWith({ id: 'yum id' }, '1_1', el);
|
|
182
182
|
});
|
|
183
183
|
});
|
|
184
184
|
});
|
|
@@ -30,7 +30,7 @@ describe('OptinButton', function() {
|
|
|
30
30
|
element.defaultFrequency = '1_1';
|
|
31
31
|
element.optinProduct = jasmine.createSpy('optinProduct');
|
|
32
32
|
await simulateClick(element, 'button');
|
|
33
|
-
expect(element.optinProduct).toHaveBeenCalledWith({ id: '123' }, '1_1');
|
|
33
|
+
expect(element.optinProduct).toHaveBeenCalledWith({ id: '123' }, '1_1', undefined);
|
|
34
34
|
});
|
|
35
35
|
|
|
36
36
|
it('should dispatch optinProduct(product, someFreq) action on click', async () => {
|
|
@@ -39,7 +39,7 @@ describe('OptinButton', function() {
|
|
|
39
39
|
element.defaultFrequency = 'custom 2.2';
|
|
40
40
|
element.optinProduct = jasmine.createSpy('optinProduct');
|
|
41
41
|
await simulateClick(element, 'button');
|
|
42
|
-
expect(element.optinProduct).toHaveBeenCalledWith({ id: '123' }, 'custom 2.2');
|
|
42
|
+
expect(element.optinProduct).toHaveBeenCalledWith({ id: '123' }, 'custom 2.2', undefined);
|
|
43
43
|
});
|
|
44
44
|
});
|
|
45
45
|
});
|
|
@@ -46,7 +46,7 @@ describe('OptinToggle', () => {
|
|
|
46
46
|
elm.setAttribute('product', 'yum product');
|
|
47
47
|
elm.setAttribute('frequency', '1_1');
|
|
48
48
|
await simulateClick(elm, 'button');
|
|
49
|
-
expect(elm.optinProduct).toHaveBeenCalledWith({ id: 'yum product' }, '1_1');
|
|
49
|
+
expect(elm.optinProduct).toHaveBeenCalledWith({ id: 'yum product' }, '1_1', undefined);
|
|
50
50
|
});
|
|
51
51
|
|
|
52
52
|
it('should optinProduct with product and set frequency', async () => {
|
|
@@ -57,6 +57,6 @@ describe('OptinToggle', () => {
|
|
|
57
57
|
elm.setAttribute('product', 'yum product');
|
|
58
58
|
elm.frequency = '3_3';
|
|
59
59
|
await simulateClick(elm, 'button');
|
|
60
|
-
expect(elm.optinProduct).toHaveBeenCalledWith({ id: 'yum product' }, '3_3');
|
|
60
|
+
expect(elm.optinProduct).toHaveBeenCalledWith({ id: 'yum product' }, '3_3', undefined);
|
|
61
61
|
});
|
|
62
62
|
});
|
|
@@ -16,7 +16,7 @@ describe('OptoutButton', () => {
|
|
|
16
16
|
elm.setAttribute('product', 'foo');
|
|
17
17
|
elm.optoutProduct = jasmine.createSpy('optoutProduct');
|
|
18
18
|
await simulateClick(elm, 'button');
|
|
19
|
-
expect(elm.optoutProduct).toHaveBeenCalledWith({ id: 'foo' });
|
|
19
|
+
expect(elm.optoutProduct).toHaveBeenCalledWith({ id: 'foo' }, undefined);
|
|
20
20
|
});
|
|
21
21
|
|
|
22
22
|
it('should have empty label if subscribed', async () => {
|
|
@@ -22,6 +22,7 @@ describe('Select Frequency', function() {
|
|
|
22
22
|
`;
|
|
23
23
|
element = document.querySelector('og-select-frequency');
|
|
24
24
|
await element.updateComplete;
|
|
25
|
+
await new Promise(r => setTimeout(r, 1000));
|
|
25
26
|
});
|
|
26
27
|
|
|
27
28
|
it('it should have default frequency as value', async () => {
|
|
@@ -10,7 +10,7 @@ describe('SelectFrequency', () => {
|
|
|
10
10
|
selectFrequency.productChangeFrequency = jasmine.createSpy('productChangeFrequency');
|
|
11
11
|
selectFrequency.setAttribute('product', 'yum product');
|
|
12
12
|
await simulateChange(selectFrequency, '2_1');
|
|
13
|
-
expect(selectFrequency.productChangeFrequency).toHaveBeenCalledWith({ id: 'yum product' }, '2_1');
|
|
13
|
+
expect(selectFrequency.productChangeFrequency).toHaveBeenCalledWith({ id: 'yum product' }, '2_1', undefined);
|
|
14
14
|
});
|
|
15
15
|
|
|
16
16
|
it('should append default-text to selected frequency', async () => {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { TestWizard } from '../TestWizard';
|
|
2
2
|
import { simulateClick } from './utils';
|
|
3
|
-
import {
|
|
3
|
+
import { makeStore } from '../../core/store';
|
|
4
4
|
|
|
5
5
|
customElements.define('og-test-wizard', TestWizard);
|
|
6
6
|
|
|
7
7
|
describe('TestWizard', () => {
|
|
8
|
-
const store =
|
|
8
|
+
const store = makeStore();
|
|
9
9
|
it('should run the tests when the button is clicked', async () => {
|
|
10
10
|
const testWizard = new TestWizard();
|
|
11
11
|
testWizard.runTests = jasmine.createSpy('runTests');
|
|
@@ -55,29 +55,29 @@ describe('redux actions', function() {
|
|
|
55
55
|
it('optinProduct should return payload', () => {
|
|
56
56
|
expect(optinProduct('foo', '1_2')).toEqual({
|
|
57
57
|
type: 'OPTIN_PRODUCT',
|
|
58
|
-
payload: {
|
|
58
|
+
payload: jasmine.objectContaining({
|
|
59
59
|
product: 'foo',
|
|
60
60
|
frequency: '1_2'
|
|
61
|
-
}
|
|
61
|
+
})
|
|
62
62
|
});
|
|
63
63
|
});
|
|
64
64
|
|
|
65
65
|
it('optoutProduct should return payload', () => {
|
|
66
66
|
expect(optoutProduct('foo')).toEqual({
|
|
67
67
|
type: 'OPTOUT_PRODUCT',
|
|
68
|
-
payload: {
|
|
68
|
+
payload: jasmine.objectContaining({
|
|
69
69
|
product: 'foo'
|
|
70
|
-
}
|
|
70
|
+
})
|
|
71
71
|
});
|
|
72
72
|
});
|
|
73
73
|
|
|
74
74
|
it('productChangeFrequency should return payload', () => {
|
|
75
75
|
expect(productChangeFrequency('foo', 'freq')).toEqual({
|
|
76
76
|
type: 'PRODUCT_CHANGE_FREQUENCY',
|
|
77
|
-
payload: {
|
|
77
|
+
payload: jasmine.objectContaining({
|
|
78
78
|
product: 'foo',
|
|
79
79
|
frequency: 'freq'
|
|
80
|
-
}
|
|
80
|
+
})
|
|
81
81
|
});
|
|
82
82
|
});
|
|
83
83
|
|
package/src/core/actions.js
CHANGED
|
@@ -2,14 +2,14 @@ import { resolveAuth } from '@ordergroove/auth';
|
|
|
2
2
|
import * as constants from './constants';
|
|
3
3
|
import { api } from './api';
|
|
4
4
|
|
|
5
|
-
export const optinProduct = (product, frequency) => ({
|
|
5
|
+
export const optinProduct = (product, frequency, offer) => ({
|
|
6
6
|
type: constants.OPTIN_PRODUCT,
|
|
7
|
-
payload: { product, frequency }
|
|
7
|
+
payload: { product, frequency, offer }
|
|
8
8
|
});
|
|
9
9
|
|
|
10
|
-
export const optoutProduct = product => ({
|
|
10
|
+
export const optoutProduct = (product, offer) => ({
|
|
11
11
|
type: constants.OPTOUT_PRODUCT,
|
|
12
|
-
payload: { product }
|
|
12
|
+
payload: { product, offer }
|
|
13
13
|
});
|
|
14
14
|
|
|
15
15
|
export const productHasChangedComponents = (newProduct, product) => ({
|
|
@@ -17,9 +17,9 @@ export const productHasChangedComponents = (newProduct, product) => ({
|
|
|
17
17
|
payload: { newProduct, product }
|
|
18
18
|
});
|
|
19
19
|
|
|
20
|
-
export const productChangeFrequency = (product, frequency) => ({
|
|
20
|
+
export const productChangeFrequency = (product, frequency, offer) => ({
|
|
21
21
|
type: constants.PRODUCT_CHANGE_FREQUENCY,
|
|
22
|
-
payload: { product, frequency }
|
|
22
|
+
payload: { product, frequency, offer }
|
|
23
23
|
});
|
|
24
24
|
|
|
25
25
|
export const concludeUpsell = product => ({
|
|
@@ -179,19 +179,19 @@ export const fetchResponseError = err => ({
|
|
|
179
179
|
payload: err
|
|
180
180
|
});
|
|
181
181
|
|
|
182
|
-
export const requestOffer = (product, module = 'pdp') => ({
|
|
182
|
+
export const requestOffer = (product, module = 'pdp', offer) => ({
|
|
183
183
|
type: constants.REQUEST_OFFER,
|
|
184
|
-
payload: { product, module }
|
|
184
|
+
payload: { product, module, offer }
|
|
185
185
|
});
|
|
186
186
|
|
|
187
|
-
export const fetchOffer = (product, module = 'pdp') =>
|
|
187
|
+
export const fetchOffer = (product, module = 'pdp', offer) =>
|
|
188
188
|
function fetchOfferThunk(dispatch, getState) {
|
|
189
189
|
const {
|
|
190
190
|
merchantId,
|
|
191
191
|
sessionId,
|
|
192
192
|
environment: { apiUrl }
|
|
193
193
|
} = getState();
|
|
194
|
-
const requestAction = requestOffer(product, module);
|
|
194
|
+
const requestAction = requestOffer(product, module, offer);
|
|
195
195
|
dispatch(requestAction);
|
|
196
196
|
return api
|
|
197
197
|
.fetchOffer(apiUrl, merchantId, sessionId, product, module)
|
package/src/core/constants.js
CHANGED
|
@@ -37,3 +37,5 @@ export const LOCAL_STORAGE_CLEAR = 'LOCAL_STORAGE_CLEAR';
|
|
|
37
37
|
export const SET_FIRST_ORDER_PLACE_DATE = 'SET_FIRST_ORDER_PLACE_DATE';
|
|
38
38
|
export const SET_PRODUCT_TO_SUBSCRIBE = 'SET_PRODUCT_TO_SUBSCRIBE';
|
|
39
39
|
export const RECEIVE_PRODUCT_PLANS = 'RECEIVE_PRODUCT_PLANS';
|
|
40
|
+
export const SETUP_PRODUCT = 'SETUP_PRODUCT';
|
|
41
|
+
export const SETUP_CART = 'SETUP_CART';
|
package/src/core/reducer.js
CHANGED
|
@@ -370,7 +370,7 @@ export const locale = (
|
|
|
370
370
|
|
|
371
371
|
export const config = (
|
|
372
372
|
state = {
|
|
373
|
-
frequencies: [
|
|
373
|
+
// frequencies: [],
|
|
374
374
|
offerType: 'radio'
|
|
375
375
|
},
|
|
376
376
|
action
|
|
@@ -454,29 +454,30 @@ export const productPlans = (state = {}, action) => {
|
|
|
454
454
|
};
|
|
455
455
|
|
|
456
456
|
export default combineReducers({
|
|
457
|
-
productPlans,
|
|
458
|
-
environment,
|
|
459
457
|
optedin,
|
|
460
458
|
optedout,
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
offerId,
|
|
464
|
-
productOffer,
|
|
465
|
-
sessionId,
|
|
459
|
+
nextUpcomingOrder,
|
|
460
|
+
autoshipEligible,
|
|
466
461
|
inStock,
|
|
467
462
|
eligibilityGroups,
|
|
468
|
-
autoshipByDefault,
|
|
469
|
-
autoshipEligible,
|
|
470
463
|
incentives,
|
|
471
|
-
|
|
464
|
+
frequency,
|
|
472
465
|
auth,
|
|
466
|
+
merchantId,
|
|
473
467
|
authUrl,
|
|
468
|
+
offer,
|
|
469
|
+
offerId,
|
|
470
|
+
sessionId,
|
|
471
|
+
productOffer,
|
|
472
|
+
firstOrderPlaceDate,
|
|
473
|
+
productToSubscribe,
|
|
474
|
+
environment,
|
|
474
475
|
locale,
|
|
475
476
|
config,
|
|
476
477
|
previewStandardOffer,
|
|
477
478
|
previewUpsellOffer,
|
|
478
|
-
|
|
479
|
+
autoshipByDefault,
|
|
479
480
|
defaultFrequencies,
|
|
480
|
-
|
|
481
|
-
|
|
481
|
+
templates,
|
|
482
|
+
productPlans
|
|
482
483
|
});
|
|
@@ -93,22 +93,17 @@ export const withProduct = Base =>
|
|
|
93
93
|
export const withChildOptions = Base =>
|
|
94
94
|
class extends Base {
|
|
95
95
|
get childOptions() {
|
|
96
|
-
return this._childOptions || { options: [] };
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
connectedCallback() {
|
|
100
96
|
const options = [];
|
|
101
97
|
let isSelected = null;
|
|
98
|
+
|
|
102
99
|
this.querySelectorAll('option').forEach(it => {
|
|
103
100
|
const value = sanitizeFrequencyString(it.value);
|
|
104
101
|
const text = it.innerText.trim();
|
|
105
102
|
options.push({ value, text });
|
|
106
|
-
|
|
107
103
|
if (!isSelected && it.selected) {
|
|
108
104
|
isSelected = value;
|
|
109
105
|
}
|
|
110
106
|
});
|
|
111
|
-
|
|
112
|
-
super.connectedCallback && super.connectedCallback();
|
|
107
|
+
return { options, isSelected };
|
|
113
108
|
}
|
|
114
109
|
};
|
package/src/core/selectors.js
CHANGED
|
@@ -133,9 +133,9 @@ export const kebabCase = string => {
|
|
|
133
133
|
*/
|
|
134
134
|
export const configSelector = (state, element, key, defaultValue) => ({
|
|
135
135
|
[key]:
|
|
136
|
+
(state.config && state.config[key]) ||
|
|
136
137
|
(element && element.hasAttribute && element.hasAttribute(kebabCase(key)) && element[key]) ||
|
|
137
138
|
(element.offer && typeof (element.offer[key] !== 'undefined') && element.offer[key]) ||
|
|
138
|
-
(state.config && state.config[key]) ||
|
|
139
139
|
defaultValue
|
|
140
140
|
});
|
|
141
141
|
|
package/src/core/store.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { createStore, compose, applyMiddleware } from 'redux';
|
|
2
2
|
import thunk from 'redux-thunk';
|
|
3
|
-
|
|
4
|
-
import { loadState
|
|
3
|
+
|
|
4
|
+
import { loadState } from './localStorage';
|
|
5
5
|
import { dispatchMiddleware, localStorageMiddleware } from './middleware';
|
|
6
6
|
|
|
7
|
-
export function
|
|
7
|
+
export function makeStore(reducer, ...extraMiddlewares) {
|
|
8
8
|
if (window.og && window.og.store) return window.og.store;
|
|
9
9
|
|
|
10
10
|
const isPreviewMode = window.og && window.og.previewMode;
|
|
@@ -19,11 +19,12 @@ export function getStore() {
|
|
|
19
19
|
: compose;
|
|
20
20
|
|
|
21
21
|
const middlewares = [thunk, dispatchMiddleware];
|
|
22
|
+
|
|
22
23
|
if (!isPreviewMode) {
|
|
23
24
|
middlewares.push(localStorageMiddleware);
|
|
24
25
|
}
|
|
25
26
|
|
|
26
|
-
const enhancer = composeEnhancers(applyMiddleware(...middlewares));
|
|
27
|
+
const enhancer = composeEnhancers(applyMiddleware(...middlewares, ...extraMiddlewares));
|
|
27
28
|
const store = createStore(reducer, isPreviewMode ? {} : loadState(), enhancer);
|
|
28
29
|
|
|
29
30
|
window.og = window.og || {};
|
|
@@ -31,4 +32,4 @@ export function getStore() {
|
|
|
31
32
|
return store;
|
|
32
33
|
}
|
|
33
34
|
|
|
34
|
-
export default
|
|
35
|
+
export default makeStore;
|