Skip to content

Commit

Permalink
feat: EphemeralController - an extendable base controller that can cl…
Browse files Browse the repository at this point in the history
…eanly uninstall controllers/targets/classes/values from DOM elements
  • Loading branch information
Sub-Xaero committed Apr 24, 2021
1 parent a12b101 commit 34ebc58
Show file tree
Hide file tree
Showing 13 changed files with 52 additions and 9 deletions.
1 change: 1 addition & 0 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export { BaseController } from "./utilities/base_controller";
export { EphemeralController } from "./utilities/ephemeral_controller";
export { AnchorSpyController } from "./controllers/anchor_spy_controller";
export { AppearanceController } from "./controllers/utility/appearance_controller";
export { AsyncBlockController } from "./controllers/async_block_controller";
Expand Down
2 changes: 1 addition & 1 deletion dist/index.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/stimulus-library.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/stimulus-library.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/stimulus-library.modern.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/stimulus-library.modern.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/stimulus-library.module.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/stimulus-library.module.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/stimulus-library.umd.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/stimulus-library.umd.js.map

Large diffs are not rendered by default.

40 changes: 40 additions & 0 deletions docs/docs/controllers/ephemeral_controller.mdx
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);
}

}
```
1 change: 1 addition & 0 deletions docs/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module.exports = {
{
"Extendable Controllers": [
"controllers/BaseController",
"controllers/EphemeralController",
]
},
{
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Utilities
export {BaseController} from "./utilities/base_controller";
export {EphemeralController} from "./utilities/ephemeral_controller";

// Controllers
export {AnchorSpyController} from "./controllers/anchor_spy_controller";
Expand Down

0 comments on commit 34ebc58

Please sign in to comment.