@24i/bigscreen-sdk 1.0.12-alpha.2254 → 1.0.12

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.
Files changed (37) hide show
  1. package/package.json +6 -2
  2. package/packages/analytics/README.md +1 -58
  3. package/packages/analytics/src/A.ts +1 -51
  4. package/packages/analytics/src/Analytics.ts +1 -114
  5. package/packages/analytics/src/analyticsOnScroll.ts +1 -11
  6. package/packages/analytics/src/clients/ConsoleAnalytics/ConsoleAnalytics.ts +1 -12
  7. package/packages/analytics/src/constants.ts +1 -56
  8. package/packages/analytics/src/interface.ts +1 -82
  9. package/packages/driver-webos/src/DeviceWebos.ts +8 -0
  10. package/packages/epg/README.md +3 -1
  11. package/packages/epg/src/v2/Cell.tsx +16 -2
  12. package/packages/epg/src/v2/DataManager.ts +4 -1
  13. package/packages/epg/src/v2/Epg.tsx +3 -1
  14. package/packages/epg/src/v2/Row.tsx +3 -1
  15. package/packages/epg/src/v2/basic/CellsManager.tsx +7 -2
  16. package/packages/epg/src/v2/basic/RowsManager.tsx +3 -1
  17. package/packages/epg/src/v2/interface.ts +13 -0
  18. package/packages/events-manager/src/EventsManager.ts +1 -56
  19. package/packages/list/src/Base/Base.tsx +6 -1
  20. package/packages/list/src/Base/interface.ts +2 -2
  21. package/packages/list/src/EdgeOffsetList/EdgeOffsetList.tsx +2 -2
  22. package/packages/logger/src/loggers/SentryLogger/Sentry.ts +1 -0
  23. package/packages/logger/src/loggers/SentryLogger/SentryLogger.ts +2 -2
  24. package/packages/perf-utils/README.md +1 -120
  25. package/packages/perf-utils/src/array/filter.ts +1 -54
  26. package/packages/perf-utils/src/array/find.ts +1 -43
  27. package/packages/perf-utils/src/array/findIndex.ts +1 -43
  28. package/packages/perf-utils/src/array/forEach.ts +1 -48
  29. package/packages/perf-utils/src/array/includes.ts +1 -41
  30. package/packages/perf-utils/src/array/includesNaN.ts +1 -32
  31. package/packages/perf-utils/src/array/index.ts +1 -7
  32. package/packages/perf-utils/src/array/map.ts +1 -52
  33. package/packages/player-ui/src/PlayerUI.tsx +15 -9
  34. package/packages/player-ui/src/Seekbar.tsx +4 -2
  35. package/packages/player-ui/src/index.ts +1 -0
  36. package/packages/player-ui/src/mocks.ts +3 -3
  37. package/packages/player-ui/src/types.ts +3 -1
@@ -241,6 +241,14 @@ type ScrollStepMsProp = {
241
241
  scrollStepMs: number,
242
242
  };
243
243
 
