Skip to content

Commit 01814d1

Browse files
chore: delete deprecated components for v0.13.0 (#1106)
BREAKING CHANGE: removed deprecated `Spinner` component BREAKING CHANGE: removed deprecated `Tokenizer` component BREAKING CHANGE: **Toolbar**: removed deprecated `onToolbarClick` in favour of `onClick` BREAKING CHANGE: **Device**: removed deprecated, class-based API. Please use the [individual util functions](https://sap.github.io/ui5-webcomponents-react/?path=/docs/migration-guide--page#device-api) instead. BREAKING CHANGE: **Device**: removed the optional `oListener` parameter from all device attach/detach functions (mostly used internally)
1 parent 8199200 commit 01814d1

28 files changed

Lines changed: 135 additions & 888 deletions

docs/2-MigrationGuide.stories.mdx

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,52 @@ const withParameters = i18nBundle.getText('CAROUSEL_DOT_TEXT', 5, 20);
5252

5353
The `Toolbar` was firing an event `onToolbarClick`. This event has been replaced with `onClick`.
5454

55+
#### Device API
56+
57+
The deprecated, class-based `Device` API is now removed. Please don't be shocked by this extensive list, most of the APIs
58+
were only used internally and are mentioned here for the sake of completeness.
59+
60+
- `Device.os` is replaced by `getOS()` (`'import { getOS } from '@ui5/webcomponents-react-base/lib/Device';`)
61+
- `Device.browser` is replaced by `getBrowser()` (`'import { getBrowser } from '@ui5/webcomponents-react-base/lib/Device';`)
62+
- `Device.system` is replaced by `getSystem()` (`'import { getSystem } from '@ui5/webcomponents-react-base/lib/Device';`)
63+
64+
<br />
65+
66+
- `Device.support.touch` is replaced by `supportTouch()` (`'import { supportTouch } from '@ui5/webcomponents-react-base/lib/Device';`)
67+
- `Device.support.pointer` is replaced by `supportPointerEvents()` (`'import { supportPointerEvents } from '@ui5/webcomponents-react-base/lib/Device';`)
68+
- `Device.support.matchmedia` is replaced by `supportMatchMedia()` (`'import { supportMatchMedia } from '@ui5/webcomponents-react-base/lib/Device';`)
69+
- `Device.support.matchmedialistener` is replaced by `supportMatchMediaListener()` (`'import { supportMatchMediaListener } from '@ui5/webcomponents-react-base/lib/Device';`)
70+
- `Device.support.orientation` is replaced by `supportOrientation()` (`'import { supportOrientation } from '@ui5/webcomponents-react-base/lib/Device';`)
71+
- `Device.support.retina` is replaced by `supportRetina()` (`'import { supportRetina } from '@ui5/webcomponents-react-base/lib/Device';`)
72+
- `Device.support.websocket` is replaced by `supportWebSocket()` (`'import { supportWebSocket } from '@ui5/webcomponents-react-base/lib/Device';`)
73+
- `Device.support.input.placeholder` is replaced by `supportInputPlaceholder()` (`'import { supportInputPlaceholder } from '@ui5/webcomponents-react-base/lib/Device';`)
74+
75+
<br />
76+
77+
- `Device.orientation.landscape` is replaced by `getOrientation().landscape` (`'import { getOrientation } from '@ui5/webcomponents-react-base/lib/Device';`)
78+
- `Device.orientation.portrait` is replaced by `getOrientation().portrait` (`'import { getOrientation } from '@ui5/webcomponents-react-base/lib/Device';`)
79+
- `Device.orientation.attachHandler` is replaced by `attachOrientationChangeHandler` (`'import { attachOrientationChangeHandler } from '@ui5/webcomponents-react-base/lib/Device';`)<br />
80+
In addition, the second, optional parameter `oListener` got removed from `attachOrientationChangeHandler`.
81+
- `Device.orientation.detachHandler` is replaced by `detachOrientationChangeHandler` (`'import { detachOrientationChangeHandler } from '@ui5/webcomponents-react-base/lib/Device';`)<br />
82+
In addition, the second, optional parameter `oListener` got removed from `detachOrientationChangeHandler`.
83+
- `Device.resize.width` is replaced by `getWindowSize().width` (`'import { getWindowSize } from '@ui5/webcomponents-react-base/lib/Device';`)
84+
- `Device.resize.height` is replaced by `getWindowSize().height` (`'import { getWindowSize } from '@ui5/webcomponents-react-base/lib/Device';`)
85+
- `Device.resize.attachHandler` is replaced by `attachResizeHandler` (`'import { attachResizeHandler } from '@ui5/webcomponents-react-base/lib/Device';`)<br />
86+
In addition, the second, optional parameter `oListener` got removed from `attachResizeHandler`.
87+
- `Device.resize.detachHandler` is replaced by `detachResizeHandler` (`'import { detachResizeHandler } from '@ui5/webcomponents-react-base/lib/Device';`)<br />
88+
In addition, the second, optional parameter `oListener` got removed from `detachResizeHandler`.
89+
90+
<br />
91+
92+
- `Device.media.getCurrentRange` is replaced by `getCurrentRange` (`'import { getCurrentRange } from '@ui5/webcomponents-react-base/lib/Device';`)
93+
- `Device.media.hasRangeSet` is replaced by `hasRangeSet` (`'import { hasRangeSet } from '@ui5/webcomponents-react-base/lib/Device';`)
94+
- `Device.media.initRangeSet` is replaced by `initRangeSet` (`'import { initRangeSet } from '@ui5/webcomponents-react-base/lib/Device';`)
95+
- `Device.media.removeRangeSet` is replaced by `removeRangeSet` (`'import { removeRangeSet } from '@ui5/webcomponents-react-base/lib/Device';`)
96+
- `Device.media.attachHandler` is replaced by `attachHandler` (`'import { attachHandler } from '@ui5/webcomponents-react-base/lib/Device';`)<br />
97+
In addition, the second, optional parameter `oListener` got removed from `attachHandler`.
98+
- `Device.media.detachHandler` is replaced by `detachHandler` (`'import { detachHandler } from '@ui5/webcomponents-react-base/lib/Device';`)<br />
99+
In addition, the second, optional parameter `oListener` got removed from `detachHandler`.
100+
55101
<br />
56102

57103
### Deleted Components

packages/base/src/Device/EventRegistry.test.ts

Lines changed: 0 additions & 33 deletions
This file was deleted.

packages/base/src/Device/EventRegistry.ts

Lines changed: 0 additions & 43 deletions
This file was deleted.
Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,45 @@
1-
import { EventRegistry } from './EventRegistry';
2-
import { getCurrentRange, MediaLegacy, RANGESETS } from './Media';
1+
import {
2+
attachMediaHandler,
3+
detachMediaHandler,
4+
getCurrentRange,
5+
hasRangeSet,
6+
initRangeSet,
7+
RANGESETS,
8+
removeRangeSet
9+
} from './Media';
10+
import { MediaEventProvider } from './MediaEventProvider';
311

412
describe('Device - Media', () => {
5-
test('invoke constructor', () => {
6-
const media = new MediaLegacy();
7-
expect(media.hasRangeSet(RANGESETS.SAP_STANDARD)).toBe(true);
8-
expect(media.hasRangeSet(RANGESETS.SAP_STANDARD_EXTENDED)).toBe(true);
9-
media.initRangeSet(RANGESETS.SAP_STANDARD_EXTENDED);
10-
expect(media.hasRangeSet(RANGESETS.SAP_STANDARD)).toBe(true);
11-
});
12-
1313
test('getCurrentRangeSet with undefined Range Set', () => {
1414
expect(getCurrentRange('Not_Defined', 100)).toBeNull();
1515
});
1616

1717
test('Attach, fire and Detach Event', () => {
18-
const media = new MediaLegacy();
1918
const callback = jest.fn();
20-
// @ts-ignore
21-
media.attachHandler(callback, this);
22-
expect(EventRegistry.mEventRegistry.hasOwnProperty('media_Std'));
23-
EventRegistry.fireEvent('media_Std');
24-
expect(callback).toBeCalled();
25-
// @ts-ignore
26-
media.detachHandler(callback, this);
27-
expect(EventRegistry.mEventRegistry.hasOwnProperty('media_Std')).toBe(false);
19+
attachMediaHandler(callback);
20+
expect(MediaEventProvider.isHandlerAttached('media_Std', callback)).toBeTruthy();
21+
detachMediaHandler(callback);
22+
expect(MediaEventProvider.isHandlerAttached('media_Std', callback)).toBeFalsy();
2823
});
2924

3025
test('Init Custom Range Set and remove it again', () => {
31-
const media = new MediaLegacy();
32-
media.initRangeSet('MyRangeSet', [200, 400], 'px', ['Small', 'Medium', 'Large']);
33-
expect(media.getCurrentRange('MyRangeSet', 300).name).toBe('Medium');
34-
media.removeRangeSet('MyRangeSet');
26+
initRangeSet('MyRangeSet', [200, 400], 'px', ['Small', 'Medium', 'Large']);
27+
expect(getCurrentRange('MyRangeSet', 300).name).toBe('Medium');
28+
removeRangeSet('MyRangeSet');
3529
});
3630

3731
test('Init Custom Range Set and remove it again w/ matchmedialistener', () => {
38-
const media = new MediaLegacy();
39-
media.initRangeSet('MyRangeSet', [200, 400], 'px', ['Small', 'Medium', 'Large']);
40-
expect(media.getCurrentRange('MyRangeSet', 300).name).toBe('Medium');
41-
media.removeRangeSet('MyRangeSet');
32+
initRangeSet('MyRangeSet', [200, 400], 'px', ['Small', 'Medium', 'Large']);
33+
expect(getCurrentRange('MyRangeSet', 300).name).toBe('Medium');
34+
removeRangeSet('MyRangeSet');
4235
});
4336

4437
test('Remove unknown rangeset should not crash', () => {
45-
const media = new MediaLegacy();
46-
expect(() => media.removeRangeSet('MyRangeSet')).not.toThrow();
38+
expect(() => removeRangeSet('MyRangeSet')).not.toThrow();
4739
});
4840

4941
test("Don't remove build in rangesets", () => {
50-
const media = new MediaLegacy();
51-
media.removeRangeSet(RANGESETS.SAP_STANDARD);
52-
expect(media.hasRangeSet(RANGESETS.SAP_STANDARD)).toBe(true);
42+
removeRangeSet(RANGESETS.SAP_STANDARD);
43+
expect(hasRangeSet(RANGESETS.SAP_STANDARD)).toBe(true);
5344
});
5445
});

packages/base/src/Device/Media.ts

Lines changed: 10 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { Logger } from '@ui5/webcomponents-react-base/lib/Logger';
2-
import { deprecationNotice } from '@ui5/webcomponents-react-base/lib/Utils';
3-
import { EventRegistry } from './EventRegistry';
2+
import { MediaEventProvider } from './MediaEventProvider';
43
import { supportMatchMediaListener } from './Support';
54
import { changeRootCSSClass, getQuery, matchLegacyBySize } from './utils';
65

@@ -31,6 +30,8 @@ interface RangeSet {
3130
listener?: () => void;
3231
}
3332

33+
const eventProvider = MediaEventProvider;
34+
3435
// private helpers
3536
const initializedQuerySets: Record<string, RangeSet> = {};
3637

@@ -93,7 +94,7 @@ const handleChange = (name: string): void => {
9394
() => {
9495
const mParams = checkQueries(name, false);
9596
if (mParams) {
96-
EventRegistry.fireEvent(`media_${name}`, mParams);
97+
eventProvider.fireEvent(`media_${name}`, mParams);
9798
}
9899
},
99100
supportMatchMediaListener() ? 0 : 100
@@ -190,8 +191,6 @@ export const initRangeSet = (
190191
}
191192

192193
if (hasRangeSet(oConfig.name)) {
193-
// TODO v0.12.0 - Reactivate this line again once the Device Class is removed.
194-
// Logger.info(`Range set ${oConfig.name} has already been initialized`, 'DEVICE.MEDIA');
195194
return;
196195
}
197196

@@ -249,95 +248,15 @@ export const removeRangeSet = (rangeSetName: string): void => {
249248
}
250249

251250
refreshCSSClasses(rangeSetName, '', true);
252-
delete EventRegistry.mEventRegistry[`media_${rangeSetName}`];
251+
// eslint-disable-next-line no-underscore-dangle
252+
delete eventProvider._eventRegistry[`media_${rangeSetName}`];
253253
delete initializedQuerySets[rangeSetName];
254254
};
255255

256-
export const attachHandler = (fnFunction, oListener?, name: string = DEFAULT_RANGE_SET): void => {
257-
EventRegistry.attachEvent(`media_${name}`, fnFunction, oListener);
256+
export const attachMediaHandler = (fnFunction, name: string = DEFAULT_RANGE_SET): void => {
257+
eventProvider.attachEvent(`media_${name}`, fnFunction);
258258
};
259259

260-
export const detachHandler = (fnFunction, oListener?, name: string = DEFAULT_RANGE_SET): void => {
261-
EventRegistry.detachEvent(`media_${name}`, fnFunction, oListener);
260+
export const detachMediaHandler = (fnFunction, name: string = DEFAULT_RANGE_SET): void => {
261+
eventProvider.detachEvent(`media_${name}`, fnFunction);
262262
};
263-
264-
export class MediaLegacy {
265-
constructor() {
266-
if (!initializedQuerySets[DEFAULT_RANGE_SET]) {
267-
initRangeSet();
268-
}
269-
if (!initializedQuerySets[RANGESETS.SAP_STANDARD_EXTENDED]) {
270-
initRangeSet(RANGESETS.SAP_STANDARD_EXTENDED);
271-
}
272-
}
273-
274-
// Public API
275-
public RANGESETS = RANGESETS;
276-
public predefinedRangeSets = DEFAULT_RANGESETS;
277-
278-
public getCurrentRange(rangeSetName: string, width: number) {
279-
deprecationNotice(
280-
'Device.media.getCurrentRange',
281-
`Accessing 'Device.media.getCurrentRange' is deprecated and will be removed in the next major version.
282-
Please use 'getCurrentRange' ('import { getCurrentRange } from '@ui5/webcomponents-react-base/lib/Media') instead.`
283-
);
284-
return getCurrentRange(rangeSetName, width);
285-
}
286-
287-
public hasRangeSet(name) {
288-
deprecationNotice(
289-
'Device.media.hasRangeSet',
290-
`Accessing 'Device.media.hasRangeSet' is deprecated and will be removed in the next major version.
291-
Please use 'hasRangeSet' ('import { hasRangeSet } from '@ui5/webcomponents-react-base/lib/Media') instead.`
292-
);
293-
return hasRangeSet(name);
294-
}
295-
296-
public initRangeSet(
297-
sName?: string,
298-
aRangeBorders?: number[],
299-
sUnit?: string,
300-
aRangeNames?: string[],
301-
bSuppressClasses?: boolean
302-
) {
303-
deprecationNotice(
304-
'Device.media.initRangeSet',
305-
`Accessing 'Device.media.initRangeSet' is deprecated and will be removed in the next major version.
306-
Please use 'initRangeSet' ('import { initRangeSet } from '@ui5/webcomponents-react-base/lib/Media') instead.`
307-
);
308-
return initRangeSet(sName, aRangeBorders, sUnit, aRangeNames, bSuppressClasses);
309-
}
310-
311-
public removeRangeSet(name) {
312-
deprecationNotice(
313-
'Device.media.removeRangeSet',
314-
`Accessing 'Device.media.removeRangeSet' is deprecated and will be removed in the next major version.
315-
Please use 'removeRangeSet' ('import { removeRangeSet } from '@ui5/webcomponents-react-base/lib/Media') instead.`
316-
);
317-
return removeRangeSet(name);
318-
}
319-
320-
public attachHandler(fnFunction, oListener?, name: string = DEFAULT_RANGE_SET) {
321-
deprecationNotice(
322-
'Device.media.attachHandler',
323-
`Accessing 'Device.media.attachHandler' is deprecated and will be removed in the next major version.
324-
Please use 'attachHandler' ('import { attachHandler } from '@ui5/webcomponents-react-base/lib/Media') instead.`
325-
);
326-
return attachHandler(fnFunction, oListener, name);
327-
}
328-
329-
public detachHandler(fnFunction, oListener?, name: string = DEFAULT_RANGE_SET) {
330-
deprecationNotice(
331-
'Device.media.detachHandler',
332-
`Accessing 'Device.media.detachHandler' is deprecated and will be removed in the next major version.
333-
Please use 'detachHandler' ('import { detachHandler } from '@ui5/webcomponents-react-base/lib/Media') instead.`
334-
);
335-
return detachHandler(fnFunction, oListener, name);
336-
}
337-
338-
// Private API
339-
private static getRangeInfo = getRangeInfo;
340-
private checkQueries = checkQueries;
341-
private handleChange = handleChange;
342-
matches = matches;
343-
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import EventProvider from '@ui5/webcomponents-base/dist/EventProvider';
2+
3+
export const MediaEventProvider = new EventProvider();

0 commit comments

Comments
 (0)