Skip to content

Commit 781e72a

Browse files
Simplify set utils and add CHANGELOG entry
1 parent f82c7c6 commit 781e72a

File tree

4 files changed

+22
-17
lines changed

4 files changed

+22
-17
lines changed

.eslintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
"message": "Don't declare const enum, because it is not supported by Babel used for building RN SDK"
8181
}
8282
],
83-
"compat/compat": ["error", "defaults, node 14"],
83+
"compat/compat": ["error", "defaults, node >=14"],
8484
"no-throw-literal": "error",
8585
"import/no-default-export": "error",
8686
"import/no-self-import": "error"

CHANGES.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
- Added `factory.destroy()` method, which invokes the `destroy` method on all SDK clients created by the factory.
44
- Bugfixing - Fixed an issue with the server-side polling manager that caused dangling timers when the SDK was destroyed before it was ready.
55
- BREAKING CHANGES:
6-
- Removed the deprecated `GOOGLE_ANALYTICS_TO_SPLIT` and `SPLIT_TO_GOOGLE_ANALYTICS` integrations.
76
- Updated default flag spec version to 1.2.
87
- Removed `/mySegments` endpoint from SplitAPI module, as it is replaced by `/memberships` endpoint.
98
- Removed support for MY_SEGMENTS_UPDATE and MY_SEGMENTS_UPDATE_V2 notification types, as they are replaced by MEMBERSHIPS_MS_UPDATE and MEMBERSHIPS_LS_UPDATE notification types.
9+
- Removed the deprecated `GOOGLE_ANALYTICS_TO_SPLIT` and `SPLIT_TO_GOOGLE_ANALYTICS` integrations.
10+
- Removed internal ponyfills for `Map`, `Set` and `Array.from` global objects, dropping support for IE and other outdated browsers. The SDK now requires the runtime environment to support these features natively or to provide a polyfill.
1011

1112
1.17.0 (September 6, 2024)
1213
- Added `sync.requestOptions.getHeaderOverrides` configuration option to enhance SDK HTTP request Headers for Authorization Frameworks.
Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
1-
import { returnSetsUnion } from '../sets';
1+
import { returnSetsUnion, returnDifference } from '../sets';
22

33
test('returnSetsUnion', () => {
4-
const set = new Set(['1', '2', '3']);
5-
const set2 = new Set(['4', '5', '6']);
4+
const set = new Set(['1', '2', '3', '4']);
5+
const set2 = new Set(['4', '5', '6', '1']);
66
expect(returnSetsUnion(set, set2)).toEqual(new Set(['1', '2', '3', '4', '5', '6']));
7-
expect(set).toEqual(new Set(['1', '2', '3']));
8-
expect(set2).toEqual(new Set(['4', '5', '6']));
7+
expect(set).toEqual(new Set(['1', '2', '3', '4']));
8+
expect(set2).toEqual(new Set(['4', '5', '6', '1']));
99

1010
const emptySet = new Set([]);
1111
expect(returnSetsUnion(emptySet, emptySet)).toEqual(emptySet);
1212
expect(returnSetsUnion(set, emptySet)).toEqual(set);
1313
expect(returnSetsUnion(emptySet, set2)).toEqual(set2);
1414
});
15+
16+
test('returnDifference', () => {
17+
const list = ['1', '2', '3'];
18+
const list2 = ['2', '3', '4'];
19+
expect(returnDifference(list, list2)).toEqual(['1']);
20+
expect(list).toEqual(['1', '2', '3']);
21+
expect(list2).toEqual(['2', '3', '4']);
22+
23+
expect(returnDifference([], [])).toEqual([]);
24+
expect(returnDifference(list, [])).toEqual(list);
25+
expect(returnDifference([], list2)).toEqual([]);
26+
});

src/utils/lang/sets.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
11
export function returnSetsUnion<T>(set: Set<T>, set2: Set<T>): Set<T> {
2-
const result = new Set(Array.from(set));
3-
set2.forEach(value => {
4-
result.add(value);
5-
});
6-
return result;
2+
return new Set(Array.from(set).concat(Array.from(set2)));
73
}
84

95
export function returnDifference<T>(list: T[] = [], list2: T[] = []): T[] {
10-
const result = new Set(list);
11-
list2.forEach(item => {
12-
result.delete(item);
13-
});
14-
return Array.from(result);
6+
return list.filter(item => list2.indexOf(item) === -1);
157
}

0 commit comments

Comments
 (0)