244
+ type SmallestAllowedCellPxProp = {
245
+ /**
246
+ * If the width of the cell is smaller than this the cell will have a special
247
+ * class `too-small`. Value in pixels.
248
+ */
249
+ smallestAllowedCellPx: number,
250
+ };
251
+
244
252
  type IdleTimerMsProp = {
245
253
  /**
246
254
  * The number of milliseconds of inactivity (no input) after which EPG starts jumps
@@ -823,6 +831,7 @@ export type RowsManagerProps<
823
831
  & RenderChannelHeaderProp<T>
824
832
  & RenderProgramProp<U>
825
833
  & IsFocusInRowsProp
834
+ & SmallestAllowedCellPxProp
826
835
  );
827
836
 
828
837
  /**
@@ -933,6 +942,7 @@ export type RowProps<
933
942
  & TimestampProp
934
943
  & TimeProp
935
944
  & ScrollStepMsProp
945
+ & SmallestAllowedCellPxProp
936
946
  & ProgramTextModeResolverProp
937
947
  & OnItemPressProp<T>
938
948
  & OnMouseEnterProp
@@ -1046,6 +1056,7 @@ export type CellsManagerProps<
1046
1056
  & ProgramTextModeResolverProp
1047
1057
  & OnMouseEnterProp
1048
1058
  & RenderProgramProp<T>
1059
+ & SmallestAllowedCellPxProp
1049
1060
  );
1050
1061
 
1051
1062
  /**
@@ -1133,6 +1144,7 @@ export type CellProps<
1133
1144
  & ProgramTextModeResolverProp
1134
1145
  & OnMouseEnterProp
1135
1146
  & RenderProgramProp<T>
1147
+ & SmallestAllowedCellPxProp
1136
1148
  );
1137
1149
 
1138
1150
  /**
@@ -1275,6 +1287,7 @@ export type Props<
1275
1287
  & Partial<InitialTimestampProp>
1276
1288
  & Partial<InitialChannelIndexProp>
1277
1289
  & Partial<ProgramTextModeResolverProp>
1290
+ & Partial<SmallestAllowedCellPxProp>
1278
1291
  & OnItemPressProp<U>
1279
1292
  & Partial<OnFocusChangeProp<U>>
1280
1293
  & Partial<OnScrolledToTimestampProp>
@@ -1,56 +1 @@
1
- import { forEach, map } from '@24i/bigscreen-sdk/perf-utils/array';
2
-
3
- type PayloadOf<T> = T extends (payload: infer Payload) => any ? Payload : never;
4
-
5
- export type EventMapType = { [key: string]: (payload: any) => void };
6
-
7
- export interface IEvents<EventMap extends EventMapType> {
8
- addEventListener: <K extends keyof EventMap>(
9
- eventName: K,
10
- listener: EventMap[K],
11
- ) => void,
12
- removeEventListener: <K extends keyof EventMap>(
13
- eventName: K,
14
- listener: EventMap[K],
15
- ) => void,
16
- triggerEvent: <K extends keyof EventMap>(
17
- eventName: K,
18
- payload: PayloadOf<EventMap[K]>,
19
- ) => void,
20
- }
21
-
22
- export class EventsManager<EventMap extends EventMapType> implements IEvents<EventMap> {
23
- eventListeners: Partial<{
24
- [key in keyof EventMap]: EventMap[key][]
25
- }> = {};
26
-
27
- addEventListener = <K extends keyof EventMap>(
28
- eventName: K,
29
- listener: EventMap[K],
30
- ): void => {
31
- if (!this.eventListeners[eventName]) this.eventListeners[eventName] = [];
32
- const listeners = this.eventListeners[eventName] as EventMap[K][];
33
- listeners.push(listener);
34
- };
35
-
36
- removeEventListener = <K extends keyof EventMap>(
37
- eventName: K,
38
- listener: EventMap[K],
39
- ): void => {
40
- const listeners = this.eventListeners[eventName] as EventMap[K][] | undefined;
41
- if (!listeners) return;
42
- const index = listeners.indexOf(listener);
43
- if (index !== -1) listeners.splice(index, 1);
44
- };
45
-
46
- triggerEvent = <K extends keyof EventMap>(
47
- eventName: K,
48
- payload?: PayloadOf<EventMap[K]>,
49
- ): void => {
50
- const eventListeners = this.eventListeners[eventName] as EventMap[K][] | undefined;
51
- if (!eventListeners) return;
52
- // In case listener removes itself during listening we need loop on a copy
53
- const listeners = map(eventListeners, (l) => l);
54
- forEach(listeners, (listener) => listener(payload));
55
- };
56
- }
1
+ export * from '@24i/appstage-shared-events-manager/dist/EventsManager';
@@ -360,7 +360,10 @@ export class ListBase<T extends Item<U>, U>
360
360
  }
361
361
 
362
362
  render() {
363
- const { horizontal, className, mrcuMountingPoint } = this.props;
363
+ const {
364
+ horizontal, className,
365
+ mrcuMountingPoint, mrcuForward, mrcuBackward, forward, backward,
366
+ } = this.props;
364
367
  return (
365
368
  <Scroller
366
369
  className={className}
@@ -375,6 +378,8 @@ export class ListBase<T extends Item<U>, U>
375
378
  ref={this.mrcuRef}
376
379
  getMountingPoint={() => mrcuMountingPoint || this.scroller.current!.wrapRef}
377
380
  {...this.props}
381
+ forward={mrcuForward || forward}
382
+ backward={mrcuBackward || backward}
378
383
  />
379
384
  </Scroller>
380
385
  );
@@ -4,11 +4,11 @@ export type MouseNavigationProps = {
4
4
  /**
5
5
  * Function to call on the press of the right arrow.
6
6
  */
7
- forward(): boolean,
7
+ forward(): void,
8
8
  /**
9
9
  * Function to call on the press of the left arrow.
10
10
  */
11
- backward(): boolean,
11
+ backward(): void,
12
12
  /**
13
13
  * Function which determines whether to show the forward arrow.
14
14
  */
@@ -81,14 +81,14 @@ export class EdgeOffsetList<T extends Item<U>, U>
81
81
  const list = this.base.current!;
82
82
  list.index = Math.max(
83
83
  0,
84
- Math.min(scrollIndex + visibleItems - VISIBLE_ITEMS_OFFSET, list.data.length - 1),
84
+ Math.min(scrollIndex + visibleItems - VISIBLE_ITEMS_OFFSET - 1, list.data.length - 1),
85
85
  );
86
86
  this.forward();
87
87
  };
