@justeattakeaway/pie-webc-core 0.11.0 → 0.12.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.12.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [Changed] - `@validPropertyValues` and `@requiredProperty` decorators to support Lit 3. ([#1027](https://github.com/justeattakeaway/pie/pull/1027)) by [@raoufswe](https://github.com/raoufswe)
8
+
9
+ ## 0.12.0-next.0
10
+
11
+ ### Minor Changes
12
+
13
+ - [Changed] - `@validPropertyValues` and `@requiredProperty` decorators to support Lit 3. ([#1025](https://github.com/justeattakeaway/pie/pull/1025)) by [@raoufswe](https://github.com/raoufswe)
14
+
3
15
  ## 0.11.0
4
16
 
5
17
  ### Minor Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@justeattakeaway/pie-webc-core",
3
- "version": "0.11.0",
3
+ "version": "0.12.0",
4
4
  "description": "PIE design system base classes, mixins and utilities for web components",
5
5
  "type": "module",
6
6
  "main": "index.ts",
@@ -11,15 +11,11 @@ export const requiredProperty = <T>(componentName: string) => function validateR
11
11
  return this[privatePropertyKey];
12
12
  },
13
13
  set (value: T): void {
14
- const oldValue = this[privatePropertyKey];
15
-
16
14
  if (value === undefined || value === null || (typeof value === 'string' && value.trim() === '')) {
17
15
  console.error(`<${componentName}> Missing required attribute "${propertyKey}"`);
18
16
  }
19
17
  this[privatePropertyKey] = value;
20
-
21
- this.requestUpdate(propertyKey, oldValue);
22
18
  },
19
+ configurable: true,
23
20
  });
24
21
  };
25
-
@@ -25,16 +25,6 @@ describe('requiredProperty', () => {
25
25
  class MockComponent {
26
26
  @requiredProperty('mock-component')
27
27
  color?: string | null;
28
-
29
- private _requestUpdateArgs = {};
30
-
31
- requestUpdate (propertyKey: string, oldValue: unknown) {
32
- this._requestUpdateArgs = { propertyKey, oldValue };
33
- }
34
-
35
- requestUpdateCalledWith () {
36
- return this._requestUpdateArgs;
37
- }
38
28
  }
39
29
 
40
30
  it('should log an error if the property is undefined', () => {
@@ -80,15 +70,4 @@ describe('requiredProperty', () => {
80
70
  // Assert
81
71
  expect(consoleErrorSpy).not.toHaveBeenCalled();
82
72
  });
83
-
84
- it('should call requestUpdate when the property is set', () => {
85
- // Arrange
86
- const mockComponent = new MockComponent();
87
-
88
- // Act
89
- mockComponent.color = 'blue';
90
-
91
- // Assert
92
- expect(mockComponent.requestUpdateCalledWith()).toStrictEqual({ propertyKey: 'color', oldValue: undefined });
93
- });
94
73
  });
@@ -25,16 +25,6 @@ describe('validPropertyValues', () => {
25
25
  class MockComponent {
26
26
  @validPropertyValues('mock-component', ['red', 'green', 'blue'], 'red')
27
27
  color = 'red';
28
-
29
- private _requestUpdateArgs = {};
30
-
31
- requestUpdate (propertyKey: string, oldValue: unknown) {
32
- this._requestUpdateArgs = { propertyKey, oldValue };
33
- }
34
-
35
- requestUpdateCalledWith () {
36
- return this._requestUpdateArgs;
37
- }
38
28
  }
39
29
 
40
30
  it('should allow value to be updated with a valid value', () => {
@@ -75,16 +65,4 @@ describe('validPropertyValues', () => {
75
65
  'Falling back to default value: "red"',
76
66
  );
77
67
  });
78
-
79
- it('should call requestUpdate when the property is set', () => {
80
- // Arrange
81
- const mockComponent = new MockComponent();
82
-
83
- // Act
84
- mockComponent.color = 'yellow';
85
-
86
- // Assert
87
- expect(mockComponent.color).toBe('red');
88
- expect(mockComponent.requestUpdateCalledWith()).toStrictEqual({ propertyKey: 'color', oldValue: 'red' });
89
- });
90
68
  });
@@ -5,7 +5,7 @@
5
5
  * @param defaultValue - The value to fall back on
6
6
  * @returns - The decorator function
7
7
  */
8
- export const validPropertyValues = <T>(componentName: string, validValues: readonly T[], defaultValue: T) => function validatePropertyValues (target: object, propertyKey: string): void {
8
+ export const validPropertyValues = <T>(componentName: string, validValues: readonly T[], defaultValue: T) => function validatePropertyValues (target: object, propertyKey: string) : void {
9
9
  const privatePropertyKey = `#${propertyKey}`;
10
10
 
11
11
  Object.defineProperty(target, propertyKey, {
@@ -13,8 +13,6 @@ export const validPropertyValues = <T>(componentName: string, validValues: reado
13
13
  return this[privatePropertyKey];
14
14
  },
15
15
  set (value: T): void {
16
- const oldValue = this[privatePropertyKey];
17
-
18
16
  if (!validValues.includes(value)) {
19
17
  console.error(
20
18
  `<${componentName}> Invalid value "${value}" provided for property "${propertyKey}".`,
@@ -25,8 +23,7 @@ export const validPropertyValues = <T>(componentName: string, validValues: reado
25
23
  } else {
26
24
  this[privatePropertyKey] = value;
27
25
  }
28
-
29
- this.requestUpdate(propertyKey, oldValue);
30
26
  },
27
+ configurable: true,
31
28
  });
32
29
  };