Skip to content

Commit 9b81a69

Browse files
Merge pull request #812 from NullVoxPopuli/changeset-release/main
Release Preview (beta)
2 parents 4905e7d + c88094a commit 9b81a69

File tree

3 files changed

+78
-1
lines changed

3 files changed

+78
-1
lines changed

.changeset/pre.json

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"afraid-cherries-type",
1212
"curvy-frogs-sin",
1313
"gold-weeks-destroy",
14+
"hip-fishes-agree",
1415
"hungry-waves-kiss",
1516
"long-apples-sneeze",
1617
"many-brooms-turn",

ember-resources/CHANGELOG.md

+76
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,81 @@
11
# ember-resources
22

3+
## 6.0.0-beta.2
4+
5+
### Minor Changes
6+
7+
- [#797](https://github.com/NullVoxPopuli/ember-resources/pull/797) [`18adb86`](https://github.com/NullVoxPopuli/ember-resources/commit/18adb86dc7a399b47dfd6a2065b059ad38b82967) Thanks [@NullVoxPopuli](https://github.com/NullVoxPopuli)! - Add link() and @link, importable from `ember-resources/link`.
8+
9+
NOTE: for existing users of `ember-resources`, this addition has no impact on your bundle.
10+
11+
<details><summary>Example property usage</summary>
12+
13+
```js
14+
import { link } from 'ember-resources/link';
15+
16+
class MyClass { ... }
17+
18+
export default class Demo extends Component {
19+
// This usage does now allow passing args to `MyClass`
20+
@link(MyClass) myInstance;
21+
}
22+
```
23+
24+
</details>
25+
26+
<details><summary>Example inline usage</summary>
27+
28+
```js
29+
import Component from "@glimmer/component";
30+
import { cached } from "@glimmer/tracking";
31+
import { link } from "ember-resources/link";
32+
33+
export default class Demo extends Component {
34+
// To pass args to `MyClass`, you must use this form
35+
// NOTE though, that `instance` is linked to the `Demo`s lifecycle.
36+
// So if @foo is changing frequently, memory pressure will increase rapidly
37+
// until the `Demo` instance is destroyed.
38+
//
39+
// Resources are a better fit for this use case, as they won't add to memory pressure.
40+
@cached
41+
get myFunction() {
42+
let instance = new MyClass(this.args.foo);
43+
44+
return link(instance, this);
45+
}
46+
}
47+
```
48+
49+
</details>
50+
51+
This abstracts away the following boilerplate:
52+
53+
```js
54+
import { getOwner, setOwner } from "@ember/owner";
55+
import { associateDestroyableChild } from "@ember/destroyable";
56+
57+
class MyClass {
58+
/* ... */
59+
}
60+
61+
export default class Demo extends Component {
62+
@cached
63+
get myInstance() {
64+
let instance = new MyClass();
65+
66+
associateDestroyableChild(this, instance);
67+
68+
let owner = getOwner(this);
69+
70+
if (owner) {
71+
setOwner(instance, owner);
72+
}
73+
74+
return instance;
75+
}
76+
}
77+
```
78+
379
## 6.0.0-beta.1
480

581
### Major Changes

ember-resources/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ember-resources",
3-
"version": "6.0.0-beta.1",
3+
"version": "6.0.0-beta.2",
44
"keywords": [
55
"ember-addon"
66
],

0 commit comments

Comments
 (0)