-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: EphemeralController - an extendable base controller that can cl…
…eanly uninstall controllers/targets/classes/values from DOM elements
- Loading branch information
Showing
13 changed files
with
52 additions
and
9 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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,40 @@ | ||
--- | ||
id: EphemeralController | ||
title: EphemeralController | ||
--- | ||
|
||
|
||
## Purpose | ||
|
||
Provide a set of controller behaviours that allow a Stimulus controller to remove its own controllerisms (controllers, targets, actions, classes, values) from an element cleanly. | ||
|
||
## Methods | ||
|
||
This controller provides the following methods to sub-classes. | ||
|
||
| Name | Parameters | Purpose | Default | | ||
| --- | --- | --- | --- | | ||
| `cleanup` | | Remove all identifiers related to this controller from an element. | | | ||
| | `element` | The element to cleanup | | | ||
|
||
|
||
## How to Use | ||
|
||
```typescript | ||
import {EphemeralController} from "stimulus-library"; | ||
|
||
export default class extends EphemeralController { | ||
static targets = ["temp"]; | ||
|
||
removeTempTarget() { | ||
if (this.hasTempTarget){ | ||
this.cleanup(this.tempTarget); | ||
} | ||
} | ||
|
||
uninstallController() { | ||
this.cleanup(this.el); | ||
} | ||
|
||
} | ||
``` |
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