Skip to content

Commit

Permalink
Merge pull request #18735 from jgwhite/doc-glimmer-classic-tracking
Browse files Browse the repository at this point in the history
[DOC release] Update documentation for tracked with classic classes
  • Loading branch information
locks authored Feb 11, 2020
2 parents 43104de + 1e92e4e commit e9e726c
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions packages/@ember/-internals/glimmer/lib/glimmer-tracking-docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,38 @@
}
```
`tracked` can also be used with the classic Ember object model in a similar
manner to classic computed properties:
```javascript
import EmberObject from '@ember/object';
import { tracked } from '@glimmer/tracking';
const Entry = EmberObject.extend({
name: tracked(),
phoneNumber: tracked()
});
```
Often this is unnecessary, but to ensure robust auto-tracking behavior it is
advisable to mark tracked state appropriately wherever possible.
This form of `tracked` also accepts an optional configuration object
containing either an initial `value` or an `initializer` function (but not
both).
```javascript
import EmberObject from '@ember/object';
import { tracked } from '@glimmer/tracking';
const Entry = EmberObject.extend({
name: tracked({ value: 'Zoey' }),
favoriteSongs: tracked({
initializer: () => ['Raspberry Beret', 'Time After Time']
})
});
```
@method tracked
@static
@for @glimmer/tracking
Expand Down

0 comments on commit e9e726c

Please sign in to comment.