|
| 1 | +--- |
| 2 | +"@patternfly/pfe-core": major |
| 3 | +--- |
| 4 | +`@cascades`: deprecated `@cascades` decorator and `CascadeController`. Use context instead. |
| 5 | + |
| 6 | +**BEFORE**: The element in charge of the context cascades data down to |
| 7 | +specifically named children. |
| 8 | + |
| 9 | +```ts |
| 10 | +import { LitElement } from 'lit'; |
| 11 | +import { property } from 'lit/decorators/property.js'; |
| 12 | +import { cascades } from '@patternfly/pfe-core/decorators/cascades.js'; |
| 13 | + |
| 14 | +class MyMood extends LitElement { |
| 15 | + @cascades('my-eyes', 'my-mouth') |
| 16 | + @property() mood: 'happy'|'sad'|'mad'|'glad'; |
| 17 | +} |
| 18 | +``` |
| 19 | + |
| 20 | +**AFTER**: children subscribe to updates from the context provider. |
| 21 | + |
| 22 | +```ts |
| 23 | +import { LitElement } from 'lit'; |
| 24 | +import { property } from 'lit/decorators/property.js'; |
| 25 | +import { provide } from '@lit/context'; |
| 26 | +import { createContextWithRoot } from '@patternfly/pfe-core/functions/context.js'; |
| 27 | + |
| 28 | +export type Mood = 'happy'|'sad'|'mad'|'glad'; |
| 29 | + |
| 30 | +export const moodContext = createContextWithRoot<Mood>(Symbol('mood')); |
| 31 | + |
| 32 | +class MyMood extends LitElement { |
| 33 | + @provide({ context: moodContext }) |
| 34 | + @property() mood: Mood; |
| 35 | +} |
| 36 | +``` |
| 37 | + |
| 38 | +```ts |
| 39 | +import { LitElement } from 'lit'; |
| 40 | +import { property } from 'lit/decorators/property.js'; |
| 41 | +import { consume } from '@lit/context'; |
| 42 | +import { moodContext, type Mood } from './my-mood.js'; |
| 43 | + |
| 44 | +class MyEyes extends LitElement { |
| 45 | + @consume({ context: moodContext, subscribe: true }) |
| 46 | + @state() private mood: Mood; |
| 47 | +} |
| 48 | +``` |
0 commit comments