|
1 | 1 | # ember-resources
|
2 | 2 |
|
| 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 | + |
3 | 79 | ## 6.0.0-beta.1
|
4 | 80 |
|
5 | 81 | ### Major Changes
|
|
0 commit comments