Skip to content

Commit

Permalink
feat(SignalVisibilityController): Predicate and value information is …
Browse files Browse the repository at this point in the history
…now attached to the events fired to the DOM. Allows for easier debugging, and can be used in other controllers if desired.
  • Loading branch information
Sub-Xaero committed Feb 16, 2022
1 parent fccc822 commit fc02e05
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
15 changes: 10 additions & 5 deletions docs/docs/controllers/signal/signal_visibility_controller.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,16 @@ the same `nameValue` as the `nameValue` of this controller.


## Events
| Event | When | Dispatched on | `event.detail` |
|--------------------------|-----------------------------------------------------------------------------------|-----------------------------|----------------------------------------|
| `signal-visibility:show` | When a signalled value matches the predicate expression and this element is shown | The controller root element | `element`: the controller root element |
| `signal-visibility:hide` | When a signalled value fails the predicate expression and this element is hidden | The controller root element | `element`: the controller root element |

| Event | When | Dispatched on | `event.detail` | |
|--------------------------|-----------------------------------------------------------------------------------|-----------------------------|----------------|---------------------------------------------------------------|
| `signal-visibility:show` | When a signalled value matches the predicate expression and this element is shown | The controller root element | | |
| | | | `element` | the controller root element |
| | | | `predicate` | the expression the controller used to try and match the value |
| | | | `value` | the value that was received |
| `signal-visibility:hide` | When a signalled value fails the predicate expression and this element is hidden | The controller root element | | |
| | | | `element` | the controller root element |
| | | | `predicate` | the expression the controller used to try and match the value |
| | | | `value` | the value that was received |

## Side Effects
<NoSideEffects/>
Expand Down
4 changes: 2 additions & 2 deletions src/controllers/signal/signal_visibility_controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ export class SignalVisibilityController extends BaseController {
return;
}
if (this._predicates.every(predicate => predicate(value))) {
this.dispatchEvent(this.el, "signal-visibility:show");
this.dispatchEvent(this.el, "signal-visibility:show", {detail: {predicate: this.showValue, value}});
this.removeHideClasses(this.el);
} else {
this.dispatchEvent(this.el, "signal-visibility:hide");
this.dispatchEvent(this.el, "signal-visibility:hide", {detail: {predicate: this.showValue, value}});
this.addHideClasses(this.el);
}
}
Expand Down

0 comments on commit fc02e05

Please sign in to comment.