Skip to content

Commit 24a7ad1

Browse files
Bugfix/only merge targeting (#88)
* [SB] Prevent leaking of variables between ads * [SB] Prep for release
1 parent e2c70c3 commit 24a7ad1

4 files changed

Lines changed: 32 additions & 28 deletions

File tree

docs/error.md

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,14 @@ Example:
3939
```
4040

4141
## Error 3
42-
Description: Sizes must be of type `Array` unless breakpoints have been specified
42+
Description: Sizes are required
4343

4444

4545
## Error 4
46+
Description: Sizes must be of type `Array` unless breakpoints have been specified
47+
48+
49+
## Error 5
4650
Description: An ad must be passed into the GenericPlugin class. If your Plugin inherits from GenericPlugin
4751
and overrides the constructor make sure you are calling "super" and that you are passing in an
4852
instance of an ad as the first parameter. Alternatively, you can hook into the onCreate method
@@ -69,19 +73,19 @@ Description: An ad must be passed into the GenericPlugin class. If your Plugin i
6973
}
7074
```
7175

72-
## Error 5
73-
Description: Parent element required for sticky plugin.
74-
75-
7676
## Error 6
77-
Description: Ad does not have an id
77+
Description: Parent element required for sticky plugin.
7878

7979

80-
## Error 7
80+
## Error 8
8181
Description: Sizes must be defined.
8282

8383

84-
## Error 8
84+
## Error 9
8585
Description: Ad Path must be defined.
8686

87+
88+
## Error 7
89+
Description: Ad does not have an id
90+
8791

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "adjs",
3-
"version": "2.0.0-beta.16",
3+
"version": "2.0.0-beta.17",
44
"description": "Ad Library to simplify and optimize integration with ad networks such as DFP",
55
"main": "./core.js",
66
"types": "./types.d.ts",

src/Ad.ts

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -183,20 +183,16 @@ class Ad implements IAd {
183183
*/
184184
this.promiseStack = this.promiseStack.then(() => this.page.promiseStack);
185185

186-
this.configuration = this.page.defaults;
187-
188-
if (localConfiguration) {
189-
Object.entries(localConfiguration).forEach(([key, value]) => {
190-
if (typeof value === 'object') {
191-
this.configuration[key] = {
192-
...this.configuration[key],
193-
...value,
194-
};
195-
} else {
196-
this.configuration[key] = value;
197-
}
198-
});
199-
}
186+
this.configuration = {
187+
...this.page.defaults,
188+
...localConfiguration,
189+
190+
// Targeting is the only value that should merge
191+
targeting: {
192+
...(this.page.defaults && this.page.defaults.targeting),
193+
...(localConfiguration && localConfiguration.targeting),
194+
},
195+
};
200196

201197
this.id = nextId();
202198
this.container = insertElement('div', { style: 'position: relative;' }, el);

tests/ad.test.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,33 @@ describe('Ad', () => {
99

1010
beforeEach(() => {
1111
global.AdJS = AdJS;
12-
page = new AdJS.Page(MockNetwork);
12+
page = new AdJS.Page(MockNetwork, {
13+
defaults: {
14+
targeting: { existing: true }
15+
}
16+
});
1317

14-
ad = page.createAd(el, { sizes: [], breakpoints: {}, targeting: { existing: true } });
18+
ad = page.createAd(el, { sizes: [], breakpoints: {} });
1519
});
1620

1721
describe('configuration', () => {
1822
it('should have the correct key vals', async () => {
1923
const overrides = {
2024
someNewKey: 'true',
25+
sizes: [],
2126
targeting: {
2227
newValues: 'moreTrue',
2328
},
2429
};
2530

2631
const expected = {
27-
sizes: {},
28-
breakpoints: {},
32+
sizes: [],
2933
targeting: {
3034
existing: true,
3135
newValues: 'moreTrue'
3236
},
3337
someNewKey: 'true',
34-
}
38+
};
3539

3640
const ad = page.createAd(el, overrides);
3741
expect(ad.configuration).toEqual(expected);

0 commit comments

Comments
 (0)