88
88
 
89
89
  mrcuBackward = () => {
90
90
  const list = this.base.current!;
91
- list.index = this.controller.scrollIndex;
91
+ list.index = this.controller.scrollIndex + 1;
92
92
  this.backward();
93
93
  };
94
94
 
@@ -1 +1,2 @@
1
1
  export * as Sentry from '@sentry/browser';
2
+ export { ErrorEvent } from '@sentry/types';
@@ -3,7 +3,7 @@ import { IStorage, Storage as DefaultStorage } from '@24i/bigscreen-sdk/storage'
3
3
  import { LogOptions, LogLevel, SentryLoggerEnvironment, XhrBreadcrumbData } from '../../types';
4
4
  import { getFormattedMemoryHeapInfo, getFormattedUsedLocalStorageSize } from '../../utils';
5
5
  import { LoggerBase, Config as LoggerBaseConfig } from '../LoggerBase';
6
- import { Sentry } from './Sentry';
6
+ import { Sentry, ErrorEvent } from './Sentry';
7
7
 
8
8
  type Config = {
9
9
  sentryOptions: Sentry.BrowserOptions;
@@ -46,7 +46,7 @@ export class SentryLogger extends LoggerBase {
46
46
  const { beforeSend, ...restOptions } = options;
47
47
  Sentry.init({
48
48
  ...restOptions,
49
- beforeSend: async (event: Sentry.Event, hint: Sentry.EventHint) => {
49
+ beforeSend: async (event: ErrorEvent, hint: Sentry.EventHint) => {
50
50
  if (this.mute) return null;
51
51
  await this.sendMemoryInfo(event);
52
52
  return beforeSend ? beforeSend(event, hint) : event;
@@ -5,123 +5,4 @@ hide_title: true
5
5
  sidebar_label: Performance Utils
6
6
  ---
7
7
 
8
- # Performance Utils
9
- Set of utilities that should increase a performance if they are used instead of a native way, mainly on older devices (e.g. Entone/Kamai set-top-boxes).
10
-
11
- > **Please check the limitations of each performance utility You want to use in a code.**
12
-
13
- ## Available perf utils
14
- - **[Array](#array-perf-utils)**
15
- - [filter](#filter)
16
- - [forEach](#foreach)
17
- - [includes](#includes)
18
- - [includesNaN](#includesnan)
19
- - [map](#map)
20
-
21
- ## Array perf utils
22
-
23
- > In general, each Array utility which requires a callback will iterate over all array items, even if array index hasn't been initialized yet (to understand the issue, see [An adventure in sparse arrays](https://remysharp.com/2018/06/26/an-adventure-in-sparse-arrays)).
24
-
25
- ### filter()
26
- > The filter() method creates a new array with all elements that pass the test implemented by the provided function.
27
-
28
- For more info, please see [native **filter** method](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter).
29
-
30
- #### Limitations against native implementation
31
- - **`callback` is invoked for all indexes of the array** (not only for indexes with assigned values like [native filter implementation](http://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/filter#Description)).
32
- - **Doesn't coerce returned value from a callback to `true` or `false`**, the callback has to return a boolean value directly.
33
- - Doesn't accept the `scope` as last argument.
34
-
35
- #### Usage
36
- ```javascript
37
- import { filter } from '@24i/bigscreen-sdk/perf-utils/array';
38
-
39
- const array = ['spray', 'limit', 'elite', 'exuberant', 'destruction'];
40
- //const result = array.filter(word => word.length > 6); // slower native solution
41
- const result = filter(array, word => word.length > 6); // faster
42
-
43
- console.log(result);
44
- // expected output: Array ["exuberant", "destruction"]
45
- ```
46
-
47
- ### forEach()
48
- > The forEach() method executes a provided function once for each array element.
49
-
50
- For more info, please see [native **forEach** method](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach).
51
-
52
- #### Limitations against native implementation
53
- - **`callback` is invoked for all indexes of the array** (not only for indexes with assigned values like [native forEach implementation](http://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach#Description)).
54
- - Doesn't accept the `scope` as last argument.
55
-
56
- #### Usage
57
- ```javascript
58
- import { forEach } from '@24i/bigscreen-sdk/perf-utils/array';
59
-
60
- const array = ['a', 'b', 'c'];
61
- // array.forEach(item => console.log(item)); // slower native solution
62
- forEach(array, item => console.log(item)); // faster
63
-
64
- // expected output: "a"
65
- // expected output: "b"
66
- // expected output: "c"
67
- ```
68
-
69
- ### includes()
70
- > The includes() method determines whether an array includes a certain value among its entries, returning true or false as appropriate.
71
-
72
- For more info, please see [native **includes** method](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes).
73
-
74
- #### Limitations against native implementation
75
- - **Doesn't work for searching NaN value!** For that purpose, please use [includesNaN()](#includesnan).
76
- - Doesn't support negative indexes for `fromIndex` param - the entire array will be processed.
77
-
78
- #### Usage
79
- ```javascript
80
- import { includes } from '@24i/bigscreen-sdk/perf-utils/array';
81
-
82
- const array = ['item0', 'item1', 'item2'];
83
-
84
- //console.log(array.includes('item1')); // slower native solution
85
- console.log(includes(array, 'item1')); // faster
86
- // expected output: true
87
-
88
- //console.log(array.includes('item1')); // slower native solution
89
- console.log(includes(array, 'item1', 2)); // faster
90
- // expected output: false
91
- ```
92
-
93
- ### includesNaN()
94
- > The includesNaN() method determines whether an array includes NaN value among its entries, returning true or false as appropriate.
95
-
96
- #### Usage
97
- ```javascript
98
- import { includesNaN } from '@24i/bigscreen-sdk/perf-utils/array';
99
-
100
- console.log(includesNaN([0, NaN, 1]));
101
- // expected output: true
102
-
103
- console.log(includesNaN([0, NaN, 1], 2));
104
- // expected output: false
105
- ```
106
-
107
- ### map()
108
- > The map() method creates a new array populated with the results of calling a provided function on every element in the calling array.
109
-
110
- For more info, please see [native **map** method](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map).
111
-
112
- #### Limitations against native implementation
113
- - **`callback` is invoked for all indexes of the array** (not only for indexes with assigned values like [native map implementation](http://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/map#Description)).
114
- - Doesn't accept the `scope` as last argument.
115
-
116
- #### Usage
117
- ```javascript
118
- import { map } from '@24i/bigscreen-sdk/perf-utils/array';
119
-
120
- const array = [1, 4, 9, 16];
121
-
122
- // const mappedArray = array.map(x => x * 2); // slower native solution
123
- const mappedArray = map(array, x => x * 2); // faster
124
-
125
- console.log(mappedArray);
126
- // expected output: Array [2, 8, 18, 32]
127
- ```
8
+ https://github.com/24i/appstage-shared-packages/blob/main/packages/perf-utils/README.md
@@ -1,54 +1 @@
1
- /**
2
- * Performance optimized version of `Array.prototype.filter` method.
3
- *
4
- * Creates a new array with all elements that pass the test implemented by the provided function.
5
- * @see https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/filter
6
- *
7
- * **Limitations against native implementation**:
8
- *
9
- * - **`callback` is invoked for all indexes of the array**,
10
- * (not only for indexes with assigned values like native filter implementation), see example.
11
- * - **Doesn't coerce returned value from a callback to `true` or `false`**,
12
- * the callback has to return a boolean value directly.
13
- * - Doesn't accept the `scope` as last argument.
14
- *
15
- * @param {Array} array - Input array.
16
- * @param {Function} callback - Predicate to test each element of the array.
17
- * Return true to keep the element, false otherwise.
18
- *
19
- * @return {Array} with filtered results.
20
- *
21
- * @example
22
- * import { filter } from '@24i/bigscreen-sdk/perf-utils/array';
23
- *
24
- * const array = ['spray', 'limit', 'elite', 'exuberant', 'destruction'];
25
- *
26
- * //const result = array.filter(word => word.length > 6); // slower native solution
27
- * const result = filter(array, word => word.length > 6); // faster
28
- *
29
- * console.log(result);
30
- * // expected output: Array ["exuberant", "destruction"]
31
- *
32
- * @example
33
- * import { filter } from '@24i/bigscreen-sdk/perf-utils/array';
34
- *
35
- * const nativeResult = [1, 2, , undefined].filter(() => true);
36
- * console.log(nativeResult); // Array [1, 2, undefined]. Yes, empty value is missing here.
37
- *
38
- * const customResult = filter([1, 2, , undefined], () => true);
39
- * console.log(customResult); // Array [1, 2, undefined, undefined]. With iteration over hole.
40
- */
41
- export const filter = <T>(
42
- array: T[],
43
- callback: (value: T, index: number, array: T[]) => boolean,
44
- ): T[] => {
45
- const output: T[] = [];
46
-
47
- for (let i = 0, len = array.length; i < len; i++) {
48
- if (callback(array[i], i, array) === true) {
49
- output.push(array[i]);
50
- }
51
- }
52
-
53
- return output;
54
- };
1
+ export { filter } from '@24i/appstage-shared-perf-utils/dist/array';
@@ -1,43 +1 @@
1
- /**
2
- * Performance optimized version of `Array.prototype.find` method.
3
- *
4
- * Returns the first element that satisfies the testing function. Undefined if no item satisfies
5
- * the testing function.
6
- * @see https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/find
7
- *
8
- * **Limitations against native implementation**:
9
- *
10
- * - **`callback` is invoked for all indexes of the array**,
11
- * (not only for indexes with assigned values like native filter implementation), see example.
12
- * - **Doesn't coerce returned value from a callback to `true` or `false`**,
13
- * the callback has to return a boolean value directly.
14
- * - Doesn't accept the `scope` as last argument.
15
- *
16
- * @param {Array<T>} array - Input array.
17
- * @param {Function} callback - Predicate to test each element of the array.
18
- * Return true to select the element, false otherwise.
19
- *
20
- * @return {T | undefined} The first element the satisfied the testing function. Or undefined.
21
- *
22
- * @example
23
- * import { find } from '@24i/bigscreen-sdk/perf-utils/array';
24
- *
25
- * const array = ['spray', 'limit', 'elite', 'exuberant', 'destruction'];
26
- *
27
- * //const result = array.find(word => word.length > 6); // slower native solution
28
- * const result = find(array, word => word.length > 6); // faster
29
- *
30
- * console.log(result);
31
- * // expected output: "exuberant"
32
- */
33
- export const find = <T>(
34
- array: T[],
35
- callback: (value: T, index: number, array: T[]) => boolean,
36
- ): T | undefined => {
37
- for (let i = 0, len = array.length; i < len; i++) {
38
- if (callback(array[i], i, array) === true) {
39
- return array[i];
40
- }
41
- }
42
- return undefined;
43
- };
1
+ export { find } from '@24i/appstage-shared-perf-utils/dist/array';
@@ -1,43 +1 @@
1
- /**
2
- * Performance optimized version of `Array.prototype.findIndex` method.
3
- *
4
- * Returns the index of the first element that satisfies the testing function.
5
- * Returns -1 if no item satisfies the testing function.
6
- * @see https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex
7
- *
8
- * **Limitations against native implementation**:
9
- *
10
- * - **`callback` is invoked for all indexes of the array**,
11
- * (not only for indexes with assigned values like native filter implementation), see example.
12
- * - **Doesn't coerce returned value from a callback to `true` or `false`**,
13
- * the callback has to return a boolean value directly.
14
- * - Doesn't accept the `scope` as last argument.
15
- *
16
- * @param {Array<T>} array - Input array.
17
- * @param {Function} callback - Predicate to test each element of the array.
18
- * Return true to select the index of the element, false otherwise.
19
- *
20
- * @return {number} Index of the first element the satisfied the testing function. Or -1.
21
- *
22
- * @example
23
- * import { findIndex } from '@24i/bigscreen-sdk/perf-utils/array';
24
- *
25
- * const array = ['spray', 'limit', 'elite', 'exuberant', 'destruction'];
26
- *
27
- * //const result = array.findIndex(word => word.length > 6); // slower native solution
28
- * const result = findIndex(array, word => word.length > 6); // faster
29
- *
30
- * console.log(result);
31
- * // expected output: 3
32
- */
33
- export const findIndex = <T>(
34
- array: T[],
35
- callback: (value: T, index: number, array: T[]) => boolean,
36
- ): number => {
37
- for (let i = 0, len = array.length; i < len; i++) {
38
- if (callback(array[i], i, array) === true) {
39
- return i;
40
- }
41
- }
42
- return -1;
43
- };
1
+ export { findIndex } from '@24i/appstage-shared-perf-utils/dist/array';
@@ -1,48 +1 @@
1
- /**
2
- * Performance optimized version of `Array.prototype.forEach` method.
3
- *
4
- * Executes a provided function once for each array element.
5
- * @see https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach
6
- *
7
- * **Limitations against native implementation**:
8
- *
9
- * - **`callback` is invoked for all indexes of the array**,
10
- * (not only for indexes with assigned values like native filter implementation), see example.
11
- * - Doesn't accept the scope as last argument.
12
- *
13
- * @param {Array} array - Input array.
14
- * @param {Function} callback - Function to execute on each element.
15
- *
16
- * @return {void}
17
- *
18
- * @example
19
- * import { forEach } from '@24i/bigscreen-sdk/perf-utils/array';
20
- *
21
- * const array = ['a', 'b', 'c'];
22
- *
23
- * // array.forEach(item => console.log(item)); // slower native solution
24
- * forEach(array, item => console.log(item)); // faster
25
- *
26
- * // expected output: "a"
27
- * // expected output: "b"
28
- * // expected output: "c"
29
- *
30
- * @example
31
- * import { forEach } from '@24i/bigscreen-sdk/perf-utils/array';
32
- *
33
- * const array = new Array(1000); // creates an empty array with length 1000
34
- *
35
- * let iNative = 0;
36
- * array.forEach(() => iNative++);
37
- * console.log(iNative); // 0 - the callback was never called
38
- *
39
- * let iCustom = 0;
40
- * forEach(array, () => iCustom++);
41
- * console.log(iCustom); // 1000 - the callback was called for each item (hole) in array
42
- */
43
-
44
- export const forEach = <T>(array: T[], callback: (value: T, index: number, array: T[]) => void) => {
45
- for (let i = 0, len = array.length; i < len; i++) {
46
- callback(array[i], i, array);
47
- }
48
- };
1
+ export { forEach } from '@24i/appstage-shared-perf-utils/dist/array';
@@ -1,41 +1 @@
1
- /**
2
- * Performance optimized version of `Array.prototype.includes` method
3
- * (doesn't work for searching NaN value).
4
- *
5
- * Determines whether an array includes a certain value among its entries,
6
- * returning true or false as appropriate.
7
-
8
- * @see https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/includes
9
- * @see includesNaN()
10
- *
11
- * **Limitations against native implementation**:
12
- * - **Doesn't work for searching NaN value. For that purpose, please use includesNaN()**.
13
- * - Doesn't accept the scope as last argument.
14
- *
15
- * @param {Array} array - Input array.
16
- * @param {*} valueToFind - Value to find in array.
17
- * @param {number} [fromIndex=0] - Index to start search from.
18
- *
19
- * @return {boolean}
20
- *
21
- * @example
22
- * import { includes } from '@24i/bigscreen-sdk/perf-utils/array';
23
- *
24
- * const array = ['item0', 'item1', 'item2'];
25
- *
26
- * //console.log(array.includes('item1')); // slower native solution
27
- * console.log(includes(array, 'item1')); // faster
28
- * // expected output: true
29
- *
30
- * //console.log(array.includes('item1')); // slower native solution
31
- * console.log(includes(array, 'item1', 2)); // faster
32
- * // expected output: false
33
- */
34
- export const includes = <T>(array: T[], valueToFind: T, fromIndex = 0): boolean => {
35
- for (let i = fromIndex, len = array.length; i < len; i++) {
36
- if (array[i] === valueToFind) {
37
- return true;
38
- }
39
- }
40
- return false;
41
- };
1
+ export { includes } from '@24i/appstage-shared-perf-utils/dist/array';
@@ -1,32 +1 @@
1
- /**
2
- * Performance optimized version of `Array.prototype.includes` method for testing `NaN` value.
3
- *
4
- * Determines whether an array includes NaN value among its entries,
5
- * returning true or false as appropriate.
6
- *
7
- * @see https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/includes
8
- *
9
- * @param {Array} array - Input array.
10
- * @param {number} [fromIndex=0] - Index to start search from.
11
- *
12
- * @return {boolean}
13
- *
14
- * @example
15
- * import { includesNaN } from '@24i/bigscreen-sdk/perf-utils/array';
16
- *
17
- * // returns true
18
- * includesNaN([0, NaN, 2]);
19
- *
20
- * // returns false
21
- * includesNaN([0, NaN, 2], 2);
22
- */
23
- export const includesNaN = (array: any[], fromIndex = 0): boolean => {
24
- for (let i = fromIndex, len = array.length; i < len; i++) {
25
- const iValue = array[i];
26
- // eslint-disable-next-line no-self-compare
27
- if (iValue !== iValue) { // true only for NaN value
28
- return true;
29
- }
30
- }
31
- return false;
32
- };
1
+ export { includesNaN } from '@24i/appstage-shared-perf-utils/dist/array';
@@ -1,7 +1 @@
1
- export { filter } from './filter';
2
- export { find } from './find';
3
- export { findIndex } from './findIndex';
4
- export { forEach } from './forEach';
5
- export { includes } from './includes';
6
- export { includesNaN } from './includesNaN';
7
- export { map } from './map';
1
+ export * from '@24i/appstage-shared-perf-utils/dist/array';
@@ -1,52 +1 @@
1
- /**
2
- * Performance optimized version of `Array.prototype.map` method.
3
- *
4
- * Creates a new array populated with the results of calling a provided function
5
- * on every element in the calling array.
6
- *
7
- * @see https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/map
8
- *
9
- * **Limitations against native implementation**:
10
- *
11
- * - **`callback` is invoked for all indexes of the array**,
12
- * (not only for indexes with assigned values like native filter implementation), see example.
13
- * - Doesn't accept the `scope` as last argument.
14
- *
15
- * @param {Array} array - Input array.
16
- * @param {Function} callback - Function that is called for every element of arr.
17
- * Each time callback executes, the returned value is added to output array.
18
- *
19
- * @return {Array} with mapped results.
20
- *
21
- * @example
22
- * import { map } from '@24i/bigscreen-sdk/perf-utils/array';
23
- *
24
- * const array = [1, 4, 9, 16];
25
- *
26
- * // const mappedArray = array.map(x => x * 2); // slower native solution
27
- * const mappedArray = map(array, x => x * 2); // faster
28
- *
29
- * console.log(mappedArray);
30
- * // expected output: Array [2, 8, 18, 32]
31
- *
32
- * @example
33
- * import { map } from '@24i/bigscreen-sdk/perf-utils/array';
34
- *
35
- * const array = [1, , 2].map(x => x * x) // [ 1, , 4 ]
36
- *
37
- * const nativeResult = array.map(x => x * x);
38
- * console.log(nativeResult); // [ 1, , 4 ] // keeps hole in array
39
- *
40
- * const customResult = map(array, x => x * x);
41
- * console.log(customResult); // [ 1, NaN , 4 ] NaN? -> undefined * undefined = NaN
42
- */
43
- export const map = <T, M>(array: T[], callback: (item: T, index: number, array: T[]) => M): M[] => {
44
- const len = array.length;
45
- const output = new Array(len);
46
-
47
- for (let i = 0; i < len; i++) {
48
- output[i] = callback(array[i], i, array);
49
- }
50
-
51
- return output;
52
- };
1
+ export { map } from '@24i/appstage-shared-perf-utils/dist/array';