-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core)!: deprecate cascades decorator (#2729)
Lit context provides us with an easier to manage and more robust alternative to the imperative cascades system, let's migrate to that and remove this in PFE 4
- Loading branch information
1 parent
02d7e71
commit 3766961
Showing
3 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
--- | ||
"@patternfly/pfe-core": major | ||
--- | ||
`@cascades`: deprecated `@cascades` decorator and `CascadeController`. Use context instead. | ||
|
||
**BEFORE**: The element in charge of the context cascades data down to | ||
specifically named children. | ||
|
||
```ts | ||
import { LitElement } from 'lit'; | ||
import { property } from 'lit/decorators/property.js'; | ||
import { cascades } from '@patternfly/pfe-core/decorators/cascades.js'; | ||
|
||
class MyMood extends LitElement { | ||
@cascades('my-eyes', 'my-mouth') | ||
@property() mood: 'happy'|'sad'|'mad'|'glad'; | ||
} | ||
``` | ||
|
||
**AFTER**: children subscribe to updates from the context provider. | ||
|
||
```ts | ||
import { LitElement } from 'lit'; | ||
import { property } from 'lit/decorators/property.js'; | ||
import { provide } from '@lit/context'; | ||
import { createContextWithRoot } from '@patternfly/pfe-core/functions/context.js'; | ||
|
||
export type Mood = 'happy'|'sad'|'mad'|'glad'; | ||
|
||
export const moodContext = createContextWithRoot<Mood>(Symbol('mood')); | ||
|
||
class MyMood extends LitElement { | ||
@provide({ context: moodContext }) | ||
@property() mood: Mood; | ||
} | ||
``` | ||
|
||
```ts | ||
import { LitElement } from 'lit'; | ||
import { property } from 'lit/decorators/property.js'; | ||
import { consume } from '@lit/context'; | ||
import { moodContext, type Mood } from './my-mood.js'; | ||
|
||
class MyEyes extends LitElement { | ||
@consume({ context: moodContext, subscribe: true }) | ||
@state() private mood: Mood; | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters