Skip to content

Commit

Permalink
Merge pull request #19835 from SergeAstapov/update-destroyable-docs
Browse files Browse the repository at this point in the history
  • Loading branch information
mixonic committed Nov 12, 2021
2 parents d612b18 + 34950eb commit ce98e57
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions packages/@ember/destroyable/index.ts
Expand Up @@ -34,7 +34,9 @@ import {
```js
class CustomSelect extends Component {
constructor() {
constructor(...args) {
super(...args);
// obj is now a child of the component. When the component is destroyed,
// obj will also be destroyed, and have all of its destructors triggered.
this.obj = associateDestroyableChild(this, {});
Expand Down Expand Up @@ -165,12 +167,15 @@ import {
parent is destroyed, the destructor function will be called.
```js
import Component from '@glimmer/component';
import { registerDestructor } from '@ember/destroyable';
class Modal extends Component {
@service resize;
constructor() {
constructor(...args) {
super(...args);
this.resize.register(this, this.layout);
registerDestructor(this, () => this.resize.unregister(this));
Expand All @@ -187,6 +192,7 @@ import {
than creating a closure function per destroyable.
```js
import Component from '@glimmer/component';
import { registerDestructor } from '@ember/destroyable';
function unregisterResize(instance) {
Expand All @@ -196,7 +202,9 @@ import {
class Modal extends Component {
@service resize;
constructor() {
constructor(...args) {
super(...args);
this.resize.register(this, this.layout);
registerDestructor(this, unregisterResize);
Expand All @@ -223,12 +231,15 @@ export function registerDestructor<T extends object>(
from the destroyable.
```js
import Component from '@glimmer/component';
import { registerDestructor, unregisterDestructor } from '@ember/destroyable';
class Modal extends Component {
@service modals;
constructor() {
constructor(...args) {
super(...args);
this.modals.add(this);
this.modalDestructor = registerDestructor(this, () => this.modals.remove(this));
Expand Down

0 comments on commit ce98e57

Please sign in to comment.