-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve Node References and JSDoc typings (#57)
add jsdoc typings + fix linting + + + +
- Loading branch information
Showing
7 changed files
with
216 additions
and
6 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<div> | ||
<button type="button" class="add-items p-2 ml-2" {{on "click" this.addItems}}>Add 100 items</button> | ||
<button type="button" class="clear p-2 ml-2" {{on "click" this.clear}}>Clear</button> | ||
</div> | ||
|
||
{{#each this.items as |item|}} | ||
<div {{create-ref (concat "item-" item) bucket=this}}> | ||
{{item}} | ||
</div> | ||
{{/each}} |
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,34 @@ | ||
import Component from '@glimmer/component'; | ||
import { tracked } from '@glimmer/tracking'; | ||
import { action } from '@ember/object'; | ||
import { ref } from 'ember-ref-bucket'; | ||
|
||
export default class Test extends Component { | ||
constructor() { | ||
super(...arguments); | ||
this.args.sendContext(this); | ||
} | ||
/** | ||
* @type {number[]} | ||
*/ | ||
@tracked items = []; | ||
|
||
@action addItems() { | ||
this.items = [ | ||
...this.items, | ||
...Array(100) | ||
.fill(0) | ||
.map((_, i) => i), | ||
]; | ||
this.items.forEach((item) => { | ||
Object.defineProperty(this, `item-${item}`, ref(`item-${item}`)(this)); | ||
}); | ||
} | ||
|
||
@action clear() { | ||
// this.items.forEach((item) => { | ||
// delete this[`item-${item}`]; | ||
// }); | ||
this.items = []; | ||
} | ||
} |
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,33 @@ | ||
import { module, test } from 'qunit'; | ||
import { setupRenderingTest } from 'ember-qunit'; | ||
import { render, click } from '@ember/test-helpers'; | ||
import { hbs } from 'ember-cli-htmlbars'; | ||
|
||
module('Integration | Component | ref-gc', function (hooks) { | ||
setupRenderingTest(hooks); | ||
|
||
// TODO: Replace this with your real tests. | ||
test('it renders', async function (assert) { | ||
let context = null; | ||
this.sendContext = (ctx) => { | ||
context = ctx; | ||
}; | ||
|
||
await render(hbs`<RefGc @sendContext={{this.sendContext}} />`); | ||
|
||
await click('.add-items'); | ||
|
||
assert.strictEqual(typeof context[`item-${0}`], 'object'); | ||
assert.strictEqual(context[`item-${0}`].tagName, 'DIV'); | ||
|
||
await click('.clear'); | ||
|
||
assert.strictEqual(typeof context[`item-${0}`], 'object'); | ||
assert.strictEqual(String(context[`item-${0}`]), 'null'); | ||
|
||
await click('.add-items'); | ||
assert.strictEqual(context[`item-${0}`].tagName, 'DIV'); | ||
await click('.clear'); | ||
assert.strictEqual(String(context[`item-${0}`]), 'null'); | ||
}); | ||
}